• Getting an entity to destroy itself
    7 replies, posted
Hi guys, need a little help with something.....how would I make it so that say I spawn a money printer but it can only spawn at a certain point in the map and when you go a certain distance away from that place it will blow up. Also a message will appear saying "Your not in the correct area to spawn this" when you try to spawn it outside the set point of the map...been toying with the lua for it for ages...can't seem to get the lua theory down.
To check ent position each frame [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/Think]ENTITY/Think[/url] Get Entity position [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetPos]Entity:GetPos[/url] Entity Distance from a vector [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/Distance]Vector:Distance[/url] Remove the entity [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/Remove]Entity:Remove[/url] Send player message [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ChatPrint]Player:ChatPrint[/url]
hook.Add( "Think", function() for _, ent in pairs( ents.GetAll() ) do local x = ... local y = ... local z = ... local distance = 5 -- whatever if ( ent:GetPos():Distance( x, y, z ) == distance ) then ent:GetOwner():ChatPrint( "You can't spawn entities in this area!" ) ent:Remove() end end end
[QUOTE=VortexZ;48238980]hook.Add( "Think", function() for _, ent in pairs( ents.GetAll() ) do local x = ... local y = ... local z = ... local distance = 5 -- whatever if ( ent:GetPos():Distance( x, y, z ) == distance ) then ent:GetOwner():ChatPrint( "You can't spawn entities in this area!" ) ent:Remove() end end end[/QUOTE] would that be done client side or server side
Serverside [editline]18th July 2015[/editline] And replace ... with a certain coordinate
Thanks for the help man, I assume I put this code inside the actual entity code also does this make it so when you actually leave a certain point it destroys ? or is this to make it so the area cannot have things spawned inside it
Well, actually that code will remove every entity out of wherever you put the coords (Including players) You should check my links, and if you really can't do something like this or "Toy in lua" (For ages? What? Lua it's pretty easy to understand with all these tutorials on wiki) i recommend you to hire someone on scriptfodder
Oh shit yeah...
Sorry, you need to Log In to post a reply to this thread.