Someone help me with this code please?

Post Reply
FreezeShot
New to forums
New to forums
Posts: 2
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Tue Mar 26, 2013 3:32 pm

Can someone help me with this code?

Post by FreezeShot »

SWEP (keys) is derived from non existant SWEP (weapon_base) - Expect errors!

[ERROR] gamemodes/darkrp/entities/weapons/keys/shared.lua:38: attempt to call method 'SetWeaponHoldType' (a nil value)
1. unknown - gamemodes/darkrp/entities/weapons/keys/shared.lua:38

SWEP (weapon_cs_base2) is derived from non existant SWEP (weapon_base) - Expect errors!
SWEP (weapon_cs_base2) is derived from non existant SWEP (weapon_base) - Expect errors!

[ERROR] gamemodes/darkrp/entities/weapons/pocket/shared.lua:44: attempt to call method 'SetWeaponHoldType' (a nil value)
1. unknown - gamemodes/darkrp/entities/weapons/pocket/shared.lua:44
it keep giving me lua erros :/
FreezeShot
New to forums
New to forums
Posts: 2
Joined: Tue Mar 26, 2013 3:32 pm

Someone help me with this code please?

Post by FreezeShot »

FreezeShot has been made a Citizen!
SWEP (keys) is derived from non existant SWEP (weapon_base) - Expect errors!

[ERROR] gamemodes/darkrp/entities/weapons/keys/shared.lua:38: attempt to call method 'SetWeaponHoldType' (a nil value)
1. unknown - gamemodes/darkrp/entities/weapons/keys/shared.lua:38

SWEP (weapon_cs_base2) is derived from non existant SWEP (weapon_base) - Expect errors!
SWEP (weapon_cs_base2) is derived from non existant SWEP (weapon_base) - Expect errors!

[ERROR] gamemodes/darkrp/entities/weapons/pocket/shared.lua:42: attempt to call method 'SetWeaponHoldType' (a nil value)
1. unknown - gamemodes/darkrp/entities/weapons/pocket/shared.lua:42

My pocket code is this
if SERVER then
AddCSLuaFile("shared.lua")
end

if CLIENT then
SWEP.PrintName = "Pocket"
SWEP.Slot = 1
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
end

SWEP.Base = "weapon_cs_base2"

SWEP.Author = "FPtje and everyone who gave FPtje the idea"
SWEP.Instructions = "Left click to pick up, right click to drop, reload for menu"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.IconLetter = ""

SWEP.ViewModelFOV = 62
SWEP.ViewModelFlip = false
SWEP.AnimPrefix = "rpg"

SWEP.Spawnable = false
SWEP.AdminSpawnable = true
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 = ""

if CLIENT then
SWEP.FrameVisible = false
end

function SWEP:Initialize()
self:SetWeaponHoldType("normal")
end

function SWEP:Deploy()
if SERVER then
self.Owner:DrawViewModel(false)
self.Owner:DrawWorldModel(false)
end
end

local blacklist = {"fadmin_jail", "drug_lab", "money_printer", "meteor", "microwave", "door", "func_", "player", "beam", "worldspawn", "env_", "path_", "darkrp_console"}
function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire(CurTime() + 0.2)
local trace = self.Owner:GetEyeTrace()

if not IsValid(trace.Entity) or (SERVER and trace.Entity:IsPlayerHolding()) then
return
end

if self.Owner:EyePos():Distance(trace.HitPos) > 65 then
return
end

self:SetWeaponHoldType("pistol")
timer.Simple(0.2, function() if self:IsValid() then self:SetWeaponHoldType("normal") end end)

if CLIENT then return end

local phys = trace.Entity:GetPhysicsObject()
if not phys:IsValid() then return end
local mass = trace.Entity.RPOriginalMass and trace.Entity.RPOriginalMass or phys:GetMass()

self.Owner:GetTable().Pocket = self.Owner:GetTable().Pocket or {}
if not trace.Entity:CPPICanPickup(self.Owner) or trace.Entity.IsPocketed or trace.Entity.jailWall then
GAMEMODE:Notify(self.Owner, 1, 4, "You can not put this object in your pocket!")
return
end
for k,v in pairs(blacklist) do
if string.find(string.lower(trace.Entity:GetClass()), v) then
GAMEMODE:Notify(self.Owner, 1, 4, "You can not put "..v.." in your pocket!")
return
end
end

if mass > 100 then
GAMEMODE:Notify(self.Owner, 1, 4, "This object is too heavy.")
return
end

if #self.Owner:GetTable().Pocket >= GAMEMODE.Config.pocketitems then
GAMEMODE:Notify(self.Owner, 1, 4, "Your pocket is full!")
return
end


umsg.Start("Pocket_AddItem", self.Owner)
umsg.Short(trace.Entity:EntIndex())
umsg.End()

table.insert(self.Owner:GetTable().Pocket, trace.Entity)
trace.Entity:SetNoDraw(true)
trace.Entity:SetPos(trace.Entity:GetPos())
local phys = trace.Entity:GetPhysicsObject()
phys:EnableMotion(false)
trace.Entity.OldCollisionGroup = trace.Entity:GetCollisionGroup()
trace.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
trace.Entity.PhysgunPickup = false
trace.Entity.OldPlayerUse = trace.Entity.PlayerUse
trace.Entity.PlayerUse = false
trace.Entity.IsPocketed = true
end

function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + 0.2)

if CLIENT then return end

if not self.Owner:GetTable().Pocket or #self.Owner:GetTable().Pocket <= 0 then
GAMEMODE:Notify(self.Owner, 1, 4, "Your pocket contains no items.")
return
end

self:NewSetWeaponHoldType("pistol")
timer.Simple(0.2, function() if self:IsValid() then self:NewSetWeaponHoldType("normal") end end)

local ent = self.Owner:GetTable().Pocket[#self.Owner:GetTable().Pocket]
self.Owner:GetTable().Pocket[#self.Owner:GetTable().Pocket] = nil
if not IsValid(ent) then GAMEMODE:Notify(self.Owner, 1, 4, "Your pocket contains no items.") return end

self.Owner:DropPocketItem(ent)
end

SWEP.OnceReload = false
function SWEP:Reload()
if CLIENT or self.Weapon.OnceReload then return end
self.Weapon.OnceReload = true
timer.Simple(0.5, function() self.Weapon.OnceReload = false end)

if not self.Owner:GetTable().Pocket or #self.Owner:GetTable().Pocket <= 0 then
GAMEMODE:Notify(self.Owner, 1, 4, "Your pocket contains no items.")
return
end

for k,v in pairs(self.Owner:GetTable().Pocket) do
if not IsValid(v) then
self.Owner:GetTable().Pocket[k] = nil
self.Owner:GetTable().Pocket = table.ClearKeys(self.Owner:GetTable().Pocket)
if #self.Owner:GetTable().Pocket <= 0 then -- Recheck after the entities have been validated.
GAMEMODE:Notify(self.Owner, 1, 4, "Your pocket contains no items.")
return
end
end
end

umsg.Start("StartPocketMenu", self.Owner)
umsg.End()
end

if CLIENT then
local function StorePocketItem(um)
LocalPlayer():GetTable().Pocket = LocalPlayer():GetTable().Pocket or {}

local ent = Entity(um:ReadShort())
if IsValid(ent) and not table.HasValue(LocalPlayer():GetTable().Pocket, ent) then
table.insert(LocalPlayer():GetTable().Pocket, ent)
end
end
usermessage.Hook("Pocket_AddItem", StorePocketItem)

local function RemovePocketItem(um)
LocalPlayer():GetTable().Pocket = LocalPlayer():GetTable().Pocket or {}

local ent = Entity(um:ReadShort())
for k,v in pairs(LocalPlayer():GetTable().Pocket) do
if v == ent then LocalPlayer():GetTable().Pocket[k] = nil end
end
end
usermessage.Hook("Pocket_RemoveItem", RemovePocketItem)

local frame
local function PocketMenu()
if frame and frame:IsValid() and frame:IsVisible() then return end
if LocalPlayer():GetActiveWeapon():GetClass() ~= "pocket" then return end
if not LocalPlayer():GetTable().Pocket then LocalPlayer():GetTable().Pocket = {} return end
for k,v in pairs(LocalPlayer():GetTable().Pocket) do if not IsValid(v) then table.remove(LocalPlayer():GetTable().Pocket, k) end end
if #LocalPlayer():GetTable().Pocket <= 0 then return end
LocalPlayer():GetTable().Pocket = table.ClearKeys(LocalPlayer():GetTable().Pocket)
frame = vgui.Create("DFrame")
frame:SetTitle("Drop item")
frame:SetVisible( true )
frame:MakePopup( )

local items = LocalPlayer():GetTable().Pocket
local function Reload()
frame:SetSize( #items * 64, 90 )
frame:Center()
for k,v in pairs(items) do
if not IsValid(v) then
items[k] = nil
for a,b in pairs(LocalPlayer().Pocket) do
if b == v or not IsValid(b) then
LocalPlayer():GetTable().Pocket[a] = nil
end
end
items = table.ClearKeys(items)
frame:Close()
PocketMenu()
break
end
local icon = vgui.Create("SpawnIcon", frame)
icon:SetPos((k-1) * 64, 25)
icon:SetModel(v:GetModel())
icon:SetSize(64, 64)
icon:SetToolTip()
icon.DoClick = function()
icon:SetToolTip()
RunConsoleCommand("_RPSpawnPocketItem", v:EntIndex())
items[k] = nil
for a,b in pairs(LocalPlayer().Pocket) do
if b == v then
LocalPlayer():GetTable().Pocket[a] = nil
end
end
if #items == 0 then
frame:Close()
return
end
items = table.ClearKeys(items)
Reload()
LocalPlayer():GetActiveWeapon():SetWeaponHoldType("pistol")
timer.Simple(0.2, function() if LocalPlayer():GetActiveWeapon():IsValid() then LocalPlayer():GetActiveWeapon():SetWeaponHoldType("normal") end end)
end
end
end
Reload()
frame:SetSkin("DarkRP")
end
usermessage.Hook("StartPocketMenu", PocketMenu)
elseif SERVER then
local function Spawn(ply, cmd, args)
if ply:GetActiveWeapon():GetClass() ~= "pocket" then
return
end
if ply:GetTable().Pocket and IsValid(Entity(tonumber(args[1]))) then
local ent = Entity(tonumber(args[1]))
if not table.HasValue(ply.Pocket, ent) then return end

for k,v in pairs(ply:GetTable().Pocket) do
if v == ent then
ply:GetTable().Pocket[k] = nil
end
end
ply:GetTable().Pocket = table.ClearKeys(ply:GetTable().Pocket)

ply:GetActiveWeapon():SetWeaponHoldType("pistol")
timer.Simple(0.2, function() if ply:GetActiveWeapon():IsValid() then ply:GetActiveWeapon():SetWeaponHoldType("normal") end end)

ply:DropPocketItem(ent)
end
end
concommand.Add("_RPSpawnPocketItem", Spawn)

local meta = FindMetaTable("Player")
function meta:DropPocketItem(ent)
local trace = {}
trace.start = self:EyePos()
trace.endpos = trace.start + self:GetAimVector() * 85
trace.filter = self
local tr = util.TraceLine(trace)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNoDraw(false)
ent:SetCollisionGroup(ent.OldCollisionGroup)
ent:SetPos(tr.HitPos)
ent:SetSolid(SOLID_VPHYSICS)
local phys = ent:GetPhysicsObject()
if phys:IsValid() then
phys:EnableCollisions(true)
phys:EnableMotion(true)
phys:Wake()
end
umsg.Start("Pocket_RemoveItem", self)
umsg.Short(ent:EntIndex())
umsg.End()
ent.PhysgunPickup = nil
ent.PlayerUse = ent.OldPlayerUse
ent.OldPlayerUse = nil
ent.IsPocketed = nil
end

hook.Add("PlayerDeath", "DropPocketItems", function(ply)
local pocket = ply.Pocket
ply.Pocket = nil
if not GAMEMODE.Config.droppocketdeath or not pocket then return end

for k, v in pairs(pocket) do
if IsValid(v) then
ply:DropPocketItem(v)
end
end
end)
end

Works on single player but not multiplayer -.-
User avatar
kraze
Former staff
Former staff
Posts: 4362
Joined: Fri Sep 17, 2010 9:06 am
Location: California

Re: Someone help me with this code please?

Post by kraze »

Try to be careful about doing multiple topics on the same issue as it could cause some confusion. I went ahead and merged your two post together.

Also, do you have any more detail then this? What are you trying to do? What do you expect to happen and what is the result?

What have you tried to fix it?
@Kraze^NFo> Juski has a very valid point
@Juski> Got my new signature, thanks!
@Kraze^NFo> Out of context!
@Juski> Doesn't matter!
@Juski> You said I had a valid point! You can't take it back now! It's out there!
Post Reply