Hello guys,
i've
little strange problem, i've a script on my server but it doesn't work
since i've update darkrp. i think that i've fund the problem but it is
really strange.
I set DarkRPVar on serverside, the DarkRPVar is well recovered clientside but on serverside it return me nill.
code that set DarkRPVar :
function DarkRP.retrievePlayerLevelData(ply)
DarkRP.retrievePlayerLevelXP(ply,function(data)
if not IsValid(ply) then return end
local info = data and data[1] or {}
info.xp = (info.xp or 0)
info.level = (info.level or 1)
ply:setDarkRPVar('xp', info.xp)
ply:setDarkRPVar('level', info.level)
if not data then DarkRP.createPlayerLevelData(ply) end
end)
end
clientside code : (var is coorect)
draw.DrawText('Level: '..(ply:getDarkRPVar('level') or 0), "DarkRPHUD2", pos.x, pos.y -58, Color(0,0,0,255), 1)
serverside code : (return false beceause darkrpvar is nill)
hook.Add('playerCanChangeTeam', 'manolis:MVLevels:playerTeamChange', function(ply, jobno)
// This one requires a little extra work
job = RPExtraTeams[jobno]
if (job.level) then
if not ((ply:getDarkRPVar('level') or 0) >= (job.level)) then
DarkRP.notify(ply, 1, 2, 'You\'re not the right level to
become this! your level : '..(ply:getDarkRPVar('level') or 0))
return false, true
end
end
end)
Funnily I've just faced up this bug yesterday. The thing is DarkRP.retrievePlayerLevelData getting called in PlayerInitialSpawn hook, but I think this is so early for setDarkRPVar to actually set the damn var. I've just put a call of this function in hook in timer.Simple on 1 second
It's working thank's you
if you need to do something with a player when they spawn for the first time do this
hook.Add("PlayerInitialSpawn","NAME",function(ply)--hook is called when a player spawns for the first time, though ply could point to an entity that has yet to be created
timer.Simple(0,function()--delay by one frame
if ply:IsValid() then--check if they're valid now
--what ever code you need to run
end
end)
end)
Sorry, you need to Log In to post a reply to this thread.