Has anyone else had the problem of the player argument being passed to on spawn hook being null?
I am trying to figure out when it happens so I can work around it :-S
Encompass the entire hook in a simple timer with 0.1 second delay.
[QUOTE=Dr Magnusson;25614209]Encompass the entire hook in a simple timer with 0.1 second delay.[/QUOTE]
I was looking more for a reason, then anything, the function that is run on the hook, is a C++ one so not really helpfull unless I know WHY
I think it's related to how much lua you get thrown at you to initialize
with a lot of addons it could take longer for the player to be valid. at least this is what I've experienced
[QUOTE=CapsAdmin;25615328]I think it's related to how much lua you get thrown at you to initialize
with a lot of addons it could take longer for the player to be valid. at least this is what I've experienced[/QUOTE]
Ahh okay thankyou, so it is because player not initialized yet, hmmm, I think I could cheat using a lua function on a timer after InitialSpawn, that calls the C++ function
If you want the client to tell the server it's ready you can always do this.
[lua]
local createdLocalPlayer = false;
function GM:OnEntityCreated(entity)
if (entity == LocalPlayer() and !createdLocalPlayer) then
timer.Simple(0.2, function()
RunConsoleCommand("PlayerHasInitialized");
end);
createdLocalPlayer = true;
end;
end;
[/lua]
[QUOTE=_Chewgum;25615449]If you want the client to tell the server it's ready you can always do this.
[lua]
local createdLocalPlayer = false;
function GM:OnEntityCreated(entity)
if (entity == LocalPlayer() and !createdLocalPlayer) then
timer.Simple(0.2, function()
RunConsoleCommand("PlayerHasInitialized");
end);
createdLocalPlayer = true;
end;
end;
[/lua][/QUOTE]
Actually I just want something to run on Initial spawn, that can access the players steam ID and Name and UniqueID (it looks it up in a database and returns the forum ID of the player)
[QUOTE=_Chewgum;25615449]If you want the client to tell the server it's ready you can always do this.
[lua]
local createdLocalPlayer = false;
function GM:OnEntityCreated(entity)
if (entity == LocalPlayer() and !createdLocalPlayer) then
timer.Simple(0.2, function()
RunConsoleCommand("PlayerHasInitialized");
end);
createdLocalPlayer = true;
end;
end;
[/lua][/QUOTE]
why do you need a timer in there?
[QUOTE=_Chewgum;25615449]If you want the client to tell the server it's ready you can always do this.[/QUOTE]
[lua]function GM:InitPostEntity()
RunConsoleCommand( "PlayerHasInitialized" )
end[/lua]
No need for extra variables or timers.
[QUOTE=raBBish;25615790][lua]function GM:InitPostEntity()
RunConsoleCommand( "PlayerHasInitialized" )
end[/lua]
No need for extra variables or timers.[/QUOTE]
And that will run once the Player is initialized? thankyou
[QUOTE=raBBish;25615790][lua]function GM:InitPostEntity()
RunConsoleCommand( "PlayerHasInitialized" )
end[/lua]
No need for extra variables or timers.[/QUOTE]
I think someone told me once that the player might not be valid there sometimes.
[QUOTE=raBBish;25615790][lua]function GM:InitPostEntity()
RunConsoleCommand( "PlayerHasInitialized" )
end[/lua]
No need for extra variables or timers.[/QUOTE]
You tested this?
[QUOTE=CapsAdmin;25615491]why do you need a timer in there?[/QUOTE]
just to make sure the client really runs the command or something lol
[QUOTE=_Chewgum;25615859]You tested this?
just to make sure the client really runs the command or something lol[/QUOTE]
Quick follow up question, this work on Initial spawn, or every spawn?
[QUOTE=nekosune;25616499]Quick follow up question, this work on Initial spawn, or every spawn?[/QUOTE]
you hook a concommand "PlayerHasInitialized", serverside and set all the stuff you want to the player there.
It's only ran once.
I knew I had to hook up a conncommand, just altered my binary to use concommand.Add rather then hook.Add, just tried it anyway since got no reply, and works exactly how I wished, thankyou all.
Clientside:
[lua]function GM:OnEntityCreated( ent )
if (ent == LocalPlayer()) && ValidEntity( ent ) then RunConsoleCommand( "PlayerHasInitialized" ) end
end[/lua]
Player guaranteed to be valid.
[QUOTE=thomasfn;25620116]Clientside:
[lua]function GM:OnEntityCreated( ent )
if (ent == LocalPlayer()) && ValidEntity( ent ) then RunConsoleCommand( "PlayerHasInitialized" ) end
end[/lua]
Player guaranteed to be valid.[/QUOTE]
in my test the localplayer entity was created 2 times.
edit:
oh wait, silly me. thomasfn is right
[QUOTE=_Chewgum;25620619]in my test the localplayer entity was created 2 times.[/QUOTE]
Twins, congratulations!
You can use GM:Initialize() which is when the game mode initializes, by then the player must have.
[QUOTE=foxxeh;25623077]You can use GM:Initialize() which is when the game mode initializes, by then the player must have.[/QUOTE]
it says on the wiki for that though:
[quote]If you need to do anything with entities, you should be using Gamemode.InitPostEntity, since all entities have been initialized when that hook gets called. This one gets called right when the server (re)starts.[/quote]
You guys should read through SDK code a little more to see how the game works.
[QUOTE=amcwatters;25623443]You guys should read through SDK code a little more to see how the game works.[/QUOTE]
I have what I wished working fine now thanks to the help here, and yes I do mostly, I just thought would get a quicker cleaner answer here, rather then confusion
[QUOTE=nekosune;25623313]it says on the wiki for that though:[/QUOTE]
Meh. I prefer initialize anyway, more of a habit.
[QUOTE=foxxeh;25624555]Meh. I prefer initialize anyway, more of a habit.[/QUOTE]
It's not a habit thing though. If you use Initialize it won't work:saddowns:
Oh come on I am talking about it being null on passed to a hook being called in a binary, how is this newbie?
Sorry, you need to Log In to post a reply to this thread.