Ulysses

General => Developers Corner => Topic started by: Tomzen on May 05, 2015, 02:57:42 AM

Title: LUA error
Post by: Tomzen 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)
Title: Re: LUA error
Post by: Aaron113 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.
Title: Re: LUA error
Post by: XxLMM13xX on May 05, 2015, 06:07:07 PM
Interesting command! What's you plans for this?
Title: Re: LUA error
Post by: JamminR 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.
Title: Re: LUA error
Post by: XxLMM13xX on May 06, 2015, 08:52:20 AM
well what would this be used for? why would you need to talk in someone else?
Title: Re: LUA error
Post by: Aaron113 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.
Title: Re: LUA error
Post by: Tomzen 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." )
Title: Re: LUA error
Post by: JamminR on May 06, 2015, 08:27:50 PM
Heh.
Using multiple targets.
] ulx impersonate !^ "The cake is a lie"
] say "no it's not!"
Title: Re: LUA error
Post by: Tomzen on May 06, 2015, 08:53:55 PM
heheh, just added that incase I feel like doing so :P
Title: Re: LUA error
Post by: JamminR 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.
Title: Re: LUA error
Post by: Tomzen 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.
Title: Re: LUA error
Post by: MrPresident 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. ;)