Weapon given upon arrested

I can’t get this simple script to work. What am I doing wrong?


function JailFist()
	for k, ply in pairs(player.GetAll()) do
		if ply:isArrested( ) then
		ply:Give( "weapon_fists" )
	end
end
hook.Add( "onArrested", "JailFist", JailFist )

If this is correct and should work. Then could it be a core file overriding?

  1. A quick google search tells me it should be ‘playerArrested’, not ‘onArrested’
  2. That hook will tell you the player, you don’t need to loop through every player.

[lua]local function JailFist(ply)
ply:Give(“weapon_fists”)
end
hook.Add(“playerArrested”,“Give fist on arrest”,JailFist)[/lua]

Oh ok thanks dude.
I over complicate everything haha

[editline]16th September 2014[/editline]

It’s still not working. The core file is probally overriding!

It’s possible, depending on how it’s coded, that your weapons get stripped AFTER you are arrested.
If that is the case then wrapping it in a timer should work.
Either way, add a print so you can see if it is actually being called.
[lua]local function JailFist(ply)
print(“JailFist called for”,ply)
timer.Simple(0.1, function()
ply:Give(“weapon_fists”)
end)
end
hook.Add(“playerArrested”,“Give fist on arrest”,JailFist)[/lua]

That does not work either… Hmm

What file are you putting this code in?

darkrpmodification/lua/darkrp_modules/Jail/jailfist.lua

Ok, I don’t have any experience with the newest darkrp so I don’t know if that file is automatically loaded or not. If it is, it should be working. You can add another print statement to see if it’s even being loaded.
[lua]
print(“JAILFIST LOADED”)
local function JailFist(ply)
print(“JailFist called for”,ply)
timer.Simple(0.1, function()
ply:Give(“weapon_fists”)
end)
end
hook.Add(“playerArrested”,“Give fist on arrest”,JailFist)[/lua]
Then have a look in your console for JAILFIST LOADED to make sure the file is loading.

[editline]17th September 2014[/editline]

(Automerge pls)

After looking at http://wiki.darkrp.com/index.php/Creating_modules I think you just need to change it’s name to **sv_**jailfist.lua

Yeah I did name it sv_jailfist.lua
forgot to add the sv_ in the file location when you asked. :stuck_out_tongue:

[editline]16th September 2014[/editline]

It’s loading

So it prints when it loads but it doesn’t print on arrest? I’m stumped.

Maybe because I am force arresting myself via ULX?

Bump

Have you tried arresting someone the standard way?
Otherwise I see no reason why the code inside the hook wouldn’t be called, since it is the correct name of the hook.
Post the current code you’re using.


local function JailFist(ply)
    print("JailFist called for",ply)
    timer.Simple(0.1, function()
        ply:Give("weapon_fists")
    end)
end
hook.Add( "playerArrested", "JailFist", JailFist )

Hmm. Anyone know away around the DarkRP core override?

Have you tried maybe using a playerloadout hook? Looking at the darkrp code, when you’re arrested it actually force spawns you after teleporting you, maybe using playerArrested actually is giving you the weapon, but it’s removed when you spawn again.

That’s why I suggested using the timer, so it gives the weapon after you have been respawned/stripped.