I’m trying to code a new script for a roleplay server.
The script itself should jail the "killer" if the "killer" kills the same person within 2 mins after respawn.
This is how I want the script to act:
1) Player Die
2) Set a counter( reset if it’s not the same killer:SteamID)
3) Check following statement...If the last "killer:SteamID" is the same then teleport "Killer:SteamID" using darkrp command (teleport to jail)
5) Make a public send msg ("Killer:SteamID has automaticlly arrested for RDM")
I have been searching lua and this is what i came up with.
[url]http://wiki.garrysmod.com/?title=Hook.Add[/url]
So what i want to know is:
1) How do i save the Killer:SteamID and Victim:SteamID in some kinda global varible.
2) How do i compare them ...should i use the timer function?
Something like this....
-------------------------------------------------------------------------
function CheckforRDM(victim,killer,checktime)
If killer:SteamID = lastKillerSteamID and checktime > 120 then
PrintMessage(HUD_PRINTTALK,killer:SteamID().." has been arrested for RDM!\n");
game.ConsoleCommand("rp_arrest" + killer:SteamID);
end
hook.Add("PlayerDeath","informTheVictims",CheckforRDM)
--------------------------------------------------------------------------
Hope someone can help me make this script.
Thank you so much for helping out with the script!
Found this: function ccArrest(ply, cmd, args)
[lua]
local function ccArrest(ply, cmd, args)
if not args[1] then return end
if ply:EntIndex() ~= 0 and not ply:HasPriv(ADMIN) then
ply:PrintMessage(2, string.format(LANGUAGE.need_admin, "rp_arrest"))
return
end
if DB.CountJailPos() == 0 then
if ply:EntIndex() == 0 then
print(LANGUAGE.no_jail_pos)
else
ply:PrintMessage(2, LANGUAGE.no_jail_pos)
end
return
end
local target = FindPlayer(args[1])
if target then
local length = tonumber(args[2])
if length then
target:Arrest(length)
else
target:Arrest()
end
if ply:EntIndex() == 0 then
DB.Log("Console force-arrested "..target:SteamName())
else
DB.Log(ply:SteamName().." ("..ply:SteamID()..") force-arrested "..target:SteamName() )
end
else
if ply:EntIndex() == 0 then
print(string.format(LANGUAGE.could_not_find, "player: "..tostring(args[1])))
else
ply:PrintMessage(2, string.format(LANGUAGE.could_not_find, "player: "..tostring(args[1])))
end
end
end
concommand.Add("rp_arrest", ccArrest)
[/lua]
So i guess it would look something like this...
[lua]
function CheckForRDM(victim, _, killer)
if(victim:IsPlayer() && killer:IsPlayer()) then -- Check if they're both players (should be)
if(!killer.LastKillTime) then killer.LastKillTime = 0 end
if(killer.LastKillTime < CurTime() - 120) then -- Check if the killers last kill time was under 120 seconds
FindMetaTable("Player"):ChatPrint(killer:Name().." has been arrested for RDM!") -- No need for \n
-- Find the arrest function and pass killer to it, don't use a console command. It probably requires a player.
ArrestedRdmTime = 300 -- How long will the killer be arrested
ccArrest(killer:SteamID(), ArrestedRdmTime()) -- Arrest him by SteamID
else
killer.LastKillTime = CurTime()
end
end
end
hook.Add("PlayerDeath", "RdmCheck", CheckForRDM)[/lua]
Im still pretty unsure if the hook.Add will work...
Thank you for you efforts so far.
Ok, so the code actually works...BUT... i need 2 things...
1) Check if the player is the same as the killer then end
2) Set a counter so it dosent arrest the "killer" first time he kills a player
3) kick the player if he rdm more then 5 times
[lua]
function CheckForRDM(victim, _, killer)
if(victim:IsPlayer() && killer:IsPlayer()) then -- Check if they're both players (should be)
if(!killer.LastKillTime) then killer.LastKillTime = 0 end -- Set Kill Time if not exist
if(!killer.LastKillCount) then killer.LastKillCount = 1 end -- Set Kill counter if not exist
if not(victim:Name() && killer:Name()) then - Check if plyaer comits suicide
-- decide what punishment
if not(killer.LastKillCount = 1 ) then -- Check if its the first time the killer kills the same person
if(killer.LastKillCount < 4 ) then -- If killer have killed less then 4 times then continue
if(killer.LastKillTime < CurTime() - 120) then -- Check if the killers last kill time was under 120 seconds
PrintMessage( HUD_PRINTTALK, (killer:Name().." has been arrested for RDM!")) - Send text to all players chat!
game.ConsoleCommand("rp_arrest "..killer:Name().." 120\n")
end
else -- If killer have killed more then 4 times kick the person
game.ConsoleCommand("ulx "..killer:SteamID().." Kicked for RDM\n")
end
end
end
else
killer.LastKillTime = CurTime()
end
end
end
hook.Add("PlayerDeath", "RdmCheck", CheckForRDM)
[/lua]
[QUOTE=TeddyBear;23374584]I’m trying to code a new script for a roleplay server.
The script itself should jail the "killer" if the "killer" kills the same person within 2 mins after respawn.
This is how I want the script to act:
1) Player Die
2) Set a counter( reset if it’s not the same killer:SteamID)
3) Check following statement...If the last "killer:SteamID" is the same then teleport "Killer:SteamID" using darkrp command (teleport to jail)
5) Make a public send msg ("Killer:SteamID has automaticlly arrested for RDM")
I have been searching lua and this is what i came up with.
[URL]http://wiki.garrysmod.com/?title=Hook.Add[/URL]
So what i want to know is:
1) How do i save the Killer:SteamID and Victim:SteamID in some kinda global varible.
2) How do i compare them ...should i use the timer function?
Something like this....
-------------------------------------------------------------------------
function CheckforRDM(victim,killer,checktime)
If killer:SteamID = lastKillerSteamID and checktime > 120 then
PrintMessage(HUD_PRINTTALK,killer:SteamID().." has been arrested for RDM!\n");
game.ConsoleCommand("rp_arrest" + killer:SteamID);
end
hook.Add("PlayerDeath","informTheVictims",CheckforRDM)
--------------------------------------------------------------------------
Hope someone can help me make this script.[/QUOTE]
what would one have to type in what file to make it so that Police and gang members called The Bloods Gang and The Crpts Gang and Crypts Gang Boss and Bloods Gang Boss Do not have to worry about this system
Sorry, you need to Log In to post a reply to this thread.