So officially day 5 of working on this project, causing the biggest headache ever. Tried multiple Developer discords but no one can figure out what's wrong so before I give up on the custom project i'll try here. Below is the code I have added in (shared.lua) and the purpose of the addon is to make NPCs spawn out of a drop pod entity. The drop pod is set up, it drops and works perfectly, but a constant error "attempt to call field 'create' (a nil value) regardless of what value I have. Tried adding this code into init.lua instead but that just bugs out the drop pod and leaves a big error floating in the sky.
-------------------------------------------------------------------------------
ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.PrintName = "Droid Dispenser"
ENT.Category = "Droid Dispenser"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.AdminOnly = false
ENT.DoNotDuplicate = true
ENT.MineAmmo = 5
function ENT:SetupDataTables()
self:NetworkVar("Int", 0, "MineAmmoNum")
end
function ENT:Initialize()
timer.Create("tood", 5, 3, function()
local tood = ents.Create("npc_sw_droid_b1_h");
if (not IsValid(tood)) then return end
tood:SetModel("models/tfa/comm/gg/npc_cit_sw_droid_b1.mdl")
tood:Give("weapon_physgun")
tood:SetHealth(400)
tood:SetPos(entclass:GetPos() + Vector(5, 0, 5))
tood:Spawn()
end)
end
------------------------------------------------------------------------------------
If anyone has any idea what i'm doing wrong or what I am missing it would be greatly appreciated. I'm not looking for someone to spoonfeed me the code, I won't learn that way but I'm at the point of going insane with this script but don't want to abandon it because I have put in this much time and effort so far.
I haven't used the "code" option on the the chat box as it merges all my code together and doesn't let me separate my ends and functions so I have just closed it off with a bunch of -----.
Thanks in advanced.
which line
The first thing you should do is make sure you copy+paste both the code and the error message. I can tell you failed to do this for at least one of them, as the error is about a missing "create" function and the code uses "Create". If your error is a typo, re-typing either creates the potential of hiding the typo, and thus, nobody can help you.
Additionally, the code references the value "entclass", which is not defined anywhere. Perhaps you meant "self"?
Same issue
So the full error..
[ERROR] addons/droid_dispenser_entities_1397048823/lua/entities/droid_dispenser/shared.lua:18: attempt to call field 'Create' (a nil value)
1. unknown - addons/droid_dispenser_entities_1397048823/lua/entities/droid_dispenser/shared.lua:18
Timer Failed! [tood][@addons/droid_dispenser_entities_1397048823/lua/entities/droid_dispenser/shared.lua (line 17)]
It's not recognizing the value for ents.Create on line 18.
if SERVER takes away the error but the NPCs still don't spawn for some reason so I am still missing something from the code
Managed to get it working. Everything looks good. Thanks for the replies!
Sorry, you need to Log In to post a reply to this thread.