Teleport to player not working

lua

#1

Hello, this is my tp function:

RegisterCommand('tp', function(args, source)
	local localPed = GetPlayerPed(-1)
	local destPed = GetPlayerPed(args[1])
	local coords = GetEntityCoords(destPed)
	SetEntityCoords = (localPed, coords.x, coords.y, coords.z, true, false, false, true)
end, false)

but when i type /tp [name of player] nothing happen
i’m new so please don’t flame me


#2

You don’t use an = for a native. It’s:

SetEntityCoords(localPed, coords.x, coords.y, coords.z, true, false, false, true)

#3

I’ve tried without ‘=’ but nothing has changed


#4

I’ve forgot to say that the script is client side


#5
RegisterCommand('tp', function(source, args, raw)
	local localPed = GetPlayerPed(-1)
	local destPed = GetPlayerPed(args[1])
	local coords = GetEntityCoords(destPed)
	SetEntityCoords = (localPed, coords.x, coords.y, coords.z, true, false, false, true)
end, false)

Are you trying to TP to a player by doing /tp [playerid]???


#6

Like he said, he is looking for a command to /tp [player name] and not /tp [player id]
:face_with_raised_eyebrow:


#7

you will need to loop through the indices and find the right player by matching the name, you can do it easily, but don’t ask me to spoonfeed you, this is all the advices i’ll give you.


#8

I didn’t read the top post I was just looking at comments and missed what he said above so maybe not be rude huh? Also why are you saying something when you aren’t here to help him in the first place.


#9

@Danilo_Maglia have not tested this but maybe try this?

RegisterCommand("tp", function(source, args, raw)
	local name = table.concat(args)
	local player = FindPlayerWithName(name)
	if player ~= nil then
		TeleportToPlayer(player)
	end
end, false)

function TeleportToPlayer(player)
	local lPed = GetPlayerPed(PlayerId())
	local oPed = GetPlayerPed(player)
	local oPedPos = GetEntityCoords(oPed, false)
	SetEntityCoords(lPed, oPedPos.x, oPedPos.y, oPedPos.x, 0.0, 0.0, 0.0, false)
end

function FindPlayerWithName(string)
	local players = GetPlayers()
	for a = 1, #players do
		if GetPlayerName(a) == string then
			return a
		end
	end
	return nil
end

#10

should i put it in client or server?


#11

anyway the script doesn’t work, maybe i did something wrong but i tried it server-side then client-side but it doesn’t work


#12

Just because, as you said, you didnt even took the time to read the post. Anyway was just to precise. You were asking


#13

Doesnt matter what I took the time to do. I am here helping and planned to help when I posted my first comment. Its people like you that make the community not wanna help at all over a small mistake just because the way you put it makes you guys sound cocky and disturbing. You warent here helping before I commented and you arent helping after you commented so what was the point. He could have clarified my question I dont believe he needed outside help.


#14

Client sided script and I need more details then “It doesnt work”. Does the script have errors? How did you put it on your server? Did you load the script in your resource.lua? Are you starting your resource in the server.cfg?


#15

As before when i type /TP [name of player] nothing happens with no error i put it in cfx-server-data/resources/[local]/ITProud
In My cfg i start ITProud


#16

Ok. I will have to test the script then and see if I can get it working.


#17
RegisterCommand("tp", function(source, args, raw)
	local name = table.concat(args)
	local player = FindPlayerWithName(name)
	if player ~= nil then
		TeleportToPlayer(player)
	end
end, false)

function TeleportToPlayer(player)
	local lPed = GetPlayerPed(PlayerId())
	local oPed = GetPlayerPed(player)
	local oPedPos = GetEntityCoords(oPed, false)
	SetEntityCoords(lPed, oPedPos.x, oPedPos.y, oPedPos.z + 1.0, 0.0, 0.0, 0.0, false)
end

function FindPlayerWithName(string)
	for a = 0, 64 do
		if GetPlayerName(a) == string then
			return a
		end
	end
	return nil
end

This code works on my dev server. Make sure you get their name exactly right.
There was an error in the console so I just fixed that error.