Lurk
Active Member
- Joined
- Dec 4, 2017
- Messages
- 336
- Reaction score
- 48
Hello, I have a pet system and I have this problem:
You summon your pet and it spawns full life, as intented. You can also at any time unspawn it by using the item again;
If my pet loses let's say 80% of it's health, I can simply use my item again to unspawn and then use again to spawn it full health
I want to check if the pet is at full health when despawning and, if it's not, save it's current health for 2 minutes so if someone tries to spawn the pet again it'll spawn with the amount of health it had before.
simple_pet.lua
actions.xml
You summon your pet and it spawns full life, as intented. You can also at any time unspawn it by using the item again;
If my pet loses let's say 80% of it's health, I can simply use my item again to unspawn and then use again to spawn it full health
I want to check if the pet is at full health when despawning and, if it's not, save it's current health for 2 minutes so if someone tries to spawn the pet again it'll spawn with the amount of health it had before.
simple_pet.lua
Lua:
function onUse(cid, item, frompos, item2, topos)
local dolls = {
[11256] = {pet = "Crystal Spider"},
[11207] = {pet = "Ashmunrah"},
[11144] = {pet = "Demon"},
[9019] = {pet = "Vampire"},
}
local go = dolls[item.itemid]
local summon = getCreatureSummons(cid)
---------------------------------------------------
if #summon >= 1 then
for _, pid in ipairs(summon) do
doRemoveCreature(pid)
doCreatureSay(cid, "Can go rest ["..go.pet.."]", TALKTYPE_ORANGE_1)
end
return true
end
doConvinceCreature(cid, doSummonCreature(go.pet, getCreaturePosition(cid)))
doCreatureSay(cid, "Let battle ["..go.pet.."]", TALKTYPE_ORANGE_1)
return true
end
actions.xml
XML:
<action itemid="11256;11207;11144;9019" event="script" value="simple_pet.lua"/>