Jump to content

[SOLVED] Would appreciate some help.


Recommended Posts

Hello, I would like some help :)! Here's the code I need help with... 

---------------------------------------------------------------------------------------------------------------------------------------------------
local x,y,z = inst.Transform:GetWorldPosition()                                                                                                  --
local ents = TheSim:FindEntities(x, y, z, 20, { "_combat" }, { "player", "shadow", "shadowminion" })                                             --
for i,v in ipairs(ents) do                                                                                                                       --
if v:HasTag("butterfly") then                                                                                                                    --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.components.health:DoDelta(-999) end)                                                                          --
elseif v:HasTag("insect") and not v:HasTag("butterfly") then                                                                                     --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.11, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.22, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.33, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.44, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.55, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.66, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.77, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.78, function(v) v.components.health:DoDelta(-999) end)                                                                          --
end                                                                                                                                              --
end                                                                                                                                              --
---------------------------------------------------------------------------------------------------------------------------------------------------

So, this code kills butterflies & insects when in 20 distance radius but I would like for it to instantly kill creatures with the "insect" tag when in a 10 distance radius instead of making them go through the hit stun states then killing them. I tried copy & paste the code & made one that effects "insects" in a 10 distance radius but it conflicted with this code... So, I would really appreciate some help on how to make this code have different effects on a closer distance :)! Thanks for reading my problem, have a wonderful day & peace :D!

Edited by SuperDavid
Link to comment
Share on other sites

sry, I did not understand what you want and what you tested and what conflicts :D

The code you posted is the one that works, right?
And what did you changed? how was your code? And what was the conflict? Do you want to run the above code + your code that both are looking for insects? Or what is the conflict?

Link to comment
Share on other sites

To put it more simple-y this is what I want the code to be like...

---------------------------------------------------------------------------------------------------------------------------------------------------
local x,y,z = inst.Transform:GetWorldPosition()                                                                                                  --
local ents = TheSim:FindEntities(x, y, z, 10, { "_combat" }, { "player", "shadow", "shadowminion" })                                             --
for i,v in ipairs(ents) do                                                                                                                       --
if v:HasTag("butterfly") then                                                                                                                    --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.components.health:DoDelta(-999) end)                                                                          --
elseif v:HasTag("insect") and not v:HasTag("butterfly") then                                                                                     --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.components.health:DoDelta(-999) end)                                                                          --
end                                                                                                                                              --
end                                                                                                                                              --
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
local x,y,z = inst.Transform:GetWorldPosition()                                                                                                  --
local ents = TheSim:FindEntities(x, y, z, 20, { "_combat" }, { "player", "shadow", "shadowminion" })                                             --
for i,v in ipairs(ents) do                                                                                                                       --
if v:HasTag("butterfly") then                                                                                                                    --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.components.health:DoDelta(-999) end)                                                                          --
elseif v:HasTag("insect") and not v:HasTag("butterfly") then                                                                                     --
if v.components.health:IsDead() then                                                                                                             --
return                                                                                                                                           --
end                                                                                                                                              --
v:DoTaskInTime(0.01, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.11, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.22, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.33, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.44, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.55, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.66, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.77, function(v) v.sg:GoToState("hit") v.components.locomotor:Stop() v.components.locomotor:Clear() v:ClearBufferedAction() end) --
v:DoTaskInTime(0.78, function(v) v.components.health:DoDelta(-999) end)                                                                          --
end                                                                                                                                              --
end                                                                                                                                              --
---------------------------------------------------------------------------------------------------------------------------------------------------

See the top part of the code? I want the bottom part of the code to be able to be different when the "TheSim:FindEntities(x, y, z, 20," is "TheSim:FindEntities(x, y, z, 10,". When I put those two sets of code together they conflict because the "TheSim:FindEntities(x, y, z, 20," also covers 10 distance radius so when you're in 10 distance radius both of the codes will try to work on "insect" so the "insect" will start taking the hit states even though they're supposed to die instantly because you're 10 distance radius away from them... Sorry I'm very bad at explaining :(... In the most simple way I can explain is I'd like the bottom code to play different events when it's "TheSim:FindEntities(x, y, z, 10," and not "TheSim:FindEntities(x, y, z, 20,"... That's the most simple way I know how to say xD, sorry!

Edited by SuperDavid
Link to comment
Share on other sites

ah, okay.

I'm also no expert at professional code, so there might be even better solutions, but the theese two come in my mind first:
1) Add a Tag.
2) Do the 20 radius search 0.05 seconds later.

1) Just add for those things that will be killed in 10 radius a Tag like "v:AddTag("mymodkilled") or any unique name that does not exist already.  And in the 20 radius search oyu can exclude everything that has this Tag.

2) You could put the whole 20 radius search code in his own function (lets says you name it "My20killfunction", then you could write below your 10 radius code
inst:DoTaskInTime(0.05, My20killfunction)
That way all things from 10 radius will be already dead when the 20 radius search is done.

Edited by Serpens
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...