• Print

Author Topic: Spectator Mode Command  (Read 14213 times)

0 Members and 1 Guest are viewing this topic.

Offline CrossBoy

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Spectator Mode Command
« on: January 18, 2016, 09:32:41 pm »
Hello! I have a deathrun server using .//MrGash's Deathrun Gamemode (https://github.com/Mr-Gash/GMod-Deathrun) and was trying to see if I could get a simple Spectator mode to work. It appeared that it already had the team created, but no way of entering it.

So, I tried making this, and put it in /addons/ulx/lua/ulx/modules/sh.
Code: [Select]
local CATEGORY_NAME = "Spectate"

 function ulx.spectate( calling_ply )
ply:Kill
ply:SetTeam(TEAM_SPECTATOR)
end
local spectate = ulx.command( CATEGORY_NAME, "ulx spectate", ulx.spectate, "!spectate", false )
spectate:defaultAccess( ULib.ACCESS_ALL )
spectate:help( "Enters Spectator Only Mode." )

Here is the error I get:

[ERROR] addons/ulx/lua/ulx/modules/sh/spec.lua:10: function arguments expected near 'ply'
  1. unknown - addons/ulx/lua/ulx/modules/sh/spec.lua:0

This is the first thing I've tried creating, and wasn't totally sure what was happening.

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Spectator Mode Command
« Reply #1 on: January 19, 2016, 01:25:10 am »
You don't have it set to target anyone.

Code: Lua
  1.  function ulx.spectate( calling_ply, target_ply )
  2.   target_ply:Kill
  3.   target_ply:SetTeam(TEAM_SPECTATOR)
  4. end
Once you get to know me, you'll find you'll have never met me at all.

Offline monkeymacman

  • Newbie
  • *
  • Posts: 44
  • Karma: 13
Re: Spectator Mode Command
« Reply #2 on: January 19, 2016, 01:23:25 pm »
You don't have it set to target anyone.

Code: Lua
  1.  function ulx.spectate( calling_ply, target_ply )
  2.   target_ply:Kill
  3.   target_ply:SetTeam(TEAM_SPECTATOR)
  4. end
I assume he is trying to make it run it on the calling ply and have no target ply. In which case it's a simple error of using the wrong variable name.
Code: Lua
  1.  function ulx.spectate( calling_ply )
  2.   ply:Kill()
  3.   ply:SetTeam(TEAM_SPECTATOR)
  4. end
Should be changed to
Code: Lua
  1.  function ulx.spectate( calling_ply )
  2.   calling-ply:Kill()
  3.   calling_ply:SetTeam(TEAM_SPECTATOR)
  4. end
(original used ply in function but the actual argument name was calling_ply.) Also you don't currently have it set to tell you in chat that you went to spectator mode, I suggest looking through default ulx commands to see the chat messages, or looking on the GMod Wiki to search for chat and see which message would work best for you (or you could leave it as is, it's perfectly fine)
« Last Edit: January 19, 2016, 01:28:30 pm by monkeymacman »

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Spectator Mode Command
« Reply #3 on: January 19, 2016, 04:56:25 pm »

Should be changed to
Code: Lua
  1.  function ulx.spectate( calling_ply )
  2.   calling-ply:Kill()
  3.   calling_ply:SetTeam(TEAM_SPECTATOR)
  4. end


Code: Lua
  1.  function ulx.spectate( calling_ply )
  2.   calling_ply:Kill()
  3.   calling_ply:SetTeam(TEAM_SPECTATOR)
  4. end

Minor typo, you did calling-ply rather than calling_ply
Once you get to know me, you'll find you'll have never met me at all.

  • Print