• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Table for pet system

Code:
creatureevents
dofile('mods/scripts/pets/pets.lua')

function onPrepareDeath(cid, deathList)
local owner = getCreatureMaster(cid)
sendMessage(owner, "Your pet has died.")
setPlayerPet(owner, -2)
setPlayerStorageValue(owner, STORAGE.LOSTHEALTH, getPlayerStorageValue(owner, STORAGE.MAXHEALTH))
return true
end

function onKill(cid, target, lastHit)
if isMonster(target) then
local targetName = getCreatureName(target)
local owner = getCreatureMaster(cid)
local experienceGain = getMonsterInfo(targetName).experience
addPetExp(owner, experienceGain)
end
return true
end

function onLogin(cid)
registerCreatureEvent(cid, "PetChannelJoin")
registerCreatureEvent(cid, "PetChannelLeave")
registerCreatureEvent(cid, "PetLogout")
return true
end

function onLogout(cid)
local pet = getPlayerPet(cid)
if not isCreature(pet) then
return true
end
maxHealth = getCreatureMaxHealth(pet)
setPlayerStorageValue(cid, STORAGE.MAXHEALTH, maxHealth)
setPlayerStorageValue(cid, STORAGE.LOSTHEALTH, maxHealth - getCreatureHealth(pet))
setPlayerPet(cid, 0)
doSendMagicEffect(getCreaturePosition(pet), CONST_ME_POFF)
doRemoveCreature(pet)
return true
end

function onJoinChannel(cid, channel, users)
if channel == PETS.CHANNELID then
if getPlayerPet(cid) == -1 then
return addEvent(sendMessage, 100, cid, "You do not have a pet. Type 'help' for an introduction to the pet system.")
elseif getPlayerPet(cid) == -2 then
return addEvent(sendMessage, 100, cid, "Your pet is dead. Revive it using the 'revive' command.")
end
return summonPet(cid, getPlayerLookPos(cid)) and addEvent(sendMessage, 100, cid, "Type 'status' to see your pet's status.") or addEvent(sendMessage, 100, cid, "You may not summon your pet here.")
end
return true
end

function onLeaveChannel (cid, channel, users)
if channel == PETS.CHANNELID then
return onLogout(cid)
end
return true
end
Code:
pets
PETS = {
VERSION = "1.76",
PREFIX = "PET_",
CHANNELID = 10,
CONFIG = {
introduction = "You may purchase pets for a one-time cost. The prices depends on the type of pets you choose. If your pet dies, you have to revive it in order to summon it again. Some pets have a special requirement in order to purchase them, some cannot be purchased at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
hpAdd = 5,
sameSpeed = false,
healCost = 2,
healCostBase = 100,
healSoul = 0.1,
healSoulBase = 25,
},
IDENTIFICATION = {
[1] = {
name = "Cat",
price = 100,
health = 100,
evolve = {
to = 3,
at = 10,
},
check = true,
},
[2] = {
name = "Dog",
price = 100,
health = 100,
evolve = {
to = 4,
at = 10,
},
check = true,
},
[3] = {
name = "Tiger",
price = false,
health = 300,
check = false,
info = "Evolves from Cat."
},
[4] = {
name = "Lion",
price = false,
health = 300,
check = false,
info = "Evolves from Dog."
},
[5] = {
name = "Husky",
price = 150,
health = 150,
check = function(cid) return isPremium(cid) end,
info = "Requires a premium account."
},
[6] = {
name = "Wolf",
price = 300,
health = 200,
evolve = {
to = 7,
at = 28,
},
check = function(cid) return getPlayerLevel(cid) >= 10 end,
info = "Requires level 10."
},
[7] = {
name = "War Wolf",
price = false,
health = 500,
evolve = {
to = 8,
at = 55,
},
check = false,
info = "Evolves from Wolf."
},
[8] = {
name = "Werewolf",
price = false,
health = 1000,
check = false,
info = "Evolves from War Wolf."
},
[9] = {
name = "Bear",
price = 200,
health = 300,
check = function(cid) return isDruid(cid) and getPlayerLevel(cid) >= 10 end,
info = "Only available to druids above level 10."
},
[10] = {
name = "Panda",
price = 200,
health = 300,
check = function(cid) return isDruid(cid) and getPlayerLevel(cid) >= 10 end,
info = "Only available to druids above level 10."
},
[11] = {
name = "Chicken",
price = 50,
health = 50,
check = true,
},
[12] = {
name = "Sheep",
price = 50,
health = 50,
check = true,
},
[13] = {
name = "Seagull",
price = 100,
health = 100,
check = function(cid) return isPremium(cid) end,
info = "Requires a premium account."
},
[14] = {
name = "Parrot",
price = 100,
health = 100,
check = function(cid) return isPremium(cid) end,
info = "Requires a premium account."
},
[15] = {
name = "Penguin",
price = 100,
health = 100,
check = function(cid) return isPremium(cid) end,
info = "Requires a premium account."
},
[16] = {
name = "Elephant",
price = 300,
health = 300,
check = function(cid) return isPremium(cid) and getPlayerLevel(cid) >= 10 end,
info = "Only available to Premium accounts above level 10."
},
[17] = {
name = "Dragon Hatchling",
price = 1000,
health = 300,
evolve = {
to = 18,
at = 20,
},
check = function(cid) return isPremium(cid) and isSorcerer(cid) and getPlayerLevel(cid) >= 25 end,
info = "Only available to Premium Sorcerers above level 25."
},
[18] = {
name = "Dragon",
price = false,
health = 1000,
check = false,
info = "Evolves from Dragon Hatchling."
},
}
}

STORAGE = {
PETTYPE = 10000,
PETUID = 10001,
LOSTHEALTH = 10002,
MAXHEALTH = 10003,
EXPERIENCE = 10004,
LEVEL = 10005,
}

function getExpNeeded(level)
return (50 * (level - 1)^3 - 150 * (level - 1)^2 + 400 * (level - 1)) / 3
end

petNames = {}
for i, v in ipairs(PETS.IDENTIFICATION) do
petNames[v.name:lower()] = i
end

function sendMessage(cid, message)
return doPlayerSendChannelMessage(cid, "", message, TALKTYPE_CHANNEL_O, PETS.CHANNELID)
end

function resetPlayerPet(cid)
setPlayerStorageValue(cid, STORAGE.PETTYPE, -1)
setPlayerStorageValue(cid, STORAGE.PETUID, -1)
setPlayerStorageValue(cid, STORAGE.LOSTHEALTH, 0)
setPlayerStorageValue(cid, STORAGE.MAXHEALTH, 0)
setPlayerStorageValue(cid, STORAGE.EXPERIENCE, 0)
setPlayerStorageValue(cid, STORAGE.LEVEL, 1)
end

function getPlayerPet(cid)
return getPlayerStorageValue(cid, STORAGE.PETUID)
end

function setPlayerPet(cid, pet)
return setPlayerStorageValue(cid, STORAGE.PETUID, pet)
end

function getPlayerPetType(cid)
return getPlayerStorageValue(cid, STORAGE.PETTYPE)
end

function setPlayerPetType(cid, type)
return setPlayerStorageValue(cid, STORAGE.PETTYPE, type)
end

function evolvePet(cid)
local pet = PETS.IDENTIFICATION[getPlayerPetType(cid)]
if pet.evolve then
local petcid = getPlayerPet(cid)
local pos
if isCreature(petcid) then
pos = getCreaturePosition(petcid)
doRemoveCreature(petcid)
end
setPlayerPet(cid, 0)
setPlayerPetType(cid, pet.evolve.to)
setPlayerStorageValue(cid, STORAGE.MAXHEALTH, PETS.IDENTIFICATION[pet.evolve.to].health)
setPlayerStorageValue(cid, STORAGE.LOSTHEALTH, 0)
if pos then
summonPet(cid, pos)
end
return true
end
return false
end

function addPetExp(cid, amount)
local totalExp = getPlayerStorageValue(cid, STORAGE.EXPERIENCE) + amount
setPlayerStorageValue(cid, STORAGE.EXPERIENCE, totalExp)
local level = getPlayerStorageValue(cid, STORAGE.LEVEL)
local leveled = false
local hpAdd = PETS.IDENTIFICATION[getPlayerPetType(cid)].hpAdd or PETS.CONFIG.hpAdd
local pid = getPlayerPet(cid)
local maxHp = getCreatureMaxHealth(pid)
while totalExp >= getExpNeeded(level + 1) do
level = level + 1
maxHp = maxHp + hpAdd
leveled = true
end
if leveled then
local petType = getPlayerPetType(cid)
setCreatureMaxHealth(pid, maxHp)
setPlayerStorageValue(cid, STORAGE.LEVEL, level)
sendMessage(cid, "Your "..PETS.IDENTIFICATION[petType].name.." has leveled up to level "..level..".")
if PETS.IDENTIFICATION[petType].evolve then
if level >= PETS.IDENTIFICATION[petType].evolve.at then
local position = getCreaturePosition(cid)
evolvePet(cid)
sendMessage(cid, "Your "..PETS.IDENTIFICATION[petType].name.." has evolved into a "..PETS.IDENTIFICATION[PETS.IDENTIFICATION[petType].evolve.to].name..".")
end
end
end
end

function addPet(cid, type)
if isCreature(getPlayerPet(cid)) then
return false
end
resetPlayerPet(cid)
setPlayerPet(cid, 0)
setPlayerPetType(cid, type)
setPlayerStorageValue(cid, STORAGE.MAXHEALTH, PETS.IDENTIFICATION[type].health)
return true
end

function summonPet(cid, pos)
local petuid = getPlayerPet(cid)
if isCreature(petuid) then
return false
end
if getTilePzInfo(getCreaturePosition(cid)) or getTilePzInfo(pos) or doTileQueryAdd(cid, pos) ~= 1 then
return false
end
local pet = doSummonCreature(PETS.PREFIX..PETS.IDENTIFICATION[getPlayerPetType(cid)].name, pos)
if isCreature(pet) then
doSendMagicEffect(pos, CONST_ME_TELEPORT)
doConvinceCreature(cid, pet)
if PETS.CONFIG.sameSpeed then
doChangeSpeed(petuid, getCreatureBaseSpeed(cid) - getCreatureBaseSpeed(petuid))
end
local maxHealth = getPlayerStorageValue(cid, STORAGE.MAXHEALTH)
setCreatureMaxHealth(pet, maxHealth)
doCreatureAddHealth(pet, maxHealth - getCreatureHealth(pet) - getPlayerStorageValue(cid, STORAGE.LOSTHEALTH))
setPlayerPet(cid, pet)
doCreatureSetSkullType(pet, SKULL_YELLOW)
registerCreatureEvent(pet, "PetDeath")
registerCreatureEvent(pet, "PetKill")
return pet
end
return false
end

function canBuyPet(cid, id)
if getPlayerAccess(cid) >= 3 then
return true
end
if not PETS.IDENTIFICATION[id].price then
return false
end
if type(PETS.IDENTIFICATION[id].check) == "function" then
return PETS.IDENTIFICATION[id].check(cid)
end
return PETS.IDENTIFICATION[id].check
end
Code:
talk
dofile('mods/scripts/pets/pets.lua')

COMMANDS = {
version = function(cid)
return sendMessage(cid, "Pet System v"..PETS.VERSION.." by Jordanhenry")
end,
help = function(cid)
return sendMessage(cid, PETS.CONFIG.introduction)
end,
commands = function(cid)
local allCommands = ""
for i, v in pairs(COMMANDS) do
allCommands = allCommands..i.."; "
end
return sendMessage(cid, "Commands: "..allCommands)
end,
buy = function(cid, param)
if getPlayerStorageValue(cid, STORAGE.PETUID) ~= -1 then
return sendMessage(cid, "You already have a pet.")
end
if param == "" then
return sendMessage(cid, "buy <name>")
end
local id = petNames[param:lower()]
local pet = PETS.IDENTIFICATION[id]
if pet then
if canBuyPet(cid, id) then
if doPlayerRemoveMoney(cid, pet.price) then
addPet(cid, id)
if type(PETS.IDENTIFICATION[id].onBuy) == "function" then
PETS.IDENTIFICATION[id].onBuy()
end
summonPet(cid, getPlayerLookPos(cid))
return sendMessage(cid, "You have bought a "..pet.name..(pet.price and " for a price of "..pet.price.." gold coins." or "."))
end
return sendMessage(cid, "You do not have enough money for a "..pet.name.." ("..pet.price..").")
end
return sendMessage(cid, "You do not have the requirements for a "..pet.name..". or this pet is not on sale.")
end
return sendMessage(cid, "Type 'list' for a list of pets you can buy.")
end,
info = function(cid, param)
if param == "" then
return sendMessage(cid, "info <name>")
end
local pet = PETS.IDENTIFICATION[petNames[param:lower()]]
return sendMessage(cid, pet and (
"Name: "..pet.name..
(pet.price and "\nPrice: "..pet.price or "\nNot on sale.")..
(pet.evolve and "\nEvolve to "..PETS.IDENTIFICATION[pet.evolve.to].name.." at level "..pet.evolve.at.."." or "\nUnable to evolve further.")..
(pet.info and "\n"..pet.info or ""))
or "There is no such pet.")
end,
list = function(cid)
local allPets = ""
for id, pet in ipairs(PETS.IDENTIFICATION) do
if canBuyPet(cid, id) then
allPets = allPets..pet.name.."; "
end
end
return sendMessage(cid, "Pets available to you: "..allPets)
end,
status = function(cid)
local pet = getPlayerPet(cid)
local level = getPlayerStorageValue(cid, STORAGE.LEVEL)
local health
if isCreature(pet) then
health = getCreatureHealth(pet).."/"..getCreatureMaxHealth(pet)
elseif pet == 0 then
local maxHealth = getPlayerStorageValue(cid, STORAGE.MAXHEALTH)
health = maxHealth - getPlayerStorageValue(cid, STORAGE.LOSTHEALTH).."/"..maxHealth
elseif pet == -2 then
health = "DEAD"
end
return health and sendMessage(cid, "Name: "..PETS.IDENTIFICATION[getPlayerPetType(cid)].name.."\nHealth: "..health.."\nLevel: "..level.."\nExperience: "..getPlayerStorageValue(cid, STORAGE.EXPERIENCE).."/"..getExpNeeded(level+1)) or sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end,
summon = function(cid)
local pet = getPlayerPet(cid)
if isCreature(pet) then
local telePos = getPlayerLookPos(cid)
local petPos = getCreaturePosition(pet)
if getDistanceBetween(telePos, petPos) > 1 then
if doTileQueryAdd(pet, telePos) == 1 then
doTeleportThing(pet, telePos)
doSendMagicEffect(petPos, CONST_ME_POFF)
doSendMagicEffect(telePos, CONST_ME_TELEPORT)
return sendMessage(cid, "Your pet has been summoned to you.")
end
return sendMessage(cid, "You may not summon your pet here.")
end
return sendMessage(cid, "Your pet is too close to you.")
elseif pet == 0 then
return summonPet(cid, getPlayerLookPos(cid)) and addEvent(sendMessage, 100, cid, "Type 'status' to see your pet's status.") or addEvent(sendMessage, 100, cid, "You may not summon your pet here.")
elseif pet == -2 then
return sendMessage(cid, "Your pet is dead. Revive it using the 'revive' command.")
end
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end,
speak = function(cid, param)
local pet = getPlayerPet(cid)
if isCreature(pet) then
return doCreatureSay(pet, param, TALKTYPE_ORANGE_1)
elseif pet == 0 then
return sendMessage(cid, "Summon your pet first.")
elseif pet == -2 then
return sendMessage(cid, "Your pet is dead. Revive it using the revive command.")
end
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end,
release = function(cid, param)
local pet = getPlayerPet(cid)
if pet == -1 then
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end
if param:lower() == PETS.IDENTIFICATION[getPlayerPetType(cid)].name:lower() then
local pet = getPlayerPet(cid)
if isCreature(pet) then
doSendMagicEffect(getCreaturePosition(pet), CONST_ME_POFF)
doRemoveCreature(pet)
end
resetPlayerPet(cid)
return sendMessage(cid, "You have released your pet.")
end
return sendMessage(cid, "Are you sure you want to release your pet? Use the command 'release <pet name>' to confirm your action.")
end,
revive = function(cid, param)
local pet = getPlayerPet(cid)
if pet == -1 then
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
elseif pet == -2 then
local petType = getPlayerPetType(cid)
local cost = PETS.IDENTIFICATION[getPlayerPetType(cid)].health * getPlayerStorageValue(cid, STORAGE.LEVEL)
if tonumber(param) == cost then
if doPlayerRemoveMoney(cid, cost) then
setPlayerPet(cid, 0)
setPlayerStorageValue(cid, STORAGE.LOSTHEALTH, getPlayerStorageValue(cid, STORAGE.MAXHEALTH) - 1)
return sendMessage(cid, "You have revived your pet for "..cost.." gold coins. Heal it before sending it into battle.")
end
return sendMessage(cid, "You do not have enough money to revive your pet.")
end
return sendMessage(cid, "It will cost "..cost.." gold coins to revive your pet. Use the command 'revive <cost>' to confirm your action.")
end
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end,
heal = function(cid, param)
local pet = getPlayerPet(cid)
if isCreature(pet) then
local petType = getPlayerPetType(cid)
local currHealth = getCreatureHealth(pet)
local healHealth = (PETS.IDENTIFICATION[getPlayerPetType(cid)].health-currHealth)
if (currHealth < PETS.IDENTIFICATION[getPlayerPetType(cid)].health) then
local cost = healHealth * PETS.CONFIG.healCost + PETS.CONFIG.healCostBase
local soulCost = math.min(math.ceil(healHealth * PETS.CONFIG.healSoul + PETS.CONFIG.healSoulBase), 100)
if tonumber(param) == cost then
if doPlayerRemoveMoney(cid, cost) then
doCreatureAddHealth(pet, healHealth)
doSendMagicEffect(getCreaturePos(pet), CONST_ME_HEARTS)
return sendMessage(cid, "You have healed your pet for "..cost.." gold coins.")
end
return sendMessage(cid, "You do not have enough money to revive your pet.")
elseif param == "soul" then
if getPlayerSoul(cid) >= soulCost then
doPlayerAddSoul(cid, -soulCost)
doCreatureAddHealth(pet, healHealth)
doSendMagicEffect(getCreaturePos(pet), CONST_ME_HEARTS)
return sendMessage(cid, "You have healed your pet for "..soulCost.." soul points.")
end
return sendMessage(cid, "You do not have enough soul points to revive your pet.")
end
return sendMessage(cid, "It will cost ("..cost.." gold coins) OR ("..soulCost.." soul points) to heal your pet. Use the command 'heal <cost>' OR 'heal soul' to confirm your action.")
end
return sendMessage(cid, "Your pet is already at its maximum health.")
elseif pet == 0 then
return sendMessage(cid, "Summon your pet first.")
elseif pet == -2 then
return sendMessage(cid, "Your pet is dead. Revive it using the revive command.")
end
return sendMessage(cid, "You do not have a pet. Buy one using the command 'buy'.")
end,
}

function onSay(cid, words, param, channel)
return COMMANDS[words](cid, param) or false
end
Code:
pets.xml
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Pets" version="1.77" author="Jordanhenry" contact="-" enabled="yes">
<description>
v1.77
simple bugfix for 'version' and 'help' command
v1.76
removed creatureevent "PetAttack"
fixed getPlayerPet and setPlayerPet
v1.75
added 'heal' command
health lost * healCost + healCostBase = cost to be payed
health lost * healSoul + healSoulBase = soul to be payed
*soul to be payed cannot exceed 100
v1.74
hpAdd now defaults to the value you set in the config.
added sameSpeed, set it to true to allow the pet to be the same speed as the owner.
v1.73
added hpAdd, amount of max health added when the pet levels. defaults to 5.
v1.72
fixed another bug in buying pets
v1.71
fixed bug in onPrepareDeath
v1.7
added support for custom requirements
added ability to add more information to 'info' command
v1.6
added more pets
added 'revive' command
v1.5
fixed bug where the pet only levels when it is greater than the level to evolve
added 'release' command
v1.41
fixed bug where you can buy 2 pets
v1.4
added leveling up
v1.31
fixed 'list' command
v1.3
added evolution
added buyable/unbuyable pets
v1.2
added 'speak' command
added 'version' command
v1.11
fixed one line
v1.1
rewrote most of it again, fixed some bugs
v1.0
started from scratch
</description>
<event type="login" name="PetLogin" event="script" value="pets/creatureevents.lua"/>
<event type="logout" name="PetLogout" event="script" value="pets/creatureevents.lua"/>
<event type="preparedeath" name="PetDeath" event="script" value="pets/creatureevents.lua"/>
<event type="kill" name="PetKill" event="script" value="pets/creatureevents.lua"/>
<event type="joinchannel" name="PetChannelJoin" event="script" value="pets/creatureevents.lua"/>
<event type="leavechannel" name="PetChannelLeave" event="script" value="pets/creatureevents.lua"/>
<talkaction words="help;commands;buy;info;list;summon;status;speak;release;revive;heal" channel="10" hide="yes" event="script" value="pets/talkactions.lua"/>
<channel id="10" name="Pet"/>
<!-- Pet Monsters -->
<monster name="PET_Cat" file="pets/cat.xml"/>
<monster name="PET_Dog" file="pets/dog.xml"/>
<monster name="PET_Husky" file="pets/husky.xml"/>
<monster name="PET_Lion" file="pets/lion.xml"/>
<monster name="PET_Tiger" file="pets/tiger.xml"/>
<monster name="PET_Wolf" file="pets/wolf.xml"/>
<monster name="PET_War Wolf" file="pets/war wolf.xml"/>
<monster name="PET_Werewolf" file="pets/werewolf.xml"/>
<monster name="PET_Bear" file="pets/bear.xml"/>
<monster name="PET_Panda" file="pets/panda.xml"/>
<monster name="PET_Seagull" file="pets/seagull.xml"/>
<monster name="PET_Parrot" file="pets/parrot.xml"/>
<monster name="PET_Chicken" file="pets/chicken.xml"/>
<monster name="PET_Penguin" file="pets/penguin.xml"/>
<monster name="PET_Sheep" file="pets/sheep.xml"/>
<monster name="PET_Elephant" file="pets/elephant.xml"/>
<monster name="PET_Dragon Hatchling" file="pets/dragon hatchling.xml"/>
<monster name="PET_Dragon" file="pets/dragon.xml"/>
</mod>
Code:


UPDATE player_storage SET key = 10000 WHERE key = 0
this sql code not working
 
pet system
no are working
commands
are working
buy name
summon
others commands do not working
i need for working all commands
for buy pet need you enter in pet chat
in pet chat do not speak nothing
need speak
normal is
hello here is pet chat for more informations "help"
player enter help
is show commands for pets

in my ot not show commands

i am novice in scripts ;D
 
in pet system by FEDEVI
this function

!pet
not working on my ot :D
nothing in executavel

i have only "login"
and "playerdeath"
can me help ?


"""""""""""""'
in pet system by jordany
in pet chat working this
functions
buy pet
summon
others not working
i don't know
when i enter in pet chat
no speak nothing :D
have poblem?
 
Last edited:
Back
Top