• Print

Author Topic: Make targeted player run console command  (Read 5494 times)

0 Members and 1 Guest are viewing this topic.

Offline Halcyon

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Make targeted player run console command
« on: February 21, 2014, 07:31:34 pm »
Extremely new to lua, I'm trying to make a TTT command that pushes the target(s) to spectator by making them run "ttt_spectator_mode 1"

Code: Lua
  1. local CATEGORY_NAME = "TTT"
  2.  
  3. function ulx.setspec( ply, command, argv, args )
  4.         if #argv < 1 then
  5.                 ULib.tsay( ply, ulx.LOW_ARGS, true )
  6.                 return
  7.         end
  8. --find players
  9.         local targets, err = ULib.getUsers( argv[ 1 ], _, true, ply )
  10.         if not targets then
  11.                 ULib.tsay( ply, err, true )
  12.                 return
  13.         end
  14. --work
  15.         for _, v in ipairs( targets ) do
  16.                 ulx.logUserAct( ply, v, "#A set #T to Spectator" )
  17.                 targets:ConCommand("ttt_spectator_mode", "1" )
  18.                 SendFullStateUpdate()
  19.         end
  20. end
  21.  
  22. ulx.addSayCommand( "setspec", ulx.setspec, "Forces target to spectator.", ULib.ACCESS_ADMIN, "!setspec", _, ulx.ID_PLAYER_HELP )
  23. ulx.addToMenu( ulx.ID_MCLIENT, "setspec", "ulx setspec" )[/code0]
  24.  
  25.  

But I keep getting this. What am I doing wrong ;-;

Offline Jacob1

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: Make targeted player run console command
« Reply #1 on: February 21, 2014, 08:48:02 pm »
Code: [Select]
function ulx.tttspec( calling_ply, target_plys, should_unspec )
if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else

    for i=1, #target_plys do
local v = target_plys[ i ]

if should_unspec then
    v:ConCommand("ttt_spectator_mode 0")
else
    v:ConCommand("ttt_spectator_mode 1")
    v:ConCommand("ttt_cl_idlepopup")
end
    end
    if should_unspec then
    ulx.fancyLogAdmin( calling_ply, "#A has forced #T to join the world of the living.", target_plys )
    else
    ulx.fancyLogAdmin( calling_ply, "#A has forced #T to spectate.", target_plys )
    end
end
end
local tttspec = ulx.command( CATEGORY_NAME, "ulx fspec", ulx.tttspec, "!fspec" )
tttspec:addParam{ type=ULib.cmds.PlayersArg }
tttspec:addParam{ type=ULib.cmds.BoolArg, invisible=true }
tttspec:defaultAccess( ULib.ACCESS_ADMIN )
tttspec:setOpposite( "ulx unspec", {_, _, true}, "!unspec" )
tttspec:help( "Forces the <target(s)> to/from spectator." )

NOT MY CODE

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Make targeted player run console command
« Reply #2 on: February 21, 2014, 09:44:52 pm »
"ulx cexec" works wonders, and is gamemode agnostic.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Make targeted player run console command
« Reply #3 on: February 22, 2014, 07:34:24 am »
You're using extremely old ulx syntax...

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Make targeted player run console command
« Reply #4 on: February 22, 2014, 10:01:33 am »
Oh wow, didn't even see that.
Yes Halcyon, your code is from the way ULX commands were written several years ago.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print