Magic090 Posted February 29 Share Posted February 29 I've been playing this character I really like but I have one problem with them and that is when I use one of their abilities it strikes lightning onto any enemy nearby the character. the main problem with this is that it will strike an unlimited amount of enemies as long as they're in the range. is there a way to limit how many enemies can be struck at once within the area? Here's the code associated with the ability, if needed: local function skill_4333(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 15, { "_combat" }, exclude_tags) for i, ent in ipairs(ents) do if not ent:HasTag("player") and not ent:HasTag("companion") and not ent:HasTag("abigail") and (ent.components.health and not ent.replica.health:IsDead()) then ent.components.combat:GetAttacked(inst, TUNING.SHUOMA_ELEDAMAGE) SpawnPrefab("lightning").Transform:SetPosition(ent.Transform:GetWorldPosition()) end end skill_cost(inst) if TUNING.GS_MOD_LANGUAGE_SETTING == "CHINESE" then inst.components.talker:Say("天罚!") else inst.components.talker:Say("Strike em down Zeus!") end end FYI I have almost no idea what i'm doing. Link to comment Share on other sites More sharing options...
Thomas Die Posted March 1 Share Posted March 1 I feel like this is the issue with the calling of the procedure and not the subroutine itself, can you find any instances where the function "skill_4333" is called? Can you link the mod itself? Link to comment Share on other sites More sharing options...
IronHunter Posted March 2 Share Posted March 2 Spoiler On 2/29/2024 at 6:48 AM, Magic090 said: I've been playing this character I really like but I have one problem with them and that is when I use one of their abilities it strikes lightning onto any enemy nearby the character. the main problem with this is that it will strike an unlimited amount of enemies as long as they're in the range. is there a way to limit how many enemies can be struck at once within the area? Here's the code associated with the ability, if needed: local function skill_4333(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 15, { "_combat" }, exclude_tags) for i, ent in ipairs(ents) do if not ent:HasTag("player") and not ent:HasTag("companion") and not ent:HasTag("abigail") and (ent.components.health and not ent.replica.health:IsDead()) then ent.components.combat:GetAttacked(inst, TUNING.SHUOMA_ELEDAMAGE) SpawnPrefab("lightning").Transform:SetPosition(ent.Transform:GetWorldPosition()) end end skill_cost(inst) if TUNING.GS_MOD_LANGUAGE_SETTING == "CHINESE" then inst.components.talker:Say("天罚!") else inst.components.talker:Say("Strike em down Zeus!") end end FYI I have almost no idea what i'm doing. If you want to cap how many ents are affected you could just make a counter for how many ents have been affected already and when it hits the limit it breaks the for loop. Also you should probably add "player", "companion", and "abigail" tags to your exclude_tags as this is just making your list longer than it has to be. That way it automatically excludes them and you don't need to do those checks in your if statement. Link to comment Share on other sites More sharing options...
Magic090 Posted March 2 Author Share Posted March 2 7 hours ago, Thomas Die said: I feel like this is the issue with the calling of the procedure and not the subroutine itself, can you find any instances where the function "skill_4333" is called? Can you link the mod itself? Im unsure of where the function "skill_4333" is called but here's the link to the mod. The specific lines of code from my original question are located in 322330\2754469576\scripts\shuoma_skill.lua https://steamcommunity.com/sharedfiles/filedetails/?id=2754469576 4 hours ago, IronHunter said: If you want to cap how many ents are affected you could just make a counter for how many ents have been affected already and when it hits the limit it breaks the for loop. Also you should probably add "player", "companion", and "abigail" tags to your exclude_tags as this is just making your list longer than it has to be. That way it automatically excludes them and you don't need to do those checks in your if statement. I will try to figure out how I could write code for what you're saying here although if I write a for loop that breaks when a certain value of ents is reached then wouldn't that cancel the ability entirely? again ill state that I have almost no idea what I am doing. The only experience I have with coding is 1 semester of a beginners java script class. Link to comment Share on other sites More sharing options...
Littlefat1213 Posted March 2 Share Posted March 2 local function skill_4333(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 15, { "_combat" }, exclude_tags) local MAX_COUNT = 10 local count = 0 for i, ent in ipairs(ents) do if not ent:HasTag("player") and not ent:HasTag("companion") and not ent:HasTag("abigail") and (ent.components.health and not ent.replica.health:IsDead()) then ent.components.combat:GetAttacked(inst, TUNING.SHUOMA_ELEDAMAGE) SpawnPrefab("lightning").Transform:SetPosition(ent.Transform:GetWorldPosition()) count = count + 1 end if count >= MAX_COUNT then break end end skill_cost(inst) if TUNING.GS_MOD_LANGUAGE_SETTING == "CHINESE" then inst.components.talker:Say("天罚!") else inst.components.talker:Say("Strike em down Zeus!") end end just for example if you wanna hit enemies no more than 10 Link to comment Share on other sites More sharing options...
Magic090 Posted March 2 Author Share Posted March 2 21 minutes ago, Littlefat1213 said: local function skill_4333(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, 15, { "_combat" }, exclude_tags) local MAX_COUNT = 10 local count = 0 for i, ent in ipairs(ents) do if not ent:HasTag("player") and not ent:HasTag("companion") and not ent:HasTag("abigail") and (ent.components.health and not ent.replica.health:IsDead()) then ent.components.combat:GetAttacked(inst, TUNING.SHUOMA_ELEDAMAGE) SpawnPrefab("lightning").Transform:SetPosition(ent.Transform:GetWorldPosition()) count = count + 1 end if count >= MAX_COUNT then break end end skill_cost(inst) if TUNING.GS_MOD_LANGUAGE_SETTING == "CHINESE" then inst.components.talker:Say("天罚!") else inst.components.talker:Say("Strike em down Zeus!") end end just for example if you wanna hit enemies no more than 10 Thank you so much! This worked perfectly. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now