Hello everyone, I'm trying to modify this Hellboy system starting by adding mana, but when I do it and call back the PET it throws me this error:
Lua Script Error: [Action Interface]
data/actions/scripts/petcontainer2.lua
nUse
data/lib/pets_lib.lua:377: attempt to call method 'setMaxMana' (a nil value)
stack traceback:
[C]: in function 'setMaxMana'
data/lib/pets_lib.lua:377: in function 'summonPet'
data/actions/scripts/petcontainer2.lua:34: in function <data/actions/scripts/petcontainer2.lua:1>
This is the script where I'm trying to add the mana (I tried to do it the same way as the one in Health):
Lua Script Error: [Action Interface]
data/actions/scripts/petcontainer2.lua

data/lib/pets_lib.lua:377: attempt to call method 'setMaxMana' (a nil value)
stack traceback:
[C]: in function 'setMaxMana'
data/lib/pets_lib.lua:377: in function 'summonPet'
data/actions/scripts/petcontainer2.lua:34: in function <data/actions/scripts/petcontainer2.lua:1>
This is the script where I'm trying to add the mana (I tried to do it the same way as the one in Health):
LUA:
---- based on Jordanhenry pet system version 1.77 (changelog)
---- edited by hellboy
-- config
PETS = {
PREFIX = "PET_",
CHANNELID = 10,
CONFIG = {
introduction = "You may catch pets using command '!petcatch'. If your pet dies, you have to revive it in order to re-summon it. Some pets have a special requirement in order to catch them, some cannot be catched at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
sameSpeed = true,
healSoulCost = 0.1,
healSoulBase = 10,
healManaCost = 200,
healOnLevelUp = true,
standardHpAdd = 5,
standardManaAdd = 3,
expMultipler = 1,
shareExpMultipler = 0.5,
maxLevel = 30,
reviveMoneyCost = 1000,
reviveMoneyLevelCost = 500
},
SYSTEM = {
EVOLUTION = true,
MOUNTS = false,
TELEPORT = true,
PLAYER_SHARE_EXPERIENCE = true, --dejar en false
DUELS_ONLY = false
},
IDENTIFICATION = {
[1] = {
name = "Cat",
health = 100,
evolve = {
to = 3, -- 3 es el id del monster al que va a evolucionar, en este caso a tiger
at = 10 -- al nivel que va a evolucionar, en este caso al lvl 10
},
check = true
},
[2] = {
name = "Dog",
health = 100,
evolve = {
to = 4,
at = 10
},
check = true
},
[3] = {
name = "Tiger",
health = 300,
check = false,
info = "Evolves from Cat."
},
[4] = {
name = "Lion",
health = 300,
mountId = 40,
check = false,
info = "Evolves from Dog."
},
[5] = {
name = "Husky",
health = 150,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[6] = {
name = "Wolf",
health = 200,
evolve = {
to = 7,
at = 4
},
check = function(player) return player:getLevel() >= 10 end,
info = "Requires level 10."
},
[7] = {
name = "War Wolf",
health = 500,
evolve = {
to = 8,
at = 55
},
check = false,
info = "Evolves from Wolf."
},
[8] = {
name = "Werewolf",
health = 1000,
mana = 100,
check = false,
info = "Evolves from War Wolf."
},
[9] = {
name = "Bear",
health = 300,
mana = 100,
mountId = 3,
check = function(player) return player:getLevel() >= 10 end,
info = "Only available to druids above level 10."
},
[10] = {
name = "Panda",
health = 300,
mountId = 19,
check = function(player) return player:getLevel() >= 10 end,
info = "Only available to druids above level 10."
},
[11] = {
name = "Chicken",
health = 50,
check = true
},
[12] = {
name = "Sheep",
health = 50,
check = true
},
[13] = {
name = "Seagull",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[14] = {
name = "Parrot",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[15] = {
name = "Penguin",
health = 100,
check = function(player) return player:getPremiumDays() > 0 end,
info = "Requires a premium account."
},
[16] = {
name = "Elephant",
health = 300,
check = function(player) return player:getLevel() >= 10 end,
contain = 5,
info = "Only available to Premium accounts above level 10."
},
[17] = {
name = "Dragon Hatchling",
health = 300,
mana = 100,
evolve = {
to = 18, -- es el id del monster al que va a evolucionar
at = 2 -- el nivel al que va a evolucionar
},
check = function(player) return player:getLevel() >= 25 end,
info = "Only available to Premium players above level 25."
},
[18] = {
name = "Dragon",
health = 1000,
mana = 100,
check = false,
info = "Evolves from Dragon Hatchling."
},
[19] = {
name = "Soul Devorer",
health = 550000,
mana = 100,
check = true,
}
},
STORAGE = {
TYPE = 10000,
UID = 10001,
LOSTHEALTH = 10002,
MAXHEALTH = 10003,
EXPERIENCE = 10004,
LEVEL = 10005,
MANA = 10006,
LOSTMANA = 10007,
MAXMANA = 10008
},
CONSTANS = {
STATUS_OK = 0,
STATUS_DOESNT_EXIST = -1,
STATUS_DEAD = -2,
STATUS_MOUNT = -3
}
}
-- get
function Player.getPetExperience(self)
return self:getStorageValue(PETS.STORAGE.EXPERIENCE)
end
function Player.getPetLevel(self)
return self:getStorageValue(PETS.STORAGE.LEVEL)
end
function Player.getPetType(self)
return self:getStorageValue(PETS.STORAGE.TYPE)
end
function Player.getPetUid(self)
return self:getStorageValue(PETS.STORAGE.UID)
end
function Player.getPetMaxHealth(self)
return self:getStorageValue(PETS.STORAGE.MAXHEALTH)
end
function Player.getPetLostHealth(self)
return self:getStorageValue(PETS.STORAGE.LOSTHEALTH)
end
function Player.getPetMountId(self)
local petType = self:getPetType()
local mountId = PETS.IDENTIFICATION[petType].mountId
return mountId
end
function Player.getPetMaxMana(self)
return self:getStorageValue(PETS.STORAGE.MAXMANA)
end
function Player.getPetLostMana(self)
return self:getStorageValue(PETS.STORAGE.LOSTMANA)
end
-- set
function Player.setPetExperience(self, experience)
return self:setStorageValue(PETS.STORAGE.EXPERIENCE, experience)
end
function Player.setPetLevel(self, petLevel)
return self:setStorageValue(PETS.STORAGE.LEVEL, petLevel)
end
function Player.setPetType(self, petType)
return self:setStorageValue(PETS.STORAGE.TYPE, petType)
end
function Player.setPetUid(self, petUid)
return self:setStorageValue(PETS.STORAGE.UID, petUid)
end
function Player.setPetMaxHealth(self, health)
return self:setStorageValue(PETS.STORAGE.MAXHEALTH, health)
end
function Player.setPetLostHealth(self, health)
return self:setStorageValue(PETS.STORAGE.LOSTHEALTH, health)
end
function Player.setPetMaxMana(self, mana)
return self:setStorageValue(PETS.STORAGE.MAXMANA, mana)
end
function Player.setPetLostMana(self, mana)
return self:setStorageValue(PETS.STORAGE.LOSTMANA, mana)
end
-- other
function Player.doAddPet(self, petType)
local pet = Creature(self:getStorageValue(PETS.STORAGE.UID))
if pet then
return false
end
self:setPetUid(PETS.CONSTANS.STATUS_OK)
self:setPetExperience(0)
self:setPetLevel(1)
self:setPetType(petType)
self:setPetMaxHealth(PETS.IDENTIFICATION[petType].health)
self:setPetLostHealth(0)
self:setPetMaxHealth(PETS.IDENTIFICATION[petType].mana)
self:setPetLostMana(0)
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil and mountId ~= 0 then
self:addMount(mountId)
end
end
return true
end
function Player.doResetPet(self)
for _, i in pairs(PETS.STORAGE) do
self:setStorageValue(i, -1)
end
return true
end
function Player.doRemovePet(self)
local petUid = self:getPetUid()
local pet = Creature(petUid)
if not pet or not pet:isCreature() then
if petUid > 0 then
self:setPetUid(PETS.CONSTANS.STATUS_OK)
end
return true
end
local maxHealth = pet:getMaxHealth()
local maxMana = pet:getMaxMana()
self:setPetMaxHealth(maxHealth)
self:setPetLostHealth(maxHealth - pet:getHealth() )
self:setPetMaxMana(maxMana)
self:setPetLostMana(maxMana - pet:getMana() )
pet:remove()
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:addMount(mountId)
end
end
return true
end
function Player.doKillPet(self, removeBody)
if removeBody then
self:doRemovePet()
end
self:setPetUid(PETS.CONSTANS.STATUS_DEAD)
self:setPetLostHealth(0)
self:setPetLostMana(0)
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:removeMount(mountId)
end
end
return true
end
function Player.summonPet(self, position)
local petUid = self:getPetUid()
local pet = Creature(petUid)
if pet and pet:isCreature() then
return false
end
if (Tile(position)):hasFlag(TILESTATE_PROTECTIONZONE) then
return false
end
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
local currentMount = self:getOutfit()['lookMount']
if mountId ~= nil and currentMount ~= nil and currentMount ~= 0 and currentMount == mountId then
return false
end
end
local pet = Game.createMonster(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name), position)
if pet then
position:sendMagicEffect(CONST_ME_TELEPORT)
pet:setMaster(self)
local maxHealth = self:getPetMaxHealth()
local maxMana = self:getPetMaxMana()
pet:setMaxHealth(maxHealth)
pet:addHealth(maxHealth - pet:getHealth() - self:getPetLostHealth() )
pet:setMaxMana(maxMana)
pet:addMana(maxMana - pet:getMana() - self:getPetLostMana() )
self:setPetUid( pet:getId() )
pet:setSkull(SKULL_GREEN)
pet:changeSpeed(PETS.CONFIG.sameSpeed and (self:getBaseSpeed() - pet:getBaseSpeed()) or 0)
for _, eventName in pairs({"PetDeath", "PetKill"}) do
pet:registerEvent(eventName)
end
if PETS.SYSTEM.TELEPORT then
pet:registerEvent("PetTeleport")
end
if PETS.SYSTEM.DUELS_ONLY then
pet:registerEvent("PetHealthChange")
end
if PETS.SYSTEM.MOUNTS then
local mountId = self:getPetMountId()
if mountId ~= nil then
self:removeMount(mountId)
end
end
return pet
end
local petMonsterType = MonsterType(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name))
if not petMonsterType then
print('[PET-SYSTEM] Cant find monster type: ' .. PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name) )
end
return false
end
function getExpNeeded(level)
return ( (50 *level^3) -(150 *level^2) +(400 *level) )/3 *PETS.CONFIG.expMultipler
end
function Player.addPetExp(self, amount)
local pet = Creature(self:getPetUid())
if not pet then
return false
end
if self:getPetLevel() >= PETS.CONFIG.maxLevel then
return false
end
local totalExp = self:getPetExperience() + amount
self:setPetExperience(totalExp)
local petLevel, petType, petUid = self:getPetLevel(), self:getPetType(), self:getPetUid()
if totalExp >= getExpNeeded(petLevel + 1) then
pet:setMaxHealth(pet:getMaxHealth() + (PETS.IDENTIFICATION[petType].hpAdd or PETS.CONFIG.standardHpAdd))
pet:setMaxMana(pet:getMaxMana() + (PETS.IDENTIFICATION[petType].manaAdd or PETS.CONFIG.standardManaAdd))
self:setPetLevel(petLevel +1)
self:say("Your pet " .. PETS.IDENTIFICATION[petType].name .. " has advanced to level " .. (petLevel + 1) .. ".", TALKTYPE_SAY)
if PETS.CONFIG.healOnLevelUp then
pet:addHealth( pet:getMaxHealth() )
pet:addMana( pet:getMaxMana() )
end
if PETS.SYSTEM.EVOLUTION and (PETS.IDENTIFICATION[petType]).evolve and ((PETS.IDENTIFICATION[petType]).evolve.at <= (petLevel +1)) then
local position = pet:getPosition()
self:doRemovePet()
self:setPetType( (PETS.IDENTIFICATION[petType]).evolve.to)
self:setPetMaxHealth( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).health )
self:setPetLostHealth(0)
self:setPetMaxMana( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).mana )
self:setPetLostMana(0)
self:say("Your pet "..(PETS.IDENTIFICATION[petType]).name.." has evolved to a "..((PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).name)..".", TALKTYPE_SAY)
self:summonPet(position)
end
-- save max hp fix
self:setPetMaxHealth(pet:getMaxHealth())
self:setPetMaxMana(pet:getMaxMana())
end
return true
end
function Player.canGetPet(self, petId)
if self:getGroup():getId() >= 3 then
return true
end
if type(PETS.IDENTIFICATION[petId].check) == "function" then
return PETS.IDENTIFICATION[petId].check(self)
end
return PETS.IDENTIFICATION[petId].check
end
-- is Pet
function Player.isPet(self)
return false
end
function Npc.isPet(self)
return false
end
function Monster.isPet(self)
local owner = self:getMaster()
if owner:isPlayer() and owner:getPetUid() == self:getId() then
return true
end
return false
end