Playerspawn hook issue

The problem is that I have written a jail system and I want it so when the player respawns, their jail gets reapplied (weapons taken etc):

This doesnt seem to work (from the wiki too):

function playerRespawn( ply )
if HasJail( ply ) == true then
GiveJail( ply )
hook.Add( “PlayerSpawn”, “playerRespawn”, playerRespawn )

Exepct this code doesnt work…nothing happens. I even added a line to send everyone text when a player respawned - also failed so its not due to error within the actual function.

Omg someone please answer end of the world omfgwtfbbq.

O shit this was made as a new post :expressionless:

Urrghh yeah I tried renaming everything and that didnt work…any ideas?

Use [noparse][lua][/lua][/noparse] tags…

why did you bump your own thread 2 hours later…

Also we need more of the lua than just that.

function playerRespawn( ply )
if HasJail( ply ) == true then
GiveJail( ply )
hook.Add( "PlayerSpawn", "playerRespawn1123", playerRespawn )

check console after you respawned to see if it worked.
The middle hook is your custom name for it. If something you have has the same name they will conflict.

Didnt work, nothing showed up :frowning:


Why? Its a function…everything else in the script works fine lol.

Is this running on the server?



Checked: its deff a serverside hook.


Can this hook only be called once?

[lua]function playerRespawn( ply )
if ( ply:HasJail() ) then
ply:GiveJail( )
hook.Add( “PlayerSpawn”, “playerRespawn”, playerRespawn )[/lua]

If that doesn’t work, paste your serverside console log in

tags here.


ERROR: Trying to derive entity sent_nuke_radiation from non existant entity base_point!
Sending 1496 ‘User Info’ ConVars to server (cl_spewuserinfoconvars to see)
Updated DuaFiles (1406)
Hook ‘playerRespawn’ Failed: autorun/server/FHadmin.lua:70: attempt to call global ‘Sendtextall’ (a nil value)
Can’t ban users with ID “UNKNOWN”
Writing cfg/banned_user.cfg.
AdvDupeShared: Server Compression: false

=== Wire 1222 Installed ===

=== RD2 7 Installed ===

— Missing Vgui material texturemissing
Redownloading all lightmaps
==sending netbeamvar var data to Player [1][[FH][A]Ratboy]
==sending Beam data to Player [1][[FH][A]Ratboy] ==
[FH][G] [FH][A]Ratboy has jailed [FH][A]Ratboy
] kill
[FH][A]Ratboy suicided!

Didnt jail me, nothing happened. However this, from the log :
Hook ‘playerRespawn’ Failed: autorun/server/FHadmin.lua:70: attempt to call global ‘Sendtextall’ (a nil value)


The sendtextall function:

local function Sendtextall( text )
for k, v in pairs(player.GetAll()) do
v:PrintMessage( HUD_PRINTTALK, "[FH][G] " … text );


Line 70:

It will work if you comment out the SendTextAll line… What’s your code for SendTextAll function?

I posted it in the above post lol…

You have the sendtextall function in the same lua file as the playerrespawn hook right?

Just commented it and another nil error value:

Hook ‘playerRespawn’ Failed: autorun/server/FHadmin.lua:71: attempt to call method ‘HasJail’ (a nil value)

HasJail and SendTextAll work in every other function - theres around ten other functions! This function is just occuring nil errors - no idea :S




Thats why I really dont understand why its not working :frowning:

Wait… your not using metatables… haha sorry.
Change your code to the original way you had it.
I don’t know sorry. :frowning: You should use metatables though.

Evenso, logically this should work and its not :S I have other hooks and functions and they all work fine…Garrysmod bug?


I did just realise you forgot to put ply (to pass the player object on). However I just added it - still a nil error.

Basically I think the hook is providing a nill value for the player being spawned.


Ok I just emptied the whole script and had only the sendtextall and respawn function+hook obv. Still a nil error…


OO I realised I added print wrong when I did it earlier, I just readded it and it does print text to the server console fine. So the error is related to the functions…


AHOY! I have found the problem yayz!

The functions cannot be local…thats whats causing the error! Aw I should have figured, its like in .net with private classes being called directly from public ones - or something. Yayz! I have to popout now, when I get back I will begin making everything non-local that is required by that function.

However I just realised that another hook uses HasJail (local function) and works fine…this is a Garrysmod permissions bug?


Also btw guys, thanks for the help :slight_smile:

Its always nice to know I can drop by here and recieve 24/7 help. I should really make a public addon to contribute to the community :smiley: I will see what I can do :stuck_out_tongue: