• Help with this code please:
    33 replies, posted
[QUOTE=Fantym420;29817648]When the entity explodes, do a find in sphere to get any entities in the blast radius. Then loop through the entities you got from the find and do a trace from the bomb to each entity that is a player. If the trace hit the player then nothing is blocking, so they die. Now, the rest depends on how you want it to work, if you want any object to stop the blast then if the trace.Entity is not the player you are tracing at then no damage, if you want only the world to stop the blast then if trace.Entity is not the player or the world, start a new trace from where you hit using what you hit as the filter, and the player is the endpos again. Repeat until either you hit the world or the player. Pseudo code -- Will not work as is, this is just an outline/example [lua] function bombExplode(bombPos, bombRadius) sphereEnts = ents.FindInSphere(bombLocation, bombRadius) -- Grab ents near bomb local hitPlayer = false -- Setup variable to check if we hit player for _, ent in pairs(sphereEnts) do -- loop the ents if ent:IsPlayer() then -- Check if it's a player tracedata = {} -- setup first trace tracedata.start = bombPos tracedata.endpos = ent:GetPos() tracedata.filter = ent trace = trace(tracedata) if trace.Entity == ent then -- see if the trace ended with the player hitPlayer = true -- then set it so we damage the player end if !(trace.Entity == ent) and !(trace.Entity:IsWorld()) then -- if we didn't hit the player or the world then... doAnotherTrace = {} -- setup another trace doAnotherTrace.start = trace.HitPos doAnotherTrace.endpos = ent:GetPos() doAnotherTrace.filter = trace.Entity newTrace = trace(doAnotherTrace) if newTrace.Entity == ent then -- did we hit the player? hitPlayer = true -- then set it so we damage the player end end if hitPlayer then -- if we hit the player ent:Kill() -- kill the player end end hitPlayer = false -- reset variable for next player end end [/lua] This could also be done with a recursive function, or masks, but it's best to start simple. Basically the way the code above would run if I wrote it as real code is, if the player is in the blast radius and there is only one prop or entity between him and the bomb, the player dies, if there's more than 1 prop/ent in the way or the world, the player won't die. if you want it to go till it hit world no mater how many props are in the way, you'll need a recursive function(a function that calls it self until a condition is met). If you still can't get it put it in the requests and i'll make a real function for it either later today or tomorrow.[/QUOTE] Ah now I see how it works, for a bit then, I try to edit it a bit, and @ Toneo, I think I need to relearn LUA, I stopped scripting for a few weeks now because I got enough funky stuff for my server already, Also I edited your landmine code a bit, TTT based, anyways, Thanks guys Ill work something out :)
Meh I think I messed this up, [lua] function bombExplode(bomb:GetPos() , 66) sphereEnts = ents.FindInSphere(bomb:GetPos(), 66) -- Grab ents near bomb local hitPlayer = false -- Setup variable to check if we hit player for _, ent in pairs(sphereEnts) do -- loop the ents if ent:IsPlayer() then -- Check if it's a player tracedata = {} -- setup first trace tracedata.start = bombPos tracedata.endpos = ent:GetPos() tracedata.filter = ent trace = trace(tracedata) if trace.Entity == ent then -- see if the trace ended with the player hitPlayer = true -- then set it so we damage the player end if !(trace.Entity == ent) and !(trace.Entity:IsWorld()) then -- if we didn't hit the player or the world then... doAnotherTrace = {} -- setup another trace doAnotherTrace.start = trace.HitPos doAnotherTrace.endpos = ent:GetPos() doAnotherTrace.filter = trace.Entity newTrace = trace(doAnotherTrace) if newTrace.Entity == ent then -- did we hit the player? hitPlayer = true -- then set it so we damage the player end end if hitPlayer then -- if we hit the player ent:Kill() -- kill the player end end hitPlayer = false -- reset variable for next player end end [/lua] Because it doesnt work, also I think it doesnt matter how much props there are in the way of the player before it explodes, Basicly what is the output is that it kills the player in its radius, (Not traitors)
Please don't copy paste. [quote][b]Pseudo code -- Will not work as is, this is just an outline/example[/b][/quote] I said that code won't work it's just a guide line. So here's the main problems, you don't use the values in the function definition, you are supposed to put a variable name in there and pass the function those values from your bomb, and you didn't fix the data the trace is recieving, bombPos is not defined =(. Also this is not even close to ready for TTT I've never coded for it so I don't know the functions it uses you'll need to put those in, like checking for traitors and not. If you have already read, please re-read [url=http://www.lua.org/pil/index.html] Programing In Lua[/url] until you understand the syntax and logic of coding in Lua. My intention was for you to read the code and write your own version with your own logic, and variables.
Hmm alright will do, And thanks :)
Sorry, you need to Log In to post a reply to this thread.