InitPostEntity | Help

Well, I am basically trying to Initialize the player… by that I mean turn player to a LocalPlayer()/ply you know…

Returns the player object of the current client.

– Off the Webpage of LocalPlayer --------------------------------------------------------------
LocalPlayer() will return NULL until all entities have been initialized. See GM:InitPostEntity.

hook.Add( "InitPostEntity", "some_unique_name", function()
	print( "Initialization hook called" )
end )

So how can you Initialize all entities aka Player, so my bloody NWInt’s will load. They only work if you refresh, but I think theres a way to initialize players with InitPostEntity? Or does it just return true when all the entities/players have been read?

What? The point of that hook is to be called once the client is loaded in. LocalPlayer just returns your player entity. NW* have no collocation with either of these except for the fact you can call it on LocalPlayer

Well, on the website. It says: LocalPlayer is = null… please help man. I wan’t to loadup LocalPlayer on join!

[editline]17th August 2016[/editline]

And, else on join LocalPlayer dosen’t register…

In what context are you using LocalPlayer() that it needs to be set at the very second the game starts up?
Also, this should probably be in the ‘Problems that don’t need their own thread’ thread

Please help!

[editline]17th August 2016[/editline]

Sorry, ill put it in that thread. But for now, how do you verify Localplayer() on startup?

[editline]17th August 2016[/editline]

And if it’s run at the VERY second player joins, then my: LocalPlayer():GetNWInt() will work… else I have to refresh, and its annoying! And, DarkRP has that function somewere… every thing does, so does PointShop… I just dont know how to do it! And it will look ugly, when someone joins; Were’s my Money?, get’s me to refresh. Done! :’(

[editline]17th August 2016[/editline]


if !IsValid(LocalPlayer()) then
-- Something here??!?

Wait… so if you want to use GetNWInt and SetNWInt on a player - but only once they’re actually connected, then why not use a

GM:PlayerInitialSpawn hook and set all the network stuff there?

Because it dosen’t work, and I wan’t to set LOCALPLAYER up when they join, so my HUD and Scoreboard will display how much LocalPlayer:GetNWInt( “money” ) they have!

[editline]17th August 2016[/editline]

I use on my HUD & Scoreboard:

client = LocalPlayer()

but always reads Error, unless I refresh the file so LocalPlayer() sets up…

If you want to display their money on a HUD/scoreboard, then all you need to do is put this INSIDE whatever hook you’re using to draw the HUD:

local money = LocalPlayer():GetNWInt( "money" )

HUDPaint hooks and drawing hooks only get run when LocalPlayer() is valid, so it’s the perfect spot to get LocalPlayer(), and get their money. Also, putting it inside the hook will ensure that the player’s money amount will be up to date if the network integer changes.

There’s nothing wrong with calling GetNWInt inside HUDPaint or a similar hook, to my knowledge it’s not laggy or anything like that, so I don’t see a reason to have it outside of the hook, where LocalPlayer() will be nil until it gets actually set

[editline]17th August 2016[/editline]

If you want to use it on a scoreboard or something vgui-related, then you just need to override the Paint or Think function of any panel used on your scoreboard, e.g.

function somepanel:Think() -- this can be any panel at all- you could also use Paint
    money = LocalPlayer():GetNWInt( "money" ) -- update the money variable so if it changes, it'll still display the correct number

Thanks, but how do I “set” LocalPlayer() this is the question I was kinda trying to get at.

What do you mean set localplayer? Localplayer will always be the person running the client side file.

You can’t set LocalPlayer(). The game sets it once the LocalPlayer() is actually in the game. There’s nothing you can do to speed it up or slow it down, so, as I was trying to say, just set whatever needs to be set with LocalPlayer() IN THE DRAWING HOOK and there shouldn’t be any problems

For example:

local ply1 = LocalPlayer() -- this WILL NOT be valid

hook.Add( 'HUDPaint', 'LOCAL PLAYER MATE', function()

    local ply2 = LocalPlayer() -- this WILL be valid

end )

And for whatever vgui stuff you have:

local ply1 = LocalPlayer() -- this WILL NOT be valid

function SOMEPANEL:Think()

    local ply2 = LocalPlayer() -- this WILL be valid