how do i make a piece of code execute when the player spawns for the first time? i heard of ply:InitialSpawn but am currently unable to use it correctly.
thanks in advance
This is for the first time they connect.
[code]function FirstSpawn( ply )
ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )[/code]
[url]http://wiki.garrysmod.com/?title=PlayerInitialSpawn[/url]
Note that if you're defining it in your gamemode's files you can write it this way :
[code]function GM:PlayerInitialSpawn( ply )
ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
end[/code]
This is for everytime they spawn :
[url]http://wiki.garrysmod.com/?title=PlayerSpawn[/url]
ok so just to clarify, i can get it to read the information of the player from a .txt file with that function?
You can do the reading/writing of information at any point. So yeah if you make a function to retrieve and set information there nothing's stopping you. I do suggest you use player data tough, a lot simpler and will stay between connections. And NWInt to keep it during a session.
[url]http://wiki.garrysmod.com/?title=Player.SetPData[/url]
[url]http://wiki.garrysmod.com/?title=Player.GetPData[/url]
[url]http://wiki.garrysmod.com/?title=Entity.SetNetworkedInt[/url]
[url]http://wiki.garrysmod.com/?title=Entity.GetNetworkedInt[/url]
example :
[code]function Money( ply, moneytoadd )
playermoney = moneytoadd + ply:GetNetworkedInt("money")
ply:SetNetworkedInt("money", playermoney )
ply:SetPData("money", playermoney )
end[/code]
[code]function GM:PlayerInitialSpawn( ply )
ply:SetNetworkedInt("money", ply:GetPData("money") )
end[/code]
Sorry, you need to Log In to post a reply to this thread.