• Print

Author Topic: ULX Slay command with a Reason.  (Read 7405 times)

0 Members and 1 Guest are viewing this topic.

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
ULX Slay command with a Reason.
« on: September 06, 2013, 05:46:20 am »
Hey, I'm Ricky and I'm just trying to figure out how to add a reason to the slay command.
Code: [Select]
function ulx.slay( calling_ply, target_plys )
local affected_plys = {}

for i=1, #target_plys do
local v = target_plys[ i ]

if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
elseif not v:Alive() then
ULib.tsayError( calling_ply, v:Nick() .. " is already dead!", true )
elseif v:IsFrozen() then
ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
else
v:Kill()
table.insert( affected_plys, v )
end
end

ulx.fancyLogAdmin( calling_ply, "#A slayed #T", affected_plys )
end
local slay = ulx.command( CATEGORY_NAME, "ulx slay", ulx.slay, "!slay" )
slay:addParam{ type=ULib.cmds.PlayerArg }
slay:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
slay:defaultAccess( ULib.ACCESS_ADMIN )
slay:help( "Slays Target." )

That is what i've got so far, but it prints this error into console.
addons/ulx/lua/ulx/modules/sh/fun.lua:75: attempt to get length of local 'target_plys' (a userdata value)
I did copy over the thing from the kick command and try edit it. But it prints that into console and dosen't slay the player.

Any help would be highly appreciated.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: ULX Slay command with a Reason.
« Reply #1 on: September 06, 2013, 08:40:30 am »
adding the string pram is a good start but you also need to include a few other things

You need to include the string with the function so

Code: Lua
  1. function ulx.slay( calling_ply, target_plys )
needs to be
Code: Lua
  1. function ulx.slay( calling_ply, target_plys, reason )

and you need to tell facylog to echo it so
Code: Lua
  1. ulx.fancyLogAdmin( calling_ply, "#A slayed #T", affected_plys )
should be
Code: Lua
  1. ulx.fancyLogAdmin( calling_ply, "#A slayed #T for #S", affected_plys, reason )

Hope this helps if your still a little confussed (or i got it wrong) someone who knows more will correct me or provide more details im sure.
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: ULX Slay command with a Reason.
« Reply #2 on: September 06, 2013, 02:30:23 pm »
Bender's modification is correct if you have only modified the parameters by adding the reason string, but I see you also changed "PlayersArg" to "PlayerArg"; was this intentional? If so, you'll need to restructure the function to accept the single player instead of a player table.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Slay command with a Reason.
« Reply #3 on: September 06, 2013, 04:28:45 pm »
Example code of what Megiddo said (since you're learning our command structure) = You converted the slay command from a multiple user command ( nick,nick2,nick3 or *) to a single target (nick or ^) command.
In the original slay command
Code: [Select]
slay:addParam{ type=ULib.cmds.PlayersArg }
You converted to
Code: [Select]
slay:addParam{ type=ULib.cmds.PlayerArg }

ULX uses ULib to strictly watch this, and would return an error if you tried to target multiple users without having the proper command set up.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ULX Slay command with a Reason.
« Reply #4 on: September 06, 2013, 09:43:11 pm »
Alright I've made it so it actually slays the user thanks to everyone. But there is one more problem, it dosen't print anything into the chat. I want it to print like Aqua slayed Blah for RDM or something like that. This is the code so far.


Code: [Select]
function ulx.slay( calling_ply, target_plys, reason )
local affected_plys = {}

for i=1, #target_plys do
local v = target_plys[ i ]

if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
elseif not v:Alive() then
ULib.tsayError( calling_ply, v:Nick() .. " is already dead!", true )
elseif v:IsFrozen() then
ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
else
v:Kill()
table.insert( affected_plys, v )
end
end

ulx.fancyLogAdmin( calling_ply, "#A slayed #T for #S", affected_plys, reason )
end
local slay = ulx.command( CATEGORY_NAME, "ulx slay", ulx.slay, "!slay" )
slay:addParam{ type=ULib.cmds.PlayersArg }
slay:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
slay:defaultAccess( ULib.ACCESS_ADMIN )
slay:help( "Slays Target." )

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: ULX Slay command with a Reason.
« Reply #5 on: September 07, 2013, 05:35:43 am »
Change "#S" to "#s", I'm pretty sure it's case sensitive.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULX Slay command with a Reason.
« Reply #6 on: September 07, 2013, 06:36:33 am »
Change "#S" to "#s", I'm pretty sure it's case sensitive.

Good catch iSnipeu, I didn't notice that at first glance.
Experiencing God's grace one day at a time.

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: ULX Slay command with a Reason.
« Reply #7 on: September 07, 2013, 08:57:38 am »
Is there any reason why slay doesn't have a reason arg in the first place?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULX Slay command with a Reason.
« Reply #8 on: September 07, 2013, 09:08:54 am »
Is there any reason why slay doesn't have a reason arg in the first place?

Unlike kicking and banning, I don't see a compelling argument for including a reason in it.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Slay command with a Reason.
« Reply #9 on: September 07, 2013, 12:02:49 pm »
Indeed, kick/ban, person't off the server. Can't see chat anymore.
All the other punishments, person remains on server and the admin doing it can explain why.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Valgoid

  • Full Member
  • ***
  • Posts: 103
  • Karma: -15
  • Wanna Be Lua King
Re: ULX Slay command with a Reason.
« Reply #10 on: June 06, 2014, 01:49:17 pm »
Just use ULX VoteSlay that I made. You can add a reason.
/index.php/topic,7320.0.html#msg36977

  • Print