ULX

Author Topic: !ban targeting multiple people  (Read 2964 times)

0 Members and 2 Guests are viewing this topic.

Offline JasonMan

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
!ban targeting multiple people
« on: July 21, 2015, 01:05:24 PM »
I tried making a fake ban ulx command, and it worked out really smooth (Considering all I had to do was remove the ban function and keep the echo)
But then I wanted to make it so that you can "ban" multiple players (Mainly for !fakeban *), but I couldn't get it to work. What am I doing wrong?

Code: [Select]
function ulx.fakeban( calling_ply, target_plys, minutes, reason )
        if target_ply:IsBot() then
                ULib.tsayError( calling_ply, "Cannot ban a bot", true )
                return
        end
 
        local time = "for #i minute(s)"
        if minutes == 0 then time = "permanently" end
        local str = "#A banned #T " .. time
        if reason and reason ~= "" then str = str .. " (#s)" end
        ulx.fancyLogAdmin( calling_ply, str, target_plys, minutes ~= 0 and minutes or reason, reason )
end
local fakeban = ulx.command( CATEGORY_NAME, "ulx fban", ulx.fakeban, "!fakeban" )
fakeban:addParam{ type=ULib.cmds.PlayersArg }
fakeban:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
fakeban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
fakeban:defaultAccess( ULib.ACCESS_ADMIN )
fakeban:help( "Perform a fake ban on your target. User will not be banned, a chat message of the ban will pop up however" )

Basically nothing is happening

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: !ban targeting multiple people
« Reply #1 on: July 21, 2015, 07:10:47 PM »
Well, your error messages in console should be quite helpful to tell you.
I'm guessing at least one is about target_ply being NULL.
You never define/pass a single target_ply anymore, so can't test if target_ply is a bot.
You're now passing a table (fakeban:addParam{ type=ULib.cmds.PlayersArg }) = a table, so, just adding s to target_ply:isBot won't fix you either.
You'll need to start treating target_plys as a table, even if it only contains one person.
(hint = for loops)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline JasonMan

  • Newbie
  • *
  • Posts: 12
  • Karma: -1
Re: !ban targeting multiple people
« Reply #2 on: July 22, 2015, 01:44:56 AM »
Ahh right, wow that was stupid of me to do.
I decided to remove the bot part tho, it's kinda needless for a command like this.
So I got this now:
Code: [Select]
function ulx.fakeban( calling_ply, target_plys, minutes, reason )
for k, v in pairs ( target_plys ) do
local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned #T " .. time
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, target_plys, minutes ~= 0 and minutes or reason, reason )
end
end
local fakeban = ulx.command( CATEGORY_NAME, "ulx fban", ulx.fakeban, "!fakeban" )
fakeban:addParam{ type=ULib.cmds.PlayersArg }
fakeban:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
fakeban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
fakeban:defaultAccess( ULib.ACCESS_ADMIN )
fakeban:help( "Perform a fake ban on your target. User will not be banned, a chat message of the ban will pop up however" )

And clearly, the chat popup is appearing multiple times (Being in the loop and all), but when I take it out of the loop I get this error in the console (line 986 being the line with the echo)

« Last Edit: July 22, 2015, 11:45:22 AM by MrPresident »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: !ban targeting multiple people
« Reply #3 on: July 22, 2015, 06:56:33 PM »
Well, you don't really need to set every single variable separately within the loop.
The ONLY thing that will change is the player.
If you'll notice, our multiplayer commands will show "Blah did action on blah1, blah2, blah3 for some number time/damage."
Do you want every player announced on a separate line.(I could see reasons why, but, it would be inefficient, especially if logging was enabled)

You're overall code shouldn't change too much from normal ban until you get to grabbing the players and placing them in a table.
Code: [Select]
local affected_plys = {}
for k=1, #target_plys do
table.insert( affected_plys, target_plys[ k ] )
end
local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned #T " .. time
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, affected_plys, minutes ~= 0 and minutes or reason, reason )
« Last Edit: July 22, 2015, 06:58:11 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming