• Print

Author Topic: String arg  (Read 7461 times)

0 Members and 1 Guest are viewing this topic.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
String arg
« on: May 10, 2013, 08:53:50 am »
I'm still relatively new to lua, and I've been trying to use ULib.cmds.StringArg but I'm having some trouble getting the data from the string to be passed into the command. I made a table for the completes argument and its appearing in game but i cant get the data from the string to work with my command. Whats the easiest way to get the data from the string into the command?

Code: [Select]
------------------------------ Force --------------------------------
ulx.role = {}
local function updateRoles()
table.Empty( ulx.role ) -- Don't reassign so we don't lose our refs
   
    table.insert(ulx.role,"traitor") -- Add "traitor" to the table.
    table.insert(ulx.role,"detective") -- Add "detective" to the table.
    table.insert(ulx.role,"innocent") -- Add "innocent" to the table.
end
hook.Add( ULib.HOOK_UCLCHANGED, "ULXRoleNamesUpdate", updateRoles )
updateRoles() -- Init

function ulx.force( calling_ply, target_plys, role )

    if role == "traitor" then role == ROLE_TRAITOR end
    if role == "detective" then role == ROLE_DETECTIVE end
    if role == "innocent" then role == ROLE_INNOCENT end
   
   for i=1, #target_plys do
local v = target_plys[ i ]
                      v:SetRole(role)
    end
    SendFullStateUpdate()
    ulx.fancyLogAdmin( calling_ply, true, "#A set #T to #s", target_plys, role )
end
local force = ulx.command( CATEGORY_NAME, "ulx force", ulx.force )
force:addParam{ type=ULib.cmds.PlayerArg }
force:addParam{ type=ULib.cmds.StringArg, completes=ulx.role, hint="Role", error="invalid role \"%s\" specified", ULib.cmds.restrictToCompletes }
force:defaultAccess( ULib.ACCESS_SUPERADMIN )
force:help( "Force a role onto a player." )

error
Code: [Select]
[ERROR] addons/terror town commands/lua/ulx/modules/sh/ttt.lua:65: 'then' expected near '=='
  1. unknown - addons/terror town commands/lua/ulx/modules/sh/ttt.lua:0

« Last Edit: May 10, 2013, 12:01:53 pm by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: String arg
« Reply #1 on: May 10, 2013, 10:13:26 am »
I think you meant to do the following:
Code: Lua
  1.     if role == "traitor" then role = ROLE_TRAITOR end
  2.     if role == "detective" then role = ROLE_DETECTIVE end
  3.     if role == "innocent" then role = ROLE_INNOCENT end

(note the second operator is "=", not "==")
Experiencing God's grace one day at a time.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: String arg
« Reply #2 on: May 10, 2013, 11:55:54 am »
Thanks for the fix still new and im not 100% on how the operators work.

but now im getting this error and im a little confused by it

[ERROR] addons/terror town commands/lua/ulx/modules/sh/ttt.lua:71: attempt to get length of local 'target_plys' (a userdata value)
  1. call - addons/terror town commands/lua/ulx/modules/sh/ttt.lua:71
   2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
    3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
     4. unknown - lua/includes/modules/concommand.lua:69

« Last Edit: May 10, 2013, 12:03:08 pm by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: String arg
« Reply #3 on: May 10, 2013, 02:35:39 pm »
Check the line where it adds the player arguement.

Code: [Select]
force:addParam{ type=ULib.cmds.PlayerArg }
That is only checking one player, but your code needs a table of players. Use this instead.

Code: [Select]
force:addParam{ type=ULib.cmds.PlayersArg }

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: String arg
« Reply #4 on: May 10, 2013, 02:37:09 pm »
thanks Mr.P i really need to be more through when i check my code i missed that...
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: String arg
« Reply #5 on: May 10, 2013, 02:42:43 pm »
one last thing the echo is outputting a number where #s is do i need to change the string again?

Code: [Select]
] ulx force Bender180 detective
]
ServerLog: [ULX] (SILENT) Bender180 set Themself to 2
You are: DETECTIVE
(SILENT) You set Yourself to 2
-
« Last Edit: May 10, 2013, 02:51:30 pm by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: String arg
« Reply #6 on: May 10, 2013, 03:11:18 pm »
That you'll have to wait on one of the other guys to chime in on. I never really understood how fancylog worked and there is no documentation on it as far as I know because it's ULX not ULib.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: String arg
« Reply #7 on: May 10, 2013, 03:23:09 pm »
To my memory, teams are numbers.
I'm guessing you'll need to use whatever function the gamemode does to look up, or set staticly in your code, team number translations.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: String arg
« Reply #8 on: May 10, 2013, 03:29:30 pm »
yes i had to change them back to strings from the role and the teams being numbers makes sense now.
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: String arg
« Reply #9 on: May 10, 2013, 03:47:57 pm »
Ahh, good call Jam.

You will use team.GetName(index) to return the name of the team.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: String arg
« Reply #10 on: May 10, 2013, 04:42:49 pm »
Thanks Mr.P, but i just reversed this right before the fancy admin
Code: [Select]
if role == "traitor" then role = ROLE_TRAITOR end
    if role == "detective" then role = ROLE_DETECTIVE end
    if role == "innocent" then role = ROLE_INNOCENT end
« Last Edit: May 10, 2013, 04:44:50 pm by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: String arg
« Reply #11 on: May 10, 2013, 06:54:17 pm »
Yep, just store it in another variable or something.
Experiencing God's grace one day at a time.

  • Print