So, lately you can't arrest people in-game with arrest sticks so I tried doing it in console and I got this error.
[code]
[ERROR] gamemodes/darkrp/entities/entities/ent_unarrestbox/shared.lua:62: attempt to index global 'Lockpick' (a nil value)
1. fn - gamemodes/darkrp/entities/entities/ent_unarrestbox/shared.lua:62
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. arrest - gamemodes/darkrp/gamemode/modules/police/sv_init.lua:83
4. unknown - gamemodes/darkrp/gamemode/modules/police/sv_init.lua:237
5. unknown - lua/includes/modules/concommand.lua:69
[/code]
Here are the scripts:
gamemodes/darkrp/entities/entities/ent_unarrestbox/shared.lua
[code]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Unarrest Box"
ENT.Author = "shadowndacorner"
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = "Unarrest people."
ENT.Spawnable = false
ENT.AdminSpawnable = true
function ENT:Initialize()
self:SetModel( "models/items/ammocrate_smg1.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
if SERVER then
self:SetUseType(SIMPLE_USE)
end
local phys = self.Entity:GetPhysicsObject()
phys:Wake()
self:SetMoveType( MOVETYPE_NONE )
phys:SetMass( 200 )
if !DarkRP then self:Remove() end
end
function ENT:Unarrest(ply)
local ang=ply:EyeAngles()
local pos=ply:GetPos()
local mdl=ply:GetModel()
local paw=ply.PreArrestWeapons
local paa=ply.PreArrestAmmo
ply:unArrest()
ply:wanted(NULL, "Escaping from jail!")
timer.Simple(0.1+FrameTime(), function()
ply:SetPos(pos)
ply:SetEyeAngles(ang)
ply:SetModel(mdl)
ply:StripWeapons()
for f, v in pairs(paw) do
ply:Give(v)
end
for f, v in pairs(paa) do
ply:SetAmmo(v, f)
end
ply.oWalkSpeed = ply.PreArrestWS
ply.oRunSpeed = ply.PrearrestRS
timer.Simple(0.5, function()
ply:SetWalkSpeed(ply.PreArrestWS)
ply:SetRunSpeed(ply.PreArrestRS or ply:GetWalkSpeed()*2)
ply:SprintEnable(true)
ply:SetLockpickCount(ply.PreArrestLockpicks + ply:GetLockpickCount())
ply.PreArrestWS=nil
ply.PreArrestRS=nil
ply.PreArrestLockpicks=nil
end)
end)
end
hook.Add('playerArrested', 'GetAllWeapons', function(ply, time, enf)
if Lockpick.Config.EnableBreakout then
ply.PreArrestWS=ply:GetWalkSpeed()
ply.PreArrestRS=ply:GetRunSpeed()
ply.PreArrestWeapons={}
ply.PreArrestAmmo={}
local picksToKeep = math.min(ply:GetLockpickCount(), Lockpick.Config.JailPicks)
ply.PreArrestLockpicks = ply:GetLockpickCount() - picksToKeep
ply:SetLockpickCount(picksToKeep)
for f, v in pairs(ply:GetWeapons()) do
ply.PreArrestWeapons[f]=v:GetClass()
ply.PreArrestAmmo[v:GetPrimaryAmmoType()]=ply:GetAmmoCount(v:GetPrimaryAmmoType())
ply.PreArrestAmmo[v:GetSecondaryAmmoType()]=ply:GetAmmoCount(v:GetPrimaryAmmoType())
end
end
end)
hook.Add('playerUnArrested', 'DeleteWeapons', function(ply, time, enf)
ply.PreArrestWeapons=nil
ply.PreArrestAmmo=nil
end)
function ENT:Use(ply)
end
function ENT:UpdateTransmitState()
return TRANSMIT_PVS
end
function ENT:Draw()
self.Entity:DrawModel()
cam.Start3D2D(self:GetPos()+self:GetAngles():Up()*self:OBBMaxs().z/2-self:GetAngles():Forward()*16-self:GetAngles():Right()*12, self:GetAngles()+Angle(180, 90, -90), 0.12)
surface.SetDrawColor(80, 80, 80, 200)
surface.DrawRect(11, 0, (23/0.12), 10/0.12)
surface.SetTextColor(255, 255, 255, 255)
surface.SetFont('Lockpick')
local txt="Evidence"
if LocalPlayer():isArrested() then
txt=txt.." (Lockpick to Unarrest)"
end
local x, y=surface.GetTextSize(txt)
surface.SetTextPos((25/0.12/2)-x/2, 12.5-y/2)
surface.DrawText(txt)
cam.End3D2D()
end
if Lockpick and Lockpick.Config then
function Lockpick:CreateUnarrestBox()
if SERVER and !self.Config.DisableJailPicks and self.Config.EnableBreakout and Lockpick.Config.UnarrestBoxPositions[game.GetMap()] then
local ent=ents.Create('ent_unarrestbox')
local pt=Lockpick.Config.UnarrestBoxPositions[game.GetMap()]
//ent:SetPos(pt.CratePos)
//ent:SetAngles(pt.CrateAng)
ent:Spawn()
ent:Activate()
ent:SetPos(pt.CratePos)
ent:SetAngles(pt.CrateAng)
end
end
game.lpoCleanUpMap=game.lpoCleanUpMap or game.CleanUpMap
function game.CleanUpMap(...)
game.lpoCleanUpMap(...)
timer.Simple(0, function()
Lockpick:CreateUnarrestBox()
end)
end
hook.Add('InitPostEntity', 'CreateUnarrestBox', function()
Lockpick:CreateUnarrestBox()
end)
end
[/code]
addons/ulib/lua/ulib/shared/hook.lua
[code]
--[[
Title: Hook
This overrides garry's default hook system. We need this better hook system for any serious development.
We're implementing hook priorities. hook.Add() now takes an additional parameter of type number between -20 and 20.
0 is default (so we remain backwards compatible). -20 and 20 are read only (ignores returned values).
Hooks are called in order from -20 on up.
]]
-- This file is coded a little awkwardly because we're trying to implement a new behavior while remaining as true to the old behavior as possible.
-- Globals that we are going to use
local gmod = gmod
local pairs = pairs
local isfunction = isfunction
local isstring = isstring
local IsValid = IsValid
-- Needed due to our modifications
local table = table
local ipairs = ipairs
local tostring = tostring
--[[ Needed for tests, below
local CLIENT = CLIENT
local print = print
local assert = assert
local error = error --]]
-- Grab all previous hooks from the pre-existing hook module.
local OldHooks = hook.GetTable()
-----------------------------------------------------------
-- Name: hook
-- Desc: For scripts to hook onto Gamemode events
-----------------------------------------------------------
module( "hook" )
-- Local variables
local Hooks = {}
local BackwardsHooks = {} -- A table fully to garry's spec for aVoN
local function sortHooks( event_name )
for i=#Hooks[ event_name ], 1, -1 do
local name = Hooks[ event_name ][ i ].name
if not isstring( name ) and not IsValid( name ) then
Remove( event_name, name )
end
end
table.sort( Hooks[ event_name ], function( a, b ) -- Sort by priority, then name
if a == nil then return false -- Move nil to end
elseif b == nil then return true -- Keep nil at end
elseif a.priority < b.priority then return true
elseif a.priority == b.priority and tostring(a.name) < tostring(b.name) then return true
else return false end
end )
end
-- Exposed Functions
--[[
Function: hook.GetTable
Returns:
The table filled with all the hooks in a format that is backwards compatible with garry's.
]]
function GetTable()
return BackwardsHooks
end
--[[
Function: hook.Add
Our new and improved hook.Add function.
Read the file description for more information on how the hook priorities work.
Parameters:
event_name - The name of the event (IE "PlayerInitialSpawn").
name - The unique name of your hook.
This is only so that if the file is reloaded, it can be unhooked (or you can unhook it yourself).
func - The function callback to call
priority - *(Optional, defaults to 0)* Priority from -20 to 20. Remember that -20 and 20 are read-only.
]]
function Add( event_name, name, func, priority )
if not isfunction( func ) then return end
if not isstring( event_name ) then return end
if not Hooks[ event_name ] then
BackwardsHooks[ event_name ] = {}
Hooks[ event_name ] = {}
end
priority = priority or 0
-- Make sure the name is unique
Remove( event_name, name )
table.insert( Hooks[ event_name ], { name=name, fn=func, priority=priority } )
BackwardsHooks[ event_name ][ name ] = func -- Keep the classic style too so we won't break anything
sortHooks( event_name )
end
--[[
Function: hook.Remove
Parameters:
event_name - The name of the event (IE "PlayerInitialSpawn").
name - The unique name of your hook. Use the same name you used in hook.Add()
]]
function Remove( eve
Can i ask, why are you using core DarkRP files & not using the DarkRPmodification addon?
I'm not, I always use DarkRPmodification.
[QUOTE=Snowpaw;45846508]I'm not, I always use DarkRPmodification.[/QUOTE]
So why is this file in the darkrp gamemode folder?
gamemodes/darkrp/entities/entities/ent_unarrestbox/shared.lua
Sorry, you need to Log In to post a reply to this thread.