Function doesnt get called by hook?

Hey guys, I am making an addon and in the addon, there is a list of every staff. when ever a staff player joins I want the game to readd the player by using a table containing every steamid of every staff.

I already have the table and stuff figured out and I know it works for a fact. How ever, when ever I try this code the function ‘PA_reapplyStaff()’ just doesnt seem to get called at all?



hook.Add("PlayerConnect", "PA_PlayerConnect", PA_PlayerConnect)
local function PA_PlayerConnect(name, ip)
	PA_Broadcast('PA_colorGood, "' .. name .. '", PA_colorDefault, " connected to the server"')

	PA_reapplyStaff(name)
	
	return ""
end


BUT! When ever I run the function ‘PA_reapplyStaff()’ by writing something then saving it, causing the code to be refreshed, it works.

I even tried to make the function inside a timer because I thought the function couldnt be called while the player was still joining. But to no luck, the function still wasnt called.

Am I missing

You are attempting to hook a function that doesn’t exist, then creating the function. Put hook.Add at the end.

Or even better,

[lua]
hook.Add(“PlayerConnect”, “PA_PlayerConnect”, function(name, ip)
PA_Broadcast(‘PA_colorGood, "’ … name … ‘", PA_colorDefault, " connected to the server"’)
PA_reapplyStaff(name)
return “”
end)
[/lua]

You mean like this?



local function PA_PlayerConnect(name, ip)
	PA_Broadcast('PA_colorGood, "' .. name .. '", PA_colorDefault, " connected to the server"')
	
	PA_reapplyStaff(name)
	
	return ""
end
hook.Add("PlayerConnect", "PA_PlayerConnect", PA_PlayerConnect)


Didnt change anything.

[editline]21st August 2014[/editline]

Still nothing.

I’m pretty sure theres a problem with your custom functions then, mind posting them?

I thought so too, but when I run PA_reapplystaff() all by it self and refresh the code it works.

Even doing in the console “lua_run PA_reapplyStaff(“OMGOMG132”)” works

EDIT: Here is the code for the function.



function PA_reapplyStaff(plyName)
	//re add staff
	
	local alreadyStaff = false
	local ply = PA_GetByName(plyName)
	//local id = ply:SteamID()
	
	print(plyName)
	
	for k,v in pairs(PA_staff.admins) do
		if(v == id) then
			alreadyStaff = true
		else
			alreadyStaff = false
		end
	end
	
	if(IsValid(ply) && alreadyStaff == false) then
		ply:SetUserGroup("admin")
		
		print(ply:Nick() .. " was made an admin")
		
		return true
	else
		return false
	end
end


Is the PA_Broadcast working as well out side of the hook?

Try using the player authenticated hook rather than player connect.

Yep

It might be because you’re running this before the player is in game, try to use the PlayerInitialSpawn hook instead.

[lua]
hook.Add(“PlayerInitialSpawn”, “PA_PlayerConnect”, function(ply)
PA_Broadcast(‘PA_colorGood, "’ … ply:Nick() … ‘", PA_colorDefault, " connected to the server"’)
PA_reapplyStaff(ply:Nick())
return “”
end)
[/lua]
[editline]sss[/editline]
Oh well, problem solved :dance:

Thanks that worked!