Hey, I haven't released my server yet with this glitch hanging around and I would like to know if there's a way around it. I'm currently using DarkRP 2.5.1.
I'll post the code of the pocket tool main scripts here:
shared.lua
[CODE]if SERVER then
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_menu.lua")
include("sv_init.lua")
end
if CLIENT then
include("cl_menu.lua")
end
SWEP.PrintName = "Pocket"
SWEP.Slot = 1
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.Base = "weapon_cs_base2"
SWEP.Author = "DarkRP Developers"
SWEP.Instructions = "Left click to pick up\nRight click to drop\nReload to open the menu"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.IconLetter = ""
SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "rpg"
SWEP.WorldModel = ""
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.Category = "DarkRP (Utility)"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""
function SWEP:Initialize()
self:SetWeaponHoldType("normal")
end
function SWEP:Deploy()
return true
end
function SWEP:DrawWorldModel() end
function SWEP:PreDrawViewModel(vm)
return true
end
function SWEP:Holster()
if not SERVER then return true end
self.Owner:DrawViewModel(true)
self.Owner:DrawWorldModel(true)
return true
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 0.2)
if not SERVER then return end
local ent = self.Owner:GetEyeTrace().Entity
local canPickup, message = hook.Call("canPocket", nil, self.Owner, ent)
if not canPickup then
if message then DarkRP.notify(self.Owner, 1, 4, message) end
return
end
self.Owner:addPocketItem(ent)
end
function SWEP:SecondaryAttack()
if not SERVER then return end
local item = #self.Owner:getPocketItems()
if item <= 0 then
DarkRP.notify(self.Owner, 1, 4, DarkRP.getPhrase("pocket_no_items"))
return
end
self.Owner:dropPocketItem(item)
end
function SWEP:Reload()
if not CLIENT then return end
DarkRP.openPocketMenu()
end
local meta = FindMetaTable("Player")
DarkRP.stub{
name = "getPocketItems",
description = "Get a player's pocket items.",
parameters = {
},
returns = {
{
name = "items",
description = "A table containing crucial information about the items in the pocket.",
type = "table"
}
},
metatable = meta,
realm = "Shared"
}
[/CODE]
sv_init.lua
[CODE]local meta = FindMetaTable("Player")
/*---------------------------------------------------------------------------
Stubs
---------------------------------------------------------------------------*/
DarkRP.stub{
name = "dropPocketItem",
description = "Make the player drop an item from the pocket.",
parameters = {
{
name = "ent",
description = "The entity to drop.",
type = "Entity",
optional = false
}
},
returns = {
},
metatable = meta
}
DarkRP.stub{
name = "addPocketItem",
description = "Add an item to the pocket of the player.",
parameters = {
{
name = "ent",
description = "The entity to add.",
type = "Entity",
optional = false
}
},
returns = {
},
metatable = meta
}
DarkRP.stub{
name = "removePocketItem",
description = "Remove an item from the pocket of the player.",
parameters = {
{
name = "item",
description = "The entity to remove from pocket.",
type = "string",
optional = false
}
},
returns = {
},
metatable = meta
}
DarkRP.hookStub{
name = "canPocket",
description = "Whether a player can pocket a certain item.",
parameters = {
{
name = "ply",
description = "The player.",
type = "Player"
},
{
name = "item",
description = "The item to be pocketed.",
type = "Entity"
}
},
returns = {
{
name = "answer",
description = "Whether the entity can be pocketed.",
type = "boolean"
},
{
name = "message",
description = "The message to send to the player when the answer is false.",
type = "string"
}
}
}
DarkRP.hookStub{
name = "onPocketItemAdded",
description = "Called when an entity is added to the pocket.",
parameters = {
{
name = "ply",
description = "The pocket holder.",
type = "Player"
},
{
name = "ent",
description = "The entity.",
type = "Entity"
},
{
name = "serialized",
description = "The serialized version of the pocketed entity.",
type = "table"
}
},
returns = {
}
}
DarkRP.hookStub{
name = "onPocketItemRemoved",
description = "Called when an item is removed from the pocket.",
parameters = {
{
name = "ply",
description = "The pocket holder.",
type = "Player"
},
{
name = "item",
description = "The index of the pocket item.",
type = "number"
}
},
returns = {
}
}
/*---------------------------------------------------------------------------
Functions
---------------------------------------------------------------------------*/
-- workaround: GetNetworkVars doesn't give entities because the /duplicator/ doesn't want to save entities
local function getDTVars(ent)
if not ent.GetNetworkVars then return nil end
local name, value = debug.getupvalue(ent.GetNetworkVars, 1)
if name ~= "datatable" then
ErrorNoHalt("Warning: Datatable cannot be stored properly in pocket. Tell a developer!")
end
local res = {}
for k,v in pairs(value) do
res[k] = v.GetFunc(ent, v.index)
end
return res
end
local function serialize(ent)
local serialized = duplicator.CopyEntTable(ent)
serialized.DT = getDTVars(ent)
return serialized
end
local function deserialize(ply, item)
local ent = ents.Create(item.Class)
duplicator.DoGeneric(ent, item)
ent:Spawn()
ent:Activate()
duplicator.DoGenericPhysics(ent, ply, item)
table.Merge(ent:GetTable(), item)
local pos, mins = ent:GetPos(), ent:WorldSpaceAABB()
local offset = pos.z - mins.z
local trace = {}
trace.start = ply:EyePos()
trace.endpos = trace.start + ply:GetAimVector() * 85
trace.filter = ply
local tr = util.TraceLine(trace)
ent:SetPos(tr.HitPos + Vector(0, 0, offset))
local phys = ent:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
return ent
end
local function dropAllPocketItems(ply)
for k,v in pairs(ply.darkRPPocket or {}) do
ply:dropPocketItem(k)
end
end
util.AddNetworkString("DarkRP_Pocket")
local function sendPocketItems(ply)
net.Start("DarkRP_Pocket")
net.WriteTable(ply:getPocketItems())
net.Send(ply)
end
/*---------------------------------------------------------------------------
Interface functions
---------------------------------------------------------------------------*/
function meta:addPocketItem(ent)
if not IsValid(ent) or ent.USED then error("Entity not valid", 2) end
-- This item cannot be used until it has been removed
ent.USED = true
local serialized = serialize(ent)
hook.Call("onPocketItemAdded", nil, self, ent, serialized)
ent:Remove()
self.darkRPPocket = self.darkRPPocket or {}
local id = table.insert(self.darkRPPocket, serialized)
sendPocketItems(self)
return id
end
function meta:removePocketItem(item)
if not self.darkRPPocket or not self.darkRPPocket[item] then error("Player does not contain " .. item .. " in their pocket.", 2) end
hook.Call("onPocketItemRemoved", nil, self, item)
self.darkRPPocket[item] = nil
sendPocketItems(self)
end
function meta:dropPocketItem(item)
if not self.darkRPPocket or not self.darkRPPocket[item] then error("Player does not contain " .. item .. " in their pocket.", 2) end
local id = self.darkRPPocket[item]
local ent = deserialize(self, id)
-- reset USED status
ent.USED = nil
self:removePocketItem(item)
return ent
end
-- serverside implementation
function meta:getPocketItems()
self.darkRPPocket = self.darkRPPocket or {}
local res = {}
for k,v in pairs
There's a place in the darkrp config file to block certain entities I think.
Its not a glitch, its a feature. What good is a pocket if you can't fit car dealers in it?
[QUOTE=nettsam;44784451]There's a place in the darkrp config file to block certain entities I think.[/QUOTE]
I couldn't find it. I know what you're talking about but I think that was for older DarkRP.
DarkRPModification addon settings.lua
[QUOTE=DanielHershey;44788901]DarkRPModification addon settings.lua[/QUOTE]
I finally found the pocket blacklist, thank you.
Sorry, you need to Log In to post a reply to this thread.