Hey attempting to do team saving on a darkrp server.
ive tried this method:
Requesting help with a DarkRP PData Job Saving system
no luck did not work
ive also tried a pdata saving method with no luck
any help would be appreciated thanks.
That's odd, why wouldn't PData work? Are you using the correct hook when he connects? The code in the thread you linked should work (And the OP said it does) so can you share with us what you have so far?
There's one problem with this method I believe tho.
If I'm not mistaken the TEAM_* variables are ENUMs, and if one team gets added or others get deleted the team number might change and making the PData basically invalid.
but it should set me to a team at least right, because currently it dosnt even change the player.
PlayerInitialSpawn - From experience this does not LOAD when the player fully loads in, this loads when the player is created meaning some functions do not work.
Also why are you saving it when they spawn?
Calling PData continuesly is silly, you should only call it once, and save it once.
Gmod has a function called https://wiki.garrysmod.com/page/GM/OnPlayerChangedTeam... so it should look more like this:
-- SERVER (sv file)
util.AddNetworkString( "PlayerFullyLoaded" )
hook.Add( "PlayerDisconnect", "fv_saveteamdisconnnect", function( ply )
ply:SetPData( "fv_savedteam", ply:Team() )
end )
net.Receive( "PlayerFullyLoaded", function( ply )
if !ply.FullyLoaded then
ply.FullyLoaded = true
ply:SetTeam( tonumber( ply:GetPData( "fv_savedteam" ) ) )
ply:Spawn()
end
end )
-- CLIENT (cl file)
hook.Add( "InitPostEntity", "fv_playerfullyloaded", function( ply )
net.Start( "PlayerFullyLoaded" )
net.SendToServer()
end )
If this doesn't work, then you either for some reason don't have an sv.db or you broke PData.
This calls when the player has fully loaded in. Hope it helps! ~long time no see btw.
ok so using the post init hook is producing an error saying that ply is not valid
hook.Add("InitPostEntity", "fv_savedteamspawn", function(ply)
fvst = tonumber(ply:GetPData("fv_savedteam"))
ply:changeTeam(fvst,true)
end)
Bud, heres the wiki with literally everything you need: Garry's Mod Wiki
Always search this for the functions you are trying to use
InitPostEntity does not pass the player entity, or anything. You can use it clientside to check when the LocalPlayer is officially fully loaded as is shown above by Jacob
My true question would be (as this seems like your first attempt at LUA), why are you here? And why is the first thing you are trying something 'hard' at you're level? Thousands of LUA tutorials on youtube, go watch a few, then come back here.
If this came off bad, I am sorry, but its the truth. We all start somewhere, but we all learnt the basics even further then that before exploring more options by reaching out to the community.
(The basic understanding of LUA and how GMOD works, is required before you post stuff, we arn't here to spoonfeed, we are here to HELP. Different meanings.)
Sorry, you need to Log In to post a reply to this thread.