• save coordinates of the player
    7 replies, posted
Saving coordinates player when exiting. And teleport players to these coordinates in the spawn. What am I doing wrong? [CODE] local function spawn( ply ) print( ply:Nick().. " has spawned!." ) ply:SetPos(ply:GetPData("SavePos") or nil) end hook.Add( "PlayerSpawn", "TheSpawn", spawn ) local function onDisc( ply ) print( ply:Nick().. " has exit!!!!" ) ply:SetPData("SavePos", ply:GetPos()) end hook.Add( "PlayerDisconnected", "TheExit", onDisc ) [/CODE]
Well, if they exit, the pdata gets removed, doesn't it? [B]EDIT:[/B] Nevermind, I think it doesn't get removed, maybe this code works on multiplayer but not on singleplayer since you're creating a different server each time or something? I don't know..
You can't write a Vector to SQL. You need to serialize it first.
[QUOTE=RealDope;49524829]You can't write a Vector to SQL. You need to serialize it first.[/QUOTE] How can i do this?
Perhaps save the players xpos, ypos and zpos separately then when you spawn them in do something like [lua]ply:SetPos( xpos, ypos, zpos ) [/lua] and when saving a vector [lua] local pos = ply:GetPos() xpos = pos.x ypos = pos.y zpos = pos.z [/lua] there might be a better way to do this but idk.
Save [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/tostring]Global.tostring[/url] Load [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/StringToType]util.StringToType[/url]
When saving the position of the player use [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/util/TypeToString"]util.TypeToString[/URL] on the vector. And when setting the position of the player, use [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/util/StringToType"]util.StringToType[/URL] on the pdata, though make sure what you what get from it isn't nil before you try to set the position of the player. -ninja'd-
i do this! thx all for help :)
Sorry, you need to Log In to post a reply to this thread.