• Print

Author Topic: ULX Jail Custom Location / No Cage  (Read 5734 times)

0 Members and 1 Guest are viewing this topic.

Offline Consortias

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
ULX Jail Custom Location / No Cage
« on: July 07, 2016, 01:51:38 am »
Hello,

I am attempting to modify the jail command in ULX to send a targeted user to specified coordinates, without using the metal cage that would normally surround a targeted user upon execution of the command.

Here is what I have so far:
Code: Lua
  1. ------------------------------ Jail ------------------------------
  2. local doJail
  3. local jailableArea
  4. local newjail = ("-3006.230957, -1259.567627, 8.140316")
  5. function ulx.jail( calling_ply, target_plys, seconds, reason, should_unjail )
  6.                 local affected_plys = {}
  7.                 for i=1, #target_plys do
  8.                                 local v = target_plys[ i ]
  9.  
  10.                                 if not should_unjail then
  11.                                                 if ulx.getExclusive( v, calling_ply ) then
  12.                                                                 ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
  13.                                                 elseif not jailableArea( v:GetPos() ) then
  14.                                                                 ULib.tsayError( calling_ply, v:Nick() .. " is not in an area where a jail can be placed!", true )
  15.                                                 else
  16.                                                                 calling_ply:SetPos( local newjail )
  17.  
  18.                                                                 table.insert( affected_plys, v )
  19.                                                 end
  20.                                 elseif v.jail then
  21.                                                 v.jail.unjail()
  22.                                                 v.jail = nil
  23.                                                 table.insert( affected_plys, v )
  24.                                 end
  25.                 end
  26.  
  27.                 if not should_unjail then
  28.                                 local str = "#A jailed #T"
  29.                                 if seconds > 0 then
  30.                                                 str = str .. " for #i seconds"
  31.                                 end
  32.                                 ulx.fancyLogAdmin( calling_ply, "#A jailed #T for " ..reason.. ".", affected_plys, seconds )
  33.                 else
  34.                                 ulx.fancyLogAdmin( calling_ply, "#A unjailed #T", affected_plys )
  35.                 end
  36. end
  37. local jail = ulx.command( CATEGORY_NAME, "ulx jail", ulx.jail, "!jail" )
  38. jail:addParam{ type=ULib.cmds.PlayersArg }
  39. jail:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, 0 is forever", ULib.cmds.round, ULib.cmds.optional }
  40. jail:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine,
  41. completes=ulx.common_kick_reasons }
  42. jail:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  43. jail:defaultAccess( ULib.ACCESS_ADMIN )
  44. jail:help( "Jails target(s)." )
  45. jail:setOpposite( "ulx unjail", {_, _, _, _, true}, "!unjail" )
  46.  

I figured at the top I could create a new local variable to be used on line 16. However, this is not working. What can I do to fix this?

Thank you!

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: ULX Jail Custom Location / No Cage
« Reply #1 on: July 07, 2016, 04:42:47 am »
Entity:SetPos accepts a Vector, while you are passing it a string.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Consortias

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: ULX Jail Custom Location / No Cage
« Reply #2 on: July 07, 2016, 08:29:01 am »
Here's what I changed..

Code: Lua
  1. else
  2.                                                                 Entity:SetPos( -3006.230957, -1259.567627, 8.140316 )
  3.  
  4.                                                                 table.insert( affected_plys, v )
  5.                                                 end

I'm receiving this error in my server console:
Code: [Select]
addons/ulx/lua/ulx/modules/sh/fun.lua:398: attempt to index global 'Entity' (a function value)
Does this mean I have to add "GM" before the function value to make it a global entity?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: ULX Jail Custom Location / No Cage
« Reply #3 on: July 07, 2016, 09:31:28 am »
Here's what I changed..

Code: Lua
  1. Entity:SetPos( -3006.230957, -1259.567627, 8.140316 )
Code: [Select]
addons/ulx/lua/ulx/modules/sh/fun.lua:398: attempt to index global 'Entity' (a function value)
Entity:(blah) is just notation. It means the SetPos function is part of the Entity class.
In your case, calling_ply, a Player object, inherits from (and is therefore an) Entity. So, you would do calling_ply:SetPos(blah).
bw81@ulysses-forums ~ % whoami
Homepage

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: ULX Jail Custom Location / No Cage
« Reply #4 on: July 07, 2016, 11:42:21 am »
As Bytewave pointed out, you still want to use calling_ply. However, even with that change, your code won't run correctly.

Vector is a special datatype in Garry's Mod. Passing three numbers is not the same as passing a Vector. You need to create a Vector by calling the Vector function. In your example, replace

Code: Lua
  1. local newjail = ("-3006.230957, -1259.567627, 8.140316")

with

Code: Lua
  1. local newjail = Vector( -3006.230957, -1259.567627, 8.140316 )



In addition, you should only use the local keyword when initializing a variable. For example, on line 16 you have

Code: Lua
  1. calling_ply:SetPos( local newjail )

when it should just be

Code: Lua
  1. calling_ply:SetPos( newjail )
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Consortias

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: ULX Jail Custom Location / No Cage
« Reply #5 on: July 07, 2016, 04:48:13 pm »
Thank you so much for explaining how functions work. You method worked without error, and I really appreciate it. When you reference local functions such as...
Code: Lua
  1. local doJail
Is that function defined in the lua document it's listed in, or is it defined somewhere else?

I've tried searching many lua files for "doJail" just to see what it's defined to do.. But I can't find it.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: ULX Jail Custom Location / No Cage
« Reply #6 on: July 07, 2016, 05:00:17 pm »
Thank you so much for explaining how functions work. You method worked without error, and I really appreciate it. When you reference local functions such as...
Code: Lua
  1. local doJail
Is that function defined in the lua document it's listed in, or is it defined somewhere else?

I've tried searching many lua files for "doJail" just to see what it's defined to do.. But I can't find it.
local doJail just says that the doJail variable is local to the scope (in this case just that file) you're in, making it a local variable.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Consortias

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: ULX Jail Custom Location / No Cage
« Reply #7 on: July 07, 2016, 05:06:10 pm »
local doJail just says that the doJail variable is local to the scope (in this case just that file) you're in, making it a local variable.

I apologize for sounding like an idiot, I'm new to this. It is a variable not a function. And I've found the snippet I'm looking for starting at line 511.

Thanks for the support!

  • Print