• question with Networked Entities
    2 replies, posted
Well after giving a quick read to Networked Entities im now using them but i have a slight question, are they saved ? i mean i have the following [LUA]function GM:PlayerInitialSpawn(ply) ply:InstallDataTable() ply:NetworkVar("Int", 0, "Skillpoints") ply:SetModel( "models/player/odessa.mdl" ) end function GM:PlayerSpawn( ply ) local oldhands = ply:GetHands() if ( IsValid( oldhands ) ) then oldhands:Remove() end local hands = ents.Create( "gmod_hands" ) if ( IsValid( hands ) ) then ply:SetHands( hands ) hands:SetOwner( ply ) -- Which hands should we use? local cl_playermodel = ply:GetInfo( "cl_playermodel" ) local info = player_manager.TranslatePlayerHands( cl_playermodel ) if ( info ) then hands:SetModel( info.model ) hands:SetSkin( info.skin ) hands:SetBodyGroups( info.body ) end -- Attach them to the viewmodel local vm = ply:GetViewModel( 0 ) hands:AttachToViewmodel( vm ) vm:DeleteOnRemove( hands ) ply:DeleteOnRemove( hands ) hands:Spawn() end print("Current SP Are:"..ply:GetSkillpoints()) end -- crude way to test -- function ISaid( ply, text, public ) ply:SetSkillpoints(5) end hook.Add( "PlayerSay", "ISaid", ISaid );[/LUA] so well in theory if NW Entities do save i shoudl be able to write anything in the chat ( Skillpoints get changed to 5 ), rejoin the server and still have 5 right? well it seems im doing someting wrong becouse when i rejoin the value IS 0 so well either im missing someting or ..well probably im missing someting here
The values persist as long as the entity exists. When you disconnect, the old player entity is destroyed, and all associated values are erased. If you were to save the game and then load that save, they should persist, and under the same logic it should persist between levels as well if they are done via transitions ( untested on my part ). You're going to have to save the values in a more persistent manner.
These two are easy to use: [url]http://wiki.garrysmod.com/page/Player/SetPData[/url] [url]http://wiki.garrysmod.com/page/Player/GetPData[/url]
Sorry, you need to Log In to post a reply to this thread.