- Initiateur de la discussion
Malcolm
Psychopathe
- Messages
- 1 096
- Score réaction
- 262
- Points
- 280
Salut, comme indiqué dans le titre je cherche un code pour respawn à l'endroit où on était avant de déco (et non mourrir ^^).
Merci
Merci
hook.Add("PlayerInitialSpawn", "SpawnToPos", function(ply) if not ply:IsValid() then return end if file.Exists("spawntopos/"..ply:SteamID64()".txt", "DATA") then ply:SetPos(file.Read("spawntopos/"..ply:SteamID64()".txt", "DATA") end
end)
hook.Add("PlayerDisconnected", "SpawnToPos", function(ply) if not ply:IsValid() then return end file.Write("spawntopos/"..ply:SteamID64()".txt", ply:GetPos())
end)
ok, prévient moi si sa ne marche pasmalcolm2003 à dit:Merci, je test dès que possible.
NopeZaros_Live à dit:Essaye ceci (j'ai pas tester @Yoh Sambre ♪ m'a obligé à jouer avec lui à fortnite )
A placer dans lua/autorun/server/spawntopos.lua (tu peux changer le nom du fichier bien évidement )Code:hook.Add("PlayerInitialSpawn", "SpawnToPos", function(ply) if not ply:IsValid() then return end if file.Exists("spawntopos/"..ply:SteamID64()".txt", "DATA") then ply:SetPos(file.Read("spawntopos/"..ply:SteamID64()".txt", "DATA") end end) hook.Add("PlayerDisconnected", "SpawnToPos", function(ply) if not ply:IsValid() then return end file.Write("spawntopos/"..ply:SteamID64()".txt", ply:GetPos()) end)
C'est quoi l'erreur?slownls à dit:
WabelGame à dit:C'est quoi l'erreur?
hook.Add("PlayerInitialSpawn", "SpawnToPos", function(ply) if not ply:IsValid() then return end if file.Exists("spawntopos/"..ply:SteamID64()".txt", "DATA") then -- le fichier spawntopos tu le sort d'ou ? ply:SetPos(file.Read("spawntopos/"..ply:SteamID64()".txt", "DATA") -- ta oublie une ")" end
end)
hook.Add("PlayerDisconnected", "SpawnToPos", function(ply) if not ply:IsValid() then return end file.Write("spawntopos/"..ply:SteamID64()".txt", ply:GetPos())-- le fichier spawntopos tu le sort d'ou ?
end)
hook.Add( "Initialize", "PS:Initialize", function() if not file.IsDir( "ps", "DATA" ) then file.CreateDir( "ps" ) end
end)
hook.Add("PlayerInitialSpawn", "PS:Player:InitialSpawn", function( ply ) timer.Simple( 0, function() if file.Exists( "ps/" .. ply:SteamID64() .. ".txt", "DATA" ) then local PS = util.JSONToTable( file.Read( 'ps/' .. ply:SteamID64() .. ".txt", 'DATA' ) ) local PlayerPos = string.Explode( ' ', PS.Pos ) local PlayerAngles = string.Explode( ' ', PS.Ang ) ply:SetPos( Vector( PlayerPos[ 1 ], PlayerPos[ 2 ], PlayerPos[ 3 ] ) ) ply:SetAngles( Angle( PlayerAngles[ 1 ], PlayerAngles[ 2 ], PlayerAngles[ 3 ] ) ) end end)
end)
hook.Add( "PlayerDisconnected", "PS:Player:Disconnect", function( ply ) local PS = {} local PlayerPos = string.Explode( ' ', tostring( ply:GetPos() ) ) local PlayerAngles = string.Explode( ' ', tostring( ply:GetAngles() + Angle( 0, - 90, 0 ) ) ) PS = { Pos = PlayerPos[1] .. ' ' .. PlayerPos[2] .. ' ' .. PlayerPos[3], Ang = PlayerAngles[1] ..' ' .. PlayerAngles[2] .. ' ' .. PlayerAngles[3] } file.Write( "ps/" .. ply:SteamID64() .. ".txt", util.TableToJSON( PS ) )
end)
Merci <3slownls à dit:Code:hook.Add( "Initialize", "PS:Initialize", function() if not file.IsDir( "ps", "DATA" ) then file.CreateDir( "ps" ) end end) hook.Add("PlayerInitialSpawn", "PS:Player:InitialSpawn", function( ply ) timer.Simple( 0, function() if file.Exists( "ps/" .. ply:SteamID64() .. ".txt", "DATA" ) then local PS = util.JSONToTable( file.Read( 'ps/' .. ply:SteamID64() .. ".txt", 'DATA' ) ) local PlayerPos = string.Explode( ' ', PS.Pos ) local PlayerAngles = string.Explode( ' ', PS.Ang ) ply:SetPos( Vector( PlayerPos[ 1 ], PlayerPos[ 2 ], PlayerPos[ 3 ] ) ) ply:SetAngles( Angle( PlayerAngles[ 1 ], PlayerAngles[ 2 ], PlayerAngles[ 3 ] ) ) end end) end) hook.Add( "PlayerDisconnected", "PS:Player:Disconnect", function( ply ) local PS = {} local PlayerPos = string.Explode( ' ', tostring( ply:GetPos() ) ) local PlayerAngles = string.Explode( ' ', tostring( ply:GetAngles() + Angle( 0, - 90, 0 ) ) ) PS = { Pos = PlayerPos[1] .. ' ' .. PlayerPos[2] .. ' ' .. PlayerPos[3], Ang = PlayerAngles[1] ..' ' .. PlayerAngles[2] .. ' ' .. PlayerAngles[3] } file.Write( "ps/" .. ply:SteamID64() .. ".txt", util.TableToJSON( PS ) ) end)
slownls à dit:EDIT : tu as également oublié les "..."
if file.Exists ("spawntopos/" .. ply:SteamID64() .. ".txt", "DATA" ) thenZaros_Live à dit:Merci <3
Et quand tu dis "..." tu parles de quoi ?
haaa ouislownls à dit:if file.Exists("spawntopos/"..ply:SteamID64()..".txt", "DATA") then
hook.Add( "Initialize", "PS:Initialize", function() if not file.IsDir( "ps", "DATA" ) then file.CreateDir( "ps" ) end
end)
hook.Add("PlayerInitialSpawn", "PS:Player:InitialSpawn", function( ply ) timer.Simple( 0, function() if file.Exists( "ps/" .. ply:SteamID64() .. ".txt", "DATA" ) then local PS = util.JSONToTable( file.Read( 'ps/' .. ply:SteamID64() .. ".txt", 'DATA' ) ) local PlayerPos = string.Explode( ' ', PS.Pos ) local PlayerAngles = string.Explode( ' ', PS.Ang ) ply:SetPos( Vector( PlayerPos[ 1 ], PlayerPos[ 2 ], PlayerPos[ 3 ] ) ) ply:SetAngles( Angle( PlayerAngles[ 1 ], PlayerAngles[ 2 ], PlayerAngles[ 3 ] ) ) for k,v in pairs( PS.Weapons ) do ply:Give( v ) end end end)
end)
local BlackListSaveWeapons = { ['weapon_fists'] = true, ['weapon_physgun'] = true, ['weapon_physcannon'] = true, ['gmod_tool'] = true, ['gmod_camera'] = true, ['weapon_medkit'] = true, ['pocket'] = true, ['med_kit'] = true, ['keys'] = true, ['arrest_stick'] = true, ['unarrest_stick'] = true, ['stunstick'] = true, ['weaponchecker'] = true, ['door_ram'] = true, ['weapon_keypadchecker'] = true,
}
hook.Add( "PlayerDisconnected", "PS:Player:Disconnect", function( ply ) local PS = {} local Weapons = {} for k,v in pairs( ply:GetWeapons() ) do if BlackListSaveWeapons[ v:GetClass() ] then continue end table.insert( Weapons, v:GetClass() ) end local PlayerPos = string.Explode( ' ', tostring( ply:GetPos() ) ) local PlayerAngles = string.Explode( ' ', tostring( ply:GetAngles() + Angle( 0, - 90, 0 ) ) ) PS = { Pos = PlayerPos[ 1 ] .. ' ' .. PlayerPos[ 2 ] .. ' ' .. PlayerPos[ 3 ], Ang = PlayerAngles[ 1 ] .. ' ' .. PlayerAngles[ 2 ] .. ' ' .. PlayerAngles[ 3 ], Weapons = Weapons } file.Write( "ps/" .. ply:SteamID64() .. ".txt", util.TableToJSON( PS ) )
end)
hook.Add( "PlayerDisconnected", "PS:Player:Disconnect", function( ply ) ply:SetPData("lastpos", "{" .. ply:GetPos().x .. "," .. ply:GetPos().y .. "," .. ply:GetPos().z .. "}") ply:SetPData("lastang", "{" .. ply:GetAngles().x .. "," .. ply:GetAngles().y .. "," .. ply:GetAngles().z .. "}")
end)
hook.Add("PlayerInitialSpawn", "PS:Player:InitialSpawn", function( ply ) if ply:GetPData("lastpos", "unknown") ~= "unknown" then local pos = util.JSONToTable(ply:GetPData("lastpos")) local ang = util.JSONToTable(ply:GetPData("lastang")) ply:SetPos( Vector( pos[1], pos[2], pos[3] ) ) ply:SetAngles( Angles ( ang[1], ang[2], ang[3] ) ) end
end)