Author Topic: need to block kill command  (Read 2904 times)

0 Members and 2 Guests are viewing this topic.

Offline wishbone

  • Newbie
  • *
  • Posts: 20
  • Karma: 0
need to block kill command
« 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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: need to block kill command
« Reply #1 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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: need to block kill command
« Reply #2 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).
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: need to block kill command
« Reply #3 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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: need to block kill command
« Reply #4 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.! =)