clientside ply:SteamID()

How do I use this on a clientside script?

Specifically, a HUD that shows the SteamID of the person it’s being rendered on.

so nobody knows :confused:

[lua]
if SERVER then
function SendSteamIDToClient(ply)
ply:SetNWString(“SteamID”,ply:SteamID())
end
hook.Add(“PlayerInitialSpawn”,“SendStmID”,SendSteamIDToClient)
end

if CLIENT then
local meta = FindMetaTable(“Player”)
function meta:SteamID()
return self:GetNWString(“SteamID”);
end
end
end
[/lua]

http://www.facepunch.com/showthread.php?t=778190

wait so a NWString goes between server and client? I only thought it went between scripts, but in the same instance

Are you making the hud for only your server? If so, his method would work. If not, use the link I gave you. The only problem with that is, they’d have to DL that module.

NWString is meant for making variables accessible serverside and clientside, global variables are meant for sharing variables between scripts.

ah ok. right now im having some trouble with NWString - can you explain this?

[lua]
function PlayerInitialSQLSpawn( ply )

timer.Create("Steam_id_delay", 2, 1, function( ply ) --wait til the steamID is available
local SteamID = ply:SteamID()
ply:SetNWString("SteamID", SteamID) --make it a network variable
player_exists( ply )
end, ply)

end

hook.Add( “PlayerInitialSpawn”, “PlayerInitialData”, PlayerInitialSQLSpawn )
[/lua]

[editline]02:38PM[/editline]

Hook ‘PlayerInitialData’ Failed: ShadowRP\gamemode\playerdata.lua:40: attempt to call method ‘GetNWString’ (a nil value)

It would help if you’d give line 40.

the player object is not valid on line 40

[editline]04:54PM[/editline]

hence method GetNWString is non-existant.

it’s line 11 where I posted it there (the error says the name of the hook)

Show us the source of player_exists().

do you mean that the hook doesn’t pass the ply argument? that’s the message I got, but I know that playerinitialspawn does pass ply, yet I can’t get it to work…

Wrong. If the player object was NULL, the error would be about the object being NULL. If the variable was nil, the error would be about the value being nil. Non-existing function errors only get thrown when the function doesn’t exist.

Post the function line 40 is in and the line you are calling it from.

i did :confused: its line 11 in the lua I posted

i fixed it, I had ply in the function () following the timer, as well as at the “end, ply)”

i removed the first one and it worked

here it is again:

[lua]
function PlayerInitialSQLSpawn( ply )

timer.Create("Steam_id_delay", 2, 1, function( ply ) --here's the extra ply that fucked it up
local SteamID = ply:SteamID()  
ply:SetNWString("SteamID", SteamID) --make it a network variable  
player_exists( ply )  
end, ply)  

end

hook.Add( “PlayerInitialSpawn”, “PlayerInitialData”, PlayerInitialSQLSpawn )
[/lua]

Now you can just as well remove the ply at the end, since it uses the ply passed to PlayerInitialSpawn directly now.

Why are you using that shitty code? Really a timer? What for? Just do what Gbps did.

The steamid isn’t available until after a few milliseconds from the initial spawn.

Then use the PlayerAuthed hook?

[lua]function SendSteamIDToClient( ply, steamid )
ply:SetNWString( “SteamID”, steamid )
end
hook.Add( “PlayerAuthed”, “SendStmID”, SendSteamIDToClient )[/lua]

The player entity isn’t valid when PlayerAuthed is called.