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.
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.
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
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.
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?
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
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.