Ulysses
General => Developers Corner => Topic started by: JasonMan 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?
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
-
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)
-
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: 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)
(http://i.gyazo.com/d91f54e51c5047f95da568bbc0e0cd2f.png)
-
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.
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 )