Ulysses

General => Off-Topic => Topic started by: wishbone on July 14, 2009, 02:08:21 AM

Title: need to block kill command
Post by: wishbone on July 14, 2009, 02:08:21 AM
Hi, I need a code that will block the kill command and make it where you can turn it on or off i post something like this a FP but never got a straight answer so hoping you guys can help more.

Thanks
Title: Re: need to block kill command
Post by: JamminR on July 14, 2009, 07:45:02 PM
Here's an excellent opportunity for you to teach yourself Lua.
ULX two nice functions. One that sets a table on a player object called "ulxNoDie" true or false.
Second; if ulxNoDie is set true on a player, prevents suicide.
We use them in a few 'punishments' (Jail, maul, to name but a few) to prevent suicide of players being punished.

See the ulx lib.lua file for examples of code.
You'd need to write additional functionality to pass player objects to the 'switch' function already in ULX.
Title: Re: need to block kill command
Post by: Megiddo on July 14, 2009, 09:12:28 PM
It's not possible to block 'kill' outright without a module or intervention on garry's part (or maybe he's even already made a hook for this purpose?). The ULX functions do get pretty close though, they just restore your state after you die (weapons, position, etc).
Title: Re: need to block kill command
Post by: JamminR on July 15, 2009, 02:57:17 PM
Oh. Nice!
Now that you mention it Megiddo; I decided to give a quick look at the GM Lua wiki.
http://wiki.garrysmod.com/?title=Gamemode.CanPlayerSuicide
I love our use of playerdeath in the lib file, but this would make it quite a bit easier.
Title: Re: need to block kill command
Post by: MrPresident on July 28, 2009, 09:06:00 AM
yeah, we use this in stranded to prevent people from suiciding on PvP worlds to avoid being killed.

Code: [Select]
function GM:CanPlayerSuicide(ply)
if ply:InPvP() then
ply:SendMessage("Can not suicide here.",3,Color(200,0,0,255))
return false
end
return true
end

so if you wanted to prevent the player from suiciding all the time.. you could just put this in a file in autorun/server

Code: [Select]
function PreventSuicide(ply)
return false
end
hook.Add( "CanPlayerSuicide", "preventsuicide", PreventSuicide )

now assume you wanted to be able to change it with a con-variable... this would do the trick.

Code: [Select]
CreateConVar("gm_cansuicide","0",FCVAR_ARCHIVED)

function PreventSuicide(ply)
if GetConVarNumber("gm_cansuicide") == 0 then
return false
else
return true
end
hook.Add( "CanPlayerSuicide", "preventsuicide", PreventSuicide )


this would create a server variable that could be changed from the server rcon or with ulx rcon called gm_cansuicide 1/0 where 1 is yes.. and 0 is no.





*Disclaimer* Completely untested.. but should work.! =)