Looking for a script to teleport back. Example you set a point with f5, if you press f4 you will teleport back to the point you have set. Can anyone help me with this?
This shouldn’t be hard to make
Something like this would probably do it (not tested)
local savedCoords = {x = nil, y = nil, z = nil} -- Define the table and set its values to nil (nothing)
Citizen.CreateThread(function(),
while true do
Citizen.Wait(0)
if IsControlJustPressed(0, 166) then -- f5 (Save coordinates)
currCoords = GetEntityCoords(PlayerPedId()) -- Get our peds placement
savedCoords[x] = currCoords.x -- Overwrite the tables coordinates with the new ones
savedCoords[y] = currCoords.y -- Overwrite the tables coordinates with the new ones
savedCoords[z] = currCoords.z -- Overwrite the tables coordinates with the new ones
end
if IsControlJustPressed(0, 167) then -- f6 (Teleport to coordinates)
x,y,z = table.unpack(savedCoords) -- Get the saved coordinates from the table
if x or y or z == nil then return end -- Check if they are nil, if they are, stop what were doing
SetEntityCoords(PlayerPedId(), x, y, z, 0,0,0,0) -- Teleport to the location of the saved coords
end
end
end)
Hope this helps
Hi thx for trying to help me out but it didn’t work it doesn’t give any errors it just doesn’t do anything.
@Quint_NHC Try this.
local savedVector = nil;
Citizen.CreateThread(function()
while (true) do
local ped = GetPlayerPed();
if (ped and IsControlJustPressed(0, 166)) then -- F5 to save
savedVector = GetEntityCoords(ped);
end
if (ped and savedVector and IsControlJustPressed(0, 167)) then -- F6 to teleport
SetEntityCoords(
ped, savedVector.x, savedVector.y,
savedVector.z, 0, 0, 0, false
);
end
Wait(0);
end
end);
still not working what should I put in the fxmanifest.lua
client_script ‘filename.lua’
client.lua (551 Bytes)
__resource.lua (98 Bytes)
those are my files I still can’t get it to work
the script gave any error? you tried to print something out when the it starts? does it even load the script?
So it doesn’t show any errors it doesn’t print anything and it loads I think
Try to put a print("it loaded or something")
at the bottom of the script and start it.
local savedVector = nil;
Citizen.CreateThread(function()
while (true) do
local ped = GetPlayerPed();if (ped and IsControlJustPressed(0, 166)) then -- F5 to save savedVector = GetEntityCoords(ped); end if (ped and savedVector and IsControlJustPressed(0, 167)) then -- F6 to teleport SetEntityCoords( ped, savedVector.x, savedVector.y, savedVector.z, 0, 0, 0, false ); end Wait(0); end
end);
print (“Script Working”)
Doesn’t Print anything like this and still doesn’t give any errors. When I delete all the code and have it only print Script Working loads gives no errors button doesn’t actually print
Are you stable able to help me?
First and foremost, you should use local ped = PlayerPedId()
instead.
Try adding debug prints under each set of indentations where a control is pressed.
Okay I will go and do that
It worked is there a way to teleport together with the car you are sitting in?
There’s no difference between PlayerPedId()
and GetPlayerPed(-1)
. (Or I just don’t know about it, then correct me please.)
local savedVector = nil;
Citizen.CreateThread(function()
while (true) do
local ped = GetPlayerPed(-1);
if (ped and IsControlJustPressed(0, 166)) then -- F5 to save
savedVector = GetEntityCoords(ped);
end
if (ped and savedVector and IsControlJustPressed(0, 167)) then -- F6 to teleport
local targetEntity = IsPedInAnyVehicle(ped, false)
and GetVehiclePedIsIn(ped, false)
or ped;
SetEntityCoords(
targetEntity, savedVector.x, savedVector.y,
savedVector.z, 0, 0, 0, false
);
end
Wait(0);
end
end);
This will probably work, if not put print everywhere and see what part is not get executed.
PlayerPedId() runs quicker than GetPlayerPed(-1).