Code is errorless but not working how it's supposed to v2
1 replies, posted
Hello I made a post about this yesterday. I have a simple script that I made that runs without errors but does not work. The zombies are supposed to be assigned a level and then get their HP set accordingly. Rubat told me to network the variables and pointed out that I was trying to call a GetLevel() function clientside while the function is a server side function as it was written. I fixed all of that but it still does not work. Here is the code:
NPC_That_Lvls = {
["npc_zombie"] = {5, 10},
["npc_headcrab"] = {1, 5}
}
local NPC = FindMetaTable("Entity")
function NPC:SetNPCLevel(value1, value2)
if IsValid(self) then
self:SetNWInt("NPCLevel", math.random(value1, value2))
self:SetNPCHealth(NPC_Level)
end
end
function NPC:GetLevel()
return self:GetNWInt("NPCLevel", 1)
end
function NPC:SetNPCHealth(lvl)
if (IsValid(self)) and (self:GetLevel() != nil) then
self:SetMaxHealth(self:GetMaxHealth() + (lvl * 25))
self:SetHealth(self:GetMaxHealth())
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
hook.Add( "OnEntityCreated", "GivingNPCLevels", function( ent )
if ( ent:GetClass() == NPC_That_Lvls[ent:GetClass()] ) then
ent:SetNPCLevel(range[1], range[2])
end
end )
All advice and help is appreciated! Thanks!
This has been solved! I need to use a custom setter to set the HP of the NPCs.
Sorry, you need to Log In to post a reply to this thread.