General > Developers Corner

Punish Command

<< < (2/2)

ZGMATT:
alright, almost got it now all thats happening now is this: Lua Error: addons/admin menu/lua/autorun/util.lua:38: attempt to call method 'Nick' (a nil value)

heres the code:

--- Code: ---local doJail
local jailableArea
function ulx.punish( calling_ply, target_plys, seconds, should_unjail )
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]

if not should_unjail then
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
elseif not jailableArea( v:GetPos() ) then
ULib.tsayError( calling_ply, v:Nick() .. " is not in an area where a jail can be placed!", true )
else
doJail( v, seconds )

table.insert( affected_plys, v )
end
elseif v.jail then
v.jail.unjail()
v.jail = nil
table.insert( affected_plys, v )
end
end

function formatReason()

GM:PlayerSay( calling_ply, text, teamChat )

reas = string.match( text, "%u", 1 )

reason = string.lower( reas )

end

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

RunConsoleCommand( "awarn_warn", target_plys:Nick(), reason )

if not should_unjail then
local str = "#A punished #T"
if seconds > 0 then
str = str .. " for #i seconds"
end
ulx.fancyLogAdmin( calling_ply, str, affected_plys, seconds )
else
ulx.fancyLogAdmin( calling_ply, "#A unjailed #T", affected_plys )
end
end
local punish = ulx.command( "Utility", "ulx punish", ulx.punish, "!punish" )
punish:addParam{ type=ULib.cmds.PlayersArg }
punish:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, 0 is forever", ULib.cmds.round, ULib.cmds.optional }
punish:addParam{ type=ULib.cmds.BoolArg, invisible=true }
punish:defaultAccess( ULib.ACCESS_ADMIN )
punish:help( "punishes target(s)." )

local function jailCheck()
local remove_timer = true
local players = player.GetAll()
for i=1, #players do
local ply = players[ i ]
if ply.jail then
remove_timer = false
end
if ply.jail and (ply.jail.pos-ply:GetPos()):LengthSqr() >= 6500 then
ply:SetPos( ply.jail.pos )
if ply.jail.jail_until then
doJail( ply, ply.jail.jail_until - CurTime() )
else
doJail( ply, 0 )
end
end
end

if remove_timer then
timer.Remove( "ULXJail" )
end
end

jailableArea = function( pos )
entList = ents.FindInBox( pos - Vector( 35, 35, 5 ), pos + Vector( 35, 35, 110 ) )
for i=1, #entList do
if entList[ i ]:GetClass() == "trigger_remove" then
return false
end
end

return true
end

local mdl1 = Model( "models/props_building_details/Storefront_Template001a_Bars.mdl" )
local jail = {
{ pos = Vector( 0, 0, -5 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 0, 0, 97 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 21, 31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( 21, -31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -21, 31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -21, -31, 46), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -52, 0, 46 ), ang = Angle( 0, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 52, 0, 46 ), ang = Angle( 0, 0, 0 ), mdl=mdl1 },
}
doJail = function( v, seconds )
if v.jail then -- They're already jailed
v.jail.unjail()
end

if v:InVehicle() then
local vehicle = v:GetParent()
v:ExitVehicle()
vehicle:Remove()
end

-- Force other players to let go of this player
if v.physgunned_by then
for ply, v in pairs( v.physgunned_by ) do
if ply:IsValid() and ply:GetActiveWeapon():IsValid() and ply:GetActiveWeapon():GetClass() == "weapon_physgun" then
ply:ConCommand( "-attack" )
end
end
end

if v:GetMoveType() == MOVETYPE_NOCLIP then -- Take them out of noclip
v:SetMoveType( MOVETYPE_WALK )
end

local pos = v:GetPos()

local walls = {}
for _, info in ipairs( jail ) do
local ent = ents.Create( "prop_physics" )
ent:SetModel( info.mdl )
ent:SetPos( pos + info.pos )
ent:SetAngles( info.ang )
ent:Spawn()
ent:GetPhysicsObject():EnableMotion( false )
ent:SetMoveType( MOVETYPE_NONE )
ent.jailWall = true
table.insert( walls, ent )
end

local key = {}
local function unjail()
if not v:IsValid() or not v.jail or v.jail.key ~= key then -- Nope
return
end

for _, ent in ipairs( walls ) do
if ent:IsValid() then
ent:DisallowDeleting( false )
ent:Remove()
end
end
if not v:IsValid() then return end -- Make sure they're still connected

v:DisallowNoclip( false )
v:DisallowMoving( false )
v:DisallowSpawning( false )
v:DisallowVehicles( false )

ulx.clearExclusive( v )
ulx.setNoDie( v, false )

v.jail = nil
end
if seconds > 0 then
timer.Simple( seconds, unjail )
end

local function newWall( old, new )
table.insert( walls, new )
end

for _, ent in ipairs( walls ) do
ent:DisallowDeleting( true, newWall )
ent:DisallowMoving( true )
end
v:DisallowNoclip( true )
v:DisallowMoving( true )
v:DisallowSpawning( true )
v:DisallowVehicles( true )
v.jail = { pos=pos, unjail=unjail, key=key }
if seconds > 0 then
v.jail.jail_until = CurTime() + seconds
end
ulx.setExclusive( v, "in jail" )
ulx.setNoDie( v, true )

timer.Create( "ULXJail", 1, 0, jailCheck )
end

local function jailDisconnectedCheck( ply )
if ply.jail then
ply.jail.unjail()
end
end
hook.Add( "PlayerDisconnected", "ULXJailDisconnectedCheck", jailDisconnectedCheck, HOOK_MONITOR_HIGH )

local function playerPickup( ply, ent )
if CLIENT then return end
if ent:IsPlayer() then
ent.physgunned_by = ent.physgunned_by or {}
ent.physgunned_by[ ply ] = true
end
end
hook.Add( "PhysgunPickup", "ulxPlayerPickupJailCheck", playerPickup, HOOK_MONITOR_HIGH )

local function playerDrop( ply, ent )
if CLIENT then return end
if ent:IsPlayer() and ent.physgunned_by then
ent.physgunned_by[ ply ] = nil
end
end
hook.Add( "PhysgunDrop", "ulxPlayerDropJailCheck", playerDrop ) end

--- End code ---

roastchicken:
target_plys is a table of players. You have to run Nick() on each player in the table, not on the table itself.

MrPresident:
If you're still having trouble with calling any of the awarn function, please post in the awarn2 thread and I can help you out.

Navigation

[0] Message Index

[*] Previous page

Go to full version