• Killing a player in a specified space.
    4 replies, posted
[lua] local meta = FindMetaTable( "Player" ); function meta:IsInBox( min, max ) local Result = ents.FindInBox( min, max ); for k,v in pairs( Result ) do if( v && ValidEntity( v ) && v:IsPlayer() ) then return true; else return false; end end end function KickDoucheBags1() for k,v in pairs( player.GetAll() ) do if( ValidEntity( v ) ) then if v:IsInBox( Vector(1768,-146,268), Vector(1552,-739,538 ) ) then v:KillSilent() v:Spawn() end end end end concommand.Add( "killdouches", KickDoucheBags1() ) [/lua] Can someone tell me why the KickDoucheBags1 function isn't working? I just can't figure it out! It is supposed to kill a player inside the box ( Vector(1768,-146,268), Vector(1552,-739,538 ) ), but it seems the function got an error. The command pops up in the console, but when i enter it, it just tells me it's a unknown command.
Your IsInBox function is completely wrong as it will return true for all players if the first player to join is in the area, false if otherwise. if( v && ValidEntity( v ) && v:IsPlayer() ) then should be if( v && ValidEntity( v ) && v == self ) then really. and with no return false in the loop.
[QUOTE=SteveUK;17050010]Your IsInBox function is completely wrong as it will return true for all players if the first player to join is in the area, false if otherwise. if( v && ValidEntity( v ) && v:IsPlayer() ) then should be if( v && ValidEntity( v ) && v == self ) then really. and with no return false in the loop.[/QUOTE] [lua] local meta = FindMetaTable( "Player" ); function meta:IsInBox( min, max ) local Result = ents.FindInBox( min, max ); for k,v in pairs( Result ) do if( v && ValidEntity( v ) && v == self ) then return true; end end end function KickDoucheBags1() for k,v in pairs( player.GetAll() ) do if( ValidEntity( v ) ) then if v:IsInBox( Vector(1768,-146,268), Vector(1552,-739,538 ) ) then v:KillSilent() v:Spawn() end end end end concommand.Add( "killdouches", KickDoucheBags1() ) [/lua] Same thing, it just won't work.
Add some debug text? Does the concommand exist? Also for concommand.Add it should be "KickDouchBags1" without the brackets.
[QUOTE=SteveUK;17050337]Add some debug text? Does the concommand exist? Also for concommand.Add it should be "KickDouchBags1" without the brackets.[/QUOTE] A simple thing like that can mess up my code so much! Is was the brackets! Thankyou!
Sorry, you need to Log In to post a reply to this thread.