ULX

Author Topic: LUA error  (Read 2747 times)

0 Members and 1 Guest are viewing this topic.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
LUA error
« on: May 05, 2015, 02:57:42 AM »
Source:
Code: [Select]
local CATEGORY_NAME = "Custom"
function ulx.impersonate( calling_ply, msg, target_plys )
target_plys:ConCommand("say ", msg)
ulx.fancyLogAdmin( calling_ply, true, "#A impersonated #T", target_plys )
end


local impersonate = ulx.command( CATEGORY_NAME, "ulx impersonate", ulx.impersonate, "!imp" )
impersonate:addParam{ type=ULib.cmds.PlayersArg }
impersonate:addParam{ type=ULib.cmds.StringArg, hint="msg" }
impersonate:addParam{ type=ULib.cmds.BoolArg, invisible=true }
impersonate:defaultAccess( ULib.ACCESS_SUPERADMIN )
impersonate:help( "Impersonates a player." )

Error:
Code: [Select]

[ERROR] addons/ulx/lua/ulx/modules/sh/custom.lua:3: bad key to string index (number expected, got string)
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: LUA error
« Reply #1 on: May 05, 2015, 07:27:11 AM »
For one, you have your parameters backwards.  They must be in the order you added them.  Try fixing that and see where the script stands.  I see possibly a few other things that need tweaking.

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: LUA error
« Reply #2 on: May 05, 2015, 06:07:07 PM »
Interesting command! What's you plans for this?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: LUA error
« Reply #3 on: May 05, 2015, 08:42:27 PM »
Pretty obvious.
Kind of like gimp, but, you control what the target says real time rather than from a table of pre-configured gimp sayings.
Fun idea.

Though I see this as the opportunity to give someone the ability to do this that you might not trust with "ulx cexec" access, it can also be done using cexec.

ulx cexec <target> say "string"
Cexec is pretty powerful though, I can imagine not trusting as many people with it as you might this impersonate command.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: LUA error
« Reply #4 on: May 06, 2015, 08:52:20 AM »
well what would this be used for? why would you need to talk in someone else?

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: LUA error
« Reply #5 on: May 06, 2015, 10:17:57 AM »
well what would this be used for? why would you need to talk in someone else?
Purely for fun... I used to do it all the time with cexec.  Mainly just to give people the rusty bullet hole achievement.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: LUA error
« Reply #6 on: May 06, 2015, 08:16:04 PM »
Yeah, looking back, I now see I'm a complete idiot haha:

Code: [Select]
function ulx.impersonate( calling_ply, target_plys, msg )

for k,v in pairs( target_plys ) do

v:ConCommand( "say " .. msg ..  "" )

end
ulx.fancyLogAdmin( calling_ply, true, "#A impersonated #T", target_plys )
end


local impersonate = ulx.command( CATEGORY_NAME, "ulx impersonate", ulx.impersonate, "!imp" )
impersonate:addParam{ type=ULib.cmds.PlayersArg }
impersonate:addParam{ type=ULib.cmds.StringArg, hint="string", ULib.cmds.takeRestOfLine }
impersonate:addParam{ type=ULib.cmds.BoolArg, invisible=true }
impersonate:defaultAccess( ULib.ACCESS_SUPERADMIN )
impersonate:help( "Impersonates a player." )
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: LUA error
« Reply #7 on: May 06, 2015, 08:27:50 PM »
Heh.
Using multiple targets.
] ulx impersonate !^ "The cake is a lie"
] say "no it's not!"
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: LUA error
« Reply #8 on: May 06, 2015, 08:53:55 PM »
heheh, just added that incase I feel like doing so :P
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: LUA error
« Reply #9 on: May 06, 2015, 09:13:12 PM »
heheh, just added that incase I feel like doing so :P
Don't need to add anything. Our target object PlayerArgs would already allow for it.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: LUA error
« Reply #10 on: May 06, 2015, 10:11:47 PM »
Also JamminR, I would not trust this command to anyone but HeadAdmins, or someone I really trust, because it can be used to force a player to type a command, example I could force you to "!ban *" or "!mode maintenance" etc.
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: LUA error
« Reply #11 on: May 07, 2015, 02:16:12 AM »
Also JamminR, I would not trust this command to anyone but HeadAdmins, or someone I really trust, because it can be used to force a player to type a command, example I could force you to "!ban *" or "!mode maintenance" etc.

!ban doesn't accept multiple targets. You can't do !ban *
I see your point though. ;)