Ok, I have the code(below) that if you do "ta" in console it teleports you to a random position. But if you do "ta <playername>" it is supposed to search for a player and say if they are there or not, if they are it teleports them to a position. But it teleports the player running the command even if the player the searched for is/isn't there.
[CODE]local function tadmin(ply, cmd, target)
local ra = math.random(1, 4)
local pos = {}
pos[1] = Vector(1405, -4511, -134)
pos[2] = Vector(3611, -7013, -134)
pos[3] = Vector(1758, -6962, -134)
pos[4] = Vector(2477, -5719, -134)
if not target then
if ply:IsUserGroup("user") or ply:IsUserGroup("vip") or ply:IsUserGroup("VIP") or ply:IsUserGroup("donator") then
ply:PrintMessage(HUD_PRINTTALK, "You aren't the correct rank to use this command!")
else
if ply:Alive() then
ply:SetPos(pos[ra])
else
ply:PrintMessage(HUD_PRINTTALK, "You can't teleport while dead")
end
end
else
for k,v in pairs(player.GetAll()) do
if v:Nick() == target:Nick() then
if target:Alive() then
target:SetPos(pos[ra])
else
ply:PrintMessage(HUD_PRINTTALK, "Player Dead")
end
else
ply:PrintMessage(HUD_PRINTTALK, "Player Not Found")
end
end
end
end
concommand.Add("ta", tadmin)[/CODE]
This should do it.
[lua]
function findPlayer(name)
for _,v in pairs(player.GetAll()) do
if string.find(string.lower(v:Nick(), string.lower(name))) then return v end
end
return false
end
concommand.Add("ta", function (ply,cmd,args)
local ra = math.random(1, 4)
local pos = {}
pos[1] = Vector(1405, -4511, -134)
pos[2] = Vector(3611, -7013, -134)
pos[3] = Vector(1758, -6962, -134)
pos[4] = Vector(2477, -5719, -134)
arg = string.Explode(" ", string.Trim(args))
if arg[1] ~= nil and arg[1] ~= "" then
local target = findPlayer(arg[1])
if not target then
ply:PrintMessage(HUD_PRINTTALK, "Player Not Found")
else
if target:Alive() then
target:SetPos(pos[ra])
else
ply:PrintMessage(HUD_PRINTTALK, "Player Dead")
end
end
else
if ply:IsUserGroup("user") or ply:IsUserGroup("vip") or ply:IsUserGroup("VIP") or ply:IsUserGroup("donator") then
ply:PrintMessage(HUD_PRINTTALK, "You aren't the correct rank to use this command!")
else
if ply:Alive() then
ply:SetPos(pos[ra])
else
ply:PrintMessage(HUD_PRINTTALK, "You can't teleport while dead")
end
end
end
end)
[/lua]
Hmm, that didn't seem to work. I'm not getting any errors in the console, and I placed print("TEST") in certain spots of the code and it seems to be stopping right before this line: [CODE]arg = string.Explode(" ", string.Trim(args))[/CODE] I tried re-editing some things and debugging it, but I've never working with function arguments before, so if you could help that would be awesome :)
Sorry, you need to Log In to post a reply to this thread.