• Lua Runtime Error darkRPPockets
    11 replies, posted
Issue: When all scavanger items are sold and the player presses the "sell item" button it creates a runtime error because dropPocketItem(a darkrp pocket function) is expecting an entity. I don't know a way around this. Mayday, Mayday! Error: [DarkRP] Sold Scavanger Hunt Items for $1000000 [DarkRP] A ru.. lua: --[[Init.lua]]-- net.Receive("myMessage", function(len, ply)--Net.Receive from clientside Derma "Sell Items" Button if ply:Team() == TEAM_HOBO then --[[SCAVENGER ITEM PRICES]]-- ScavangerHunt_ItemWorth = { Common = 10000, Uncommon = 25000, Rare = 50000, Mythic = 100000, Universal = 1000000, } --[[SCAVENGER ITEMS]]-- ScavangerHunt_Items = {     { Name = "Lemon", Rarity = "Universal", EntClass = "coin_pickup", model = "watermelon01.mdl`",} } --[[CHECK DARKRP POCKET FOR SCAVENGER ITEMS]]--             local Table, Num=ply.darkRPPocket or {},0               for key,item in pairs(ScavangerHunt_Items) do                     local Bag=ply:dropPocketItem(key)--The problem child (line 54)                     if(Bag)then SafeRemoveEntity(Bag) end                     Num=Num+1                 end --[[IF SCAVENGER ITEMS ARE FOUND]]--             if(Num>0)then                 for i, v in pairs(ScavangerHunt_Items) do            local name = v.Name                     local rarity = v.Rarity                     local class = v.EntClass                     local model = v.Model                  local cost = ScavangerHunt_ItemWorth[rarity]                 ply:addMoney(cost)                 DarkRP.notify(ply,4,4,"Sold Scavanger Hunt Items for $"..tostring(cost))         end        end     end   end) Things I've tried(on line 54): if Num<=0 then return if table.Count(ScavangerHunt_Items) == 0 then return if table.Count(getPocketItems) == 0 then return if table.Count(ScavangerHunt_Items) == 0 then return elseif table.Count(ScavangerHunt_Items) > 0 then --and a whole mess of others I can't remember darkRPPockets Documentation/helpful links: https://github.com/FPtje/DarkRP/blob/master/entities/weapons/pocket/sv_init.lua Category Functions/Player/Server/addPocketItem Functions/Player/Server/dropPocketItem Functions/Player/Shared/getPocketItems Functions/Player/Server/removePocketItem
Just wrap the drop function in a IsValid "if" condition before running the actual dropping code. Something like this should work: if(IsValid(key)) then ply:dropPocketItem(key) end Also you have: local Bag = ply:dropPocketItem(key) but in the documentation for the function it says that nothing gets returned, so Bag is always going to be "nil"
I ended up having a friend help me though I appreciate the response. Uh... How do I give you 5 coins? lol want to chit-chat till there's 5 posts?
There's no need.
Could I ask you another question? local scavitems = {} scavitems["scav_common"] = { Name = "Lemon1", Rarity = "Common", model = "models/props_c17/doll01.mdl"} hook.Add( "PreDrawHalos", "AddPropHalos", function()     halo.Add(scavitems, Color(255,255,255), 2, 2, 5, true, false ) end ) I'm just trying to get this entity to glow with a halo. It's being called in the cl_init.lua but isn't working - I don't have a firm grasp on tables yet unfortunately. :/
The table is not valid. All values inside the table need to be entities, not the name of the class. When spawning in the entity add it on a table and use that table to draw the halo.
Could you give me an example? What's the difference between the name of the class and the entity itself?
The class name for an entity is what you use to get all you need to know about it. For example if you want to spawn a basic prop you will use ents.Create("prop_physics") and lated set its model and finalize the spawning process so it generates the hitbox and physics. Here are some examples I can think of: Toolgun = "gmod_tool" Player = "player" World = "worldspawn" (The world itself is an entity too! Make sure to not delete it accidentally) These also come in handy when you need to search all entities of a certain type. For example if you wanted to find all props on the server you can use this: https://wiki.garrysmod.com/page/ents/FindByClass (Also look at the example) That value is a string, while the entity itself is its own class. Almost everything is an entity (Because Source works this way, other engines can decide to do it another way), particles are entities, same for effects, light, weapons, tools, players, props, viewmodels, skybox and even the color of the sky is an entity, don't ask why. Now if you want to run a function like https://wiki.garrysmod.com/page/Entity/Remove you need to target the entity itself, which is why your table doesn't work with halo.Add() Every entity has its own ID and two entities can never had the same ID (Unless you have a really fucked up client to server communication). Hope this cleared up a bit.
I'm still confused in the example here: halo.Add it says you can use the ents.FindByClass but when I use my Entity's class nothing happens. But if I use props_physics it works just fine?
Care to leave a snippet of the code? Not sure why that would be happening.
I figured out ish... why it isn't working but I'm not sure how to fix it: function ENT:Initialize()     util.PrecacheSound("addons/coin_pickup/sound/Lemons.wav")     self:SetModel("models/props_c17/doll01.mdl")     self:SetMaterial("models/shiny")     self:PhysicsInit(SOLID_VPHYSICS)     self:SetMoveType(MOVETYPE_NONE)     self:SetSolid(SOLID_VPHYSICS)     self:SetColor(Color(255,221,0))     local phys = self:GetPhysicsObject()     if (phys:IsValid()) then         phys:Wake()     self:SetCollisionGroup(COLLISION_GROUP_WEAPON)          self:SetTrigger(true)--start touch events or others     self:DrawShadow(false)     PrintTable(ents.GetAll())     end end It's an entity that bobs up and down while rotating it's not an npc or anything it's just an entity there is no hull type and I can't set the hull type for whatever reason.
I see what you're trying to do, it really doesn't have a model to display on the server, what it does is use that model just to create the physics. The model being displayed (Which I guess is self.csModel) needs to be set somewhere because I don't see it. Use https://wiki.garrysmod.com/page/Global/ClientsideModel to create one in the Initialize function and set it to self.csModel The drawHalo hook should work.
Sorry, you need to Log In to post a reply to this thread.