• Use is a nil value or did I just goof?
    1 replies, posted
Hey guys so I am trying to use DERP Inv and ran into an odd error whenever I try to use an item from the inventory. Here is the code and the error thanks for reading/your time! P.S- I tried looking around and asking others, but I have failed to find an answer. All suggestions/fixes are appreciated greatly. [CODE] AddCSLuaFile("autorun/client/cl_drpinv.lua") AddCSLuaFile("autorun/drpshared.lua") AddCSLuaFile("autorun/colchat.lua") require("glon") -- CONVARS -- local maxitems = CreateConVar( "drp_maxitems", "15", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) local maxguns = CreateConVar( "drp_maxguns", "4", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) local maxshipments = CreateConVar( "drp_maxshipments", "2", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) local maxfood = CreateConVar( "drp_maxfood", "6", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) local shouldlog = CreateConVar( "drp_printinfo", "0", { FCVAR_REPLICATED, FCVAR_ARCHIVE } ) -- HOOKS -- local function plyjoin(ply) local path = "drpinv/" .. ply:UniqueID() .. ".txt" if file.Exists( path, "DATA" ) then ply.inv = glon.decode(file.Read(path)) ply:ColChat("SERVER", Color(0,255,0), "Welcome back " .. ply:Nick() .. "! Your inventory has been loaded.") else ply.inv = { } ply.inv._size = 0 -- hacky, hope no one names an ent _size ply.inv.sweps = {} ply.inv.ships = {} ply.inv.foods = {} ply:SaveInv() --ply:ColChat("DrpInv", Color(0,255,0), "This server is running the DrpInv! Type !inv to show your inventory, hold alt+use to pickup a valid item.") end if shouldlog:GetBool() then print("[INV]: Loaded data for " .. ply:Nick()) end ply:SendInv() ply.canuse = true --to stop textspam/multiple pickups --since darkrp ents dont check for uninitialized vars we have to init the max vars incase someone hasnt spawned anythign "legit" yet if not ply.maxFoods then ply.maxFoods = 0 end if not ply.maxDrugs then ply.maxDrugs = 0 end end hook.Add("PlayerInitialSpawn","DrpInvSpawn",plyjoin) local function plydis(ply) ply:SaveInv() timer.Destroy("canuse" .. ply:UniqueID()) end hook.Add("PlayerDisconnected","DrpPlyLeave",plydis) local function plyuse(ply, ent) -- handle normal ents first if ply:KeyDown(IN_WALK) and !ply.canuse then return false end if ply:KeyDown(IN_WALK) and items[ent:GetClass()] then if !ply.inv[ent:GetClass()] then ply.inv[ent:GetClass()] = 0 end if ply.inv._size >= maxitems:GetInt() then ply:ColChat("DrpInv", Color(0,255,0), "Your inventory is full!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end local max = items[ent:GetClass()]["max"] if max > 0 and ply.inv[ent:GetClass()] >= max then ply:ColChat("DrpInv", Color(0,255,0), "You have reached the maximum amount for that item!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end ply.inv._size = ply.inv._size + 1 ply:AddItem(ent:GetClass(), 1) ply:EmitSound("items/ammo_pickup.wav", 100, 100) local vec = ply:GetPos() - ent:GetPos() ent:GetPhysicsObject():ApplyForceCenter(Vector(0,0,450)) ent:SetNotSolid(true) local ed = EffectData() ed:SetEntity(ent) util.Effect( "propspawn", ed ) SafeRemoveEntityDelayed(ent, 0.75) ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end -- now handle the stupid special cases -- sweps first if ply:KeyDown(IN_WALK) and ent:GetClass() == "spawned_weapon" and weps[ent.weaponclass] then if ply.inv._size >= maxitems:GetInt() then ply:ColChat("DrpInv", Color(0,255,0), "Your inventory is full!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end if #table.ClearKeys(ply.inv.sweps) >= maxguns:GetInt() then ply:ColChat("DrpInv", Color(0,255,0), "You have reached the maximum amount of sweps!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end local gun = { model = ent:GetModel(), class = ent.weaponclass } ply.inv._size = ply.inv._size + 1 ply:AddSwep(gun) ply:EmitSound("items/ammo_pickup.wav", 100, 100) local vec = ply:GetPos() - ent:GetPos() ent:GetPhysicsObject():ApplyForceCenter(Vector(0,0,400)) ent:SetNotSolid(true) local ed = EffectData() ed:SetEntity(ent) util.Effect( "propspawn", ed ) SafeRemoveEntityDelayed(ent, 0.75) ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end -- now food if ply:KeyDown(IN_WALK) and ent:GetClass() == "spawned_food" and foodies[ent:GetModel()] then if ply.inv._size >= maxitems:GetInt() then ply:ColChat("DrpInv", Color(0,255,0), "Your inventory is full!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end if #table.ClearKeys(ply.inv.foods) >= maxfood:GetInt() then ply:ColChat("DrpInv", Color(0,255,0), "You have reached the maximum amount of food!") ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false end local food = { model = ent:GetModel(), amount = ent.FoodEnergy } ply.inv._size = ply.inv._size + 1 ply:AddFood(food) ply:EmitSound("items/ammo_pickup.wav", 100, 100) local vec = ply:GetPos() - ent:GetPos() ent:GetPhysicsObject():ApplyForceCenter(Vector(0,0,800)) -- fatty melons need a bigger kick ent:SetNotSolid(true) local ed = EffectData() ed:SetEntity(ent) util.Effect( "propspawn", ed ) SafeRemoveEntityDelayed(ent, 0.75) ply.canuse = false timer.Create("canuse" .. ply:UniqueID(), 1, 1,function() ply.canuse = true end) return false
I believe the arguments are as follows: [code]Entity:Use( Player user, Entity activator, Number usetype (USE Enums), 1 )[/code] second argument may be misnomered, and I don't know what the fourth argument is supposed to be, but 1 seems to work for me.
Sorry, you need to Log In to post a reply to this thread.