I'm making this add on/script for darkrp, that will jail someone on death and increase jail time if they have crime. (jail time increases hasn't been added yet)
So far this is what I have and I cant seem to get it too work...
[CODE]local crimecount = 0
hook.Add("PlayerDeath","CheckKillCount",function(ply,dmg,attacker)
if attacker:Frags()%1==0 then
print(crimecount)
crimecount = crimecount + 1
end
end)
function GM:PlayerDeath( ply, inflictor, attacker )
if crimecount > 1 then
print(crimecount)
RunConsoleCommand("darkrp arrest "..ply)
end
end [/CODE]
The error I'm getting is lua:12 attempt to index global 'GM' (a nil value), I've tried to remove this the error doesn't pop up but it wont work at all.
Thanks to anyone who is willing to help in advance! :)
You're not storing the variable to a player, and you're not using a hook for the second one. Also, %1 always returns 0.
[code]hook.Add( "PlayerSpawn", "CrimeShit", function( ply )
ply.crimecount = 0 -- Make sure crimecount always exists and is reset
end )
local crimetime = 30
hook.Add( "PlayerDeath", "CrimeShit",function( ply, _, attacker )
if ( attacker:IsPlayer() ) then
attacker.crimecount = attacker.crimecount + 1 -- Increase crime
end
if ( ply.crimecount ~= 0 ) then -- If the player committed a crime during their life
ply:arrest( ply.crimecount * crimetime ) -- Send them to prison
end
end )[/code]
[QUOTE=code_gs;50824922]You're not storing the variable to a player, and you're not using a hook for the second one. Also, %1 always returns 0.
[code]hook.Add( "PlayerSpawn", "CrimeShit", function( ply )
ply.crimecount = 0 -- Make sure crimecount always exists and is reset
end )
local crimetime = 30
hook.Add( "PlayerDeath", "CrimeShit",function( ply, _, attacker )
if ( attacker:IsPlayer() ) then
attacker.crimecount = attacker.crimecount + 1 -- Increase crime
end
if ( ply.crimecount ~= 0 ) then -- If the player committed a crime during their life
ply:arrest( ply.crimecount * crimetime ) -- Send them to prison
end
end )[/code][/QUOTE]
Thank you so much and sorry for the late response, this will help a great deal!
Sorry, you need to Log In to post a reply to this thread.