Author Topic: Warp Target Player  (Read 532 times)

0 Members and 1 Guest are viewing this topic.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Warp Target Player
« on: October 13, 2018, 12:51:01 PM »
Hello,
I posted a warp code for ULX, but I noticed that it would only teleport the caster when the command is used. Is there anyway to make it so the command can target players to teleport that player to the warp location?
Thanks


Code: [Select]
local CATEGORY_NAME = 'Teleport'

local warps = {
-- ['name of warp location'] = Position that you want players to be teleported to
['admin'] = Vector(-1936.525879, -2138.591553, 8439.391602),
['spawn'] = Vector(423.965302, 9198.730469, 74.031250)
}


local WarpACs = { 'admin', 'spawn' }

function ulx.warp(caller, place)
if not warps[place] then
ULIb.tsayError(caller, 'That is not a valid warp location!', true)
else
local pos = warps[place]
if not isvector(pos) then
ULIb.tsayError(caller, 'Invalid warp vector, please check warps list.', true)
else
caller:SetPos(pos)
ulx.fancyLogAdmin(caller, '#A has teleported to warp location: ' .. place..'.')
end
end
end

local warp = ulx.command(CATEGORY_NAME, 'ulx warp', ulx.warp, '!tp')
warp:defaultAccess(ULib.ACCESS_ADMIN) -- Put ULib.ACCESS_OPERATOR for operator, ULib.ACCESS_SUPERADMIN for only superadmins, or ULib.ACCESS_ALL for everyone.
warp:addParam{type = ULib.cmds.StringArg, hint = 'warp location name', completes = WarpACs}
warp:help('Teleports a user to a location specified by a name.')

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 783
  • Karma: 54
    • Anonymous Gaming
Re: Warp Target Player
« Reply #1 on: October 13, 2018, 12:57:53 PM »
Yes, add a "PlayerArg" to your command.

Code: Lua
  1. local CATEGORY_NAME = 'Teleport'
  2.  
  3. local warps = {
  4.         -- ['name of warp location'] = Position that you want players to be teleported to
  5.         ['admin'] = Vector(-1936.525879, -2138.591553, 8439.391602),
  6.         ['spawn'] = Vector(423.965302, 9198.730469, 74.031250)
  7. }
  8.  
  9.  
  10. local WarpACs = { 'admin', 'spawn' }
  11.  
  12. function ulx.warp(caller, target, place)
  13.         if not warps[place] then
  14.                 ULIb.tsayError(caller, 'That is not a valid warp location!', true)
  15.         else
  16.                 local pos = warps[place]
  17.                 if not isvector(pos) then
  18.                         ULIb.tsayError(caller, 'Invalid warp vector, please check warps list.', true)
  19.                 else
  20.                         target:SetPos(pos) -- I replaced "caller" with "target" here.
  21.                         ulx.fancyLogAdmin(caller, '#A has teleported #T to warp location: ' .. place .. '.', target)
  22.                 end
  23.         end
  24. end
  25.  
  26. local warp = ulx.command(CATEGORY_NAME, 'ulx warp', ulx.warp, '!tp')
  27. warp:defaultAccess(ULib.ACCESS_ADMIN) -- Put ULib.ACCESS_OPERATOR for operator, ULib.ACCESS_SUPERADMIN for only superadmins, or ULib.ACCESS_ALL for everyone.
  28. warp:addParam{type = ULib.cmds.PlayerArg} -- This makes it so you can target a player. Remember parameters must be added in the same order as the variables in the function.
  29. warp:addParam{type = ULib.cmds.StringArg, hint = 'warp location name', completes = WarpACs}
  30. warp:help('Teleports a user to a location specified by a name.')
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Discord

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Warp Target Player
« Reply #2 on: October 13, 2018, 01:34:18 PM »
Thank you!