• Assigning NPCs Levels and Setting Their Health
    1 replies, posted
Hi guys! I am trying to make a npc leveling system and set the npc's health based on their level. I have the following code: NPC_That_Lvls = {     ["npc_zombie"] = {5, 10},     ["npc_headcrab"] = {1, 5} } local NPC = FindMetaTable("Npc") function NPC:SetNPCLevel(value1, value2) if IsValid(self) then NPC_Level = math.random(value1, value2) self:SetNPCHealth(NPC_Level) end end function NPC:GetLevel() return self.NPC_Level end function NPC:SetNPCHealth(lvl) if (IsValid(self)) and (self:GetLevel() != nil) then self:SetHealth(self:GetMaxHealth() + (lvl * 25)) end end for k, v in pairs(ents.GetAll()) do     if NPC_That_Lvls[v:GetClass()] then         local range = NPC_That_Lvls[v:GetClass()]         v:SetNPCLevel(range[1], range[2])     end end I am new to GLua so please do not criticize me too hard, but all feedback is appreciated. I am trying to make custom methods for the NPC class but I am getting this error: [ERROR] gamemodes/testrealm/gamemode/modules/npcs/sh_npclevels.lua:8: attempt to index local 'NPC' (a nil value)   1. unknown - gamemodes/testrealm/gamemode/modules/npcs/sh_npclevels.lua:8    2. include - [C]:-1     3. recursiveInclusion - gamemodes/testrealm/gamemode/shared.lua:41      4. unknown - gamemodes/testrealm/gamemode/shared.lua:67       5. include - [C]:-1        6. unknown - gamemodes/testrealm/gamemode/cl_init.lua:1
There's no such metatable like "Npc" They're combined with Entity metatable. FindMetaTable("Entity")
Sorry, you need to Log In to post a reply to this thread.