• Print

Author Topic: SlayQ  (Read 4645 times)

0 Members and 1 Guest are viewing this topic.

Offline Tarado

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
SlayQ
« on: June 01, 2014, 01:38:14 pm »
Heya,

So I'm trying to modify ULX's default "slay" command so that instead you add the player you want slayed into a queue and when the round next starts, the SlayQ automatically slays said player without the Admin needing to manually slay the player themselves.

Now this works perfectly fine, the player dies at Round start and no errors pop up but when I try to add a text for the SlayQ to say after someone is slain the console gives me an error.
Here is the Section for the SlayQ script:
Code: [Select]
------------------------------ SlayQ ------------------------------
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 v:IsFrozen() then
ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
else
hook.Add("TTTBeginRound", "Kill SlayQ", function()
v:Kill()
table.insert( affected_plys, v )
player.PrintMessage( HUD_PRINTTALK, v .. " was slain by SlayQ for RDM") -- The bit that says the message
end)
end
end

end
local slay = ulx.command( CATEGORY_NAME, "ulx slayq", ulx.slay, "!slayq" )
slay:addParam{ type=ULib.cmds.PlayersArg }
slay:defaultAccess( ULib.ACCESS_ADMIN )
slay:help( "Adds Target to slay queue." )

And this is the console error:

Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/sh/fun.lua:114: attempt to concatenate upvalue 'v' (a userdata value)
1. fn - addons/ulx/lua/ulx/modules/sh/fun.lua:114
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. unknown - gamemodes/terrortown/gamemode/init.lua:671

Thanks,
Tarado

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: SlayQ
« Reply #1 on: June 01, 2014, 02:27:41 pm »
The error is caused by only using "v". "v" will just return the player object, and nothing else. I assume you want to get the name of the player, use "v:Nick()" instead.

Also, "player.PrintMessage" will not work. "player" isn't defined, so it won't print to anyone.
You could replace that with something like ULib.tsay, so the code looks something like this:
Code: Lua
  1. ULib.tsay( nil, v:Nick() .. " was slain by SlayQ for RDM" ) -- "nil" means every player connected.

Since you're running TTT, you could use Bender and Skillz' TTT addon. It contains a bunch of different commands, including "slaynr" ("slay next round"), which should work the same way as your command.
« Last Edit: June 01, 2014, 02:29:45 pm by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: SlayQ
« Reply #2 on: June 01, 2014, 09:27:24 pm »
Since you're running TTT, you could use Bender and Skillz' TTT addon.

I was thinking I'd seen this before. :)
But, seriously Tarado, by all means, don't let the fact it's been done before stop you from learning lua and/or how to integrate with ULib and ULX.
You might just come up with some other code server owners can't live without.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print