• 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!

[Help] Simple Pet System

Ryryk

New Member
Joined
Jun 28, 2008
Messages
30
Reaction score
0
First off, im using [8.70] Mystic Spirit v0.2.10 Distro

Im looking for a script that will randomly summon one monster as the players pet when a egg is used. The pet does not attack, and cannot be attacked, all it does is basically follow the player. If the player has a pet already, they cannot get another one unless they release their current pet. A talk action that would summon the pet to the player would be awsome aswell as I assume the pet would lose the player if the the player dies or logs off ? If theres a way to make the pet spawn near the player when he dies or logs off that would be even better. But heres the item ids / pet names


Pet names spelt correctly. Each pet has a [Pet] tag infront of their name.

Code:
{"[Pet] Cat", "[Pet] Rat", "[Pet] Dog", "[Pet] Crab", "[Pet] Badger", "[Pet] Boar", "[Pet] Chicken", "[Pet] Sheep", "[Pet] Husky", "[Pet] Skunk", "[Pet] Cobra", "[Pet] Pig", "[Pet] Penguin", "[Pet] Rabbit", "[Pet] Squirrel"}

The id of the egg that randomly summons a pet

Code:
10523

The id of the item that releases the summoned pet so a new one can be obtained

Code:
10531
 
Okay so so far I have

Code:
local config = {
    randomize = 58,
v = {
        [{1, 3}] = {level = 8, monster = "[Pet] Cat", msg = "You shake the egg."},
        [{4, 6}] = {level = 8, monster = "[Pet] Rat", msg = "You shake the egg."},
        [{7, 10}] = {level = 8, monster = "[Pet] Dog", msg = "You shake the egg."},
        [{11, 14}] = {level = 8, monster = "[Pet] Crab", msg = "You shake the egg."},
        [{15, 18}] = {level = 8, monster = "[Pet] Badger", msg = "You shake the egg."},
        [{19, 22}] = {level = 8, monster = "[Pet] Boar", msg = "You shake the egg."},
        [{23, 26}] = {level = 8, monster = "[Pet] Chicken", msg = "You shake the egg."},
        [{27, 30}] = {level = 8, monster = "[Pet] Sheep", msg = "You shake the egg."},
        [{31, 34}] = {level = 8, monster = "[Pet] Husky", msg = "You shake the egg."},
        [{35, 38}] = {level = 8, monster = "[Pet] Skunk", msg = "You shake the egg."},
        [{39, 42}] = {level = 8, monster = "[Pet] Cobra", msg = "You shake the egg."},
        [{43, 46}] = {level = 8, monster = "[Pet] Pig", msg = "You shake the egg."},
        [{47, 50}] = {level = 8, monster = "[Pet] Penguin", msg = "You shake the egg."},
        [{51, 54}] = {level = 8, monster = "[Pet] Rabbit", msg = "You shake the egg."},
        [{55, 58}] = {level = 8, monster = "[Pet] Squirrel", msg = "You shake the egg."}                
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
 if (getCreatureCondition(cid, CONDITION_INFIGHT) == FALSE) and itemEx.itemid ~= 493 and math.random((100 + 50))
    then
        local formula, lvl = math.random(config.randomize), getPlayerLevel(cid)
        for range, inf in pairs(config.v) do
            if formula >= range[1] and formula <= range[2] and lvl >= inf.level then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, inf.msg)
                doSummonCreature(inf.monster, getThingPos(cid))
                break
  else
doPlayerSendCancel(cid,"You must be out of combat first!")
            end
        end
    end
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
    return true
end

It will randomly summon one of the monsters listed. This all works so far. Now im trying to figure out how to make it so the monster follows the player that summoned it.

And I know there is no storage ids or anything yet, im tryin to get everything done w/ the script before I have to do the storage values.

But any1 know how to force the creature to follow who ever it summoned ?
 
Code:
[B][COLOR="red"]doConvinceCreature(cid,[/COLOR][/B] doSummonCreature(inf.monster, getThingPos(cid))[B][COLOR="red"])[/COLOR][/B]
the monster will still chase the player's target, you can make it not hit and not get hit by editing its flags in the monster file and removing the attacks
 
Awsome tyvm.. Now I gotta figure out how to give the summoned pet a storage value so when the player logs out and logs back in or dies the pet will log back in aswell (or worst case, make a !petsummon spell to summon it to the player again). I'll post what I get.
 
you're supposed to set the storage for the player, not pet

setPlayerStorageValue(cid, 100, 1) + storage check in login.lua (if getPlayerStorageValue(cid, 100) == 1 then)

You can choose to put the first above code in a new onLogout and onDeath script,
OR in the summon actionscript and then make an onDeath script registered for the monster only, unsetting the storage for the monster's master (setPlayerStorageValue(getCreatureMaster(cid), 100, -1))
 
Last edited:
Okay heres what I got now


petsystem.lua

Code:
local config = {
    randomize = 58,
v = {
        [{1, 3}] = {level = 8, monster = "[Pet] Cat", msg = "You shake the egg."},
        [{4, 6}] = {level = 8, monster = "[Pet] Rat", msg = "You shake the egg."},
        [{7, 10}] = {level = 8, monster = "[Pet] Dog", msg = "You shake the egg."},
        [{11, 14}] = {level = 8, monster = "[Pet] Crab", msg = "You shake the egg."},
        [{15, 18}] = {level = 8, monster = "[Pet] Badger", msg = "You shake the egg."},
        [{19, 22}] = {level = 8, monster = "[Pet] Boar", msg = "You shake the egg."},
        [{23, 26}] = {level = 8, monster = "[Pet] Chicken", msg = "You shake the egg."},
        [{27, 30}] = {level = 8, monster = "[Pet] Sheep", msg = "You shake the egg."},
        [{31, 34}] = {level = 8, monster = "[Pet] Husky", msg = "You shake the egg."},
        [{35, 38}] = {level = 8, monster = "[Pet] Skunk", msg = "You shake the egg."},
        [{39, 42}] = {level = 8, monster = "[Pet] Cobra", msg = "You shake the egg."},
        [{43, 46}] = {level = 8, monster = "[Pet] Pig", msg = "You shake the egg."},
        [{47, 50}] = {level = 8, monster = "[Pet] Penguin", msg = "You shake the egg."},
        [{51, 54}] = {level = 8, monster = "[Pet] Rabbit", msg = "You shake the egg."},
        [{55, 58}] = {level = 8, monster = "[Pet] Squirrel", msg = "You shake the egg."}                
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if itemEx.itemid ~= 493 and math.random((100 + 50))
    then
        local formula, lvl = math.random(config.randomize), getPlayerLevel(cid)
        for range, inf in pairs(config.v) do
            if formula >= range[1] and formula <= range[2] and lvl >= inf.level then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, inf.msg)
                doConvinceCreature(cid, doSummonCreature(inf.monster, getThingPos(cid)))
                setPlayerStorageValue(cid, 100, 1)
                break
    else
        doPlayerSendTextMessage(cid,22,"You already have a pet!")
    
   end
 end
end
  doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
  return true
end


For the
Code:
setPlayerStorageValue(getCreatureMaster(cid), 100, -1)
I plan on using that for a npc or another item the player can use when they want a new pet.


For the storage check login.lua do I do it like this?

Code:
function onLogin(cid)
  if getPlayerStorageValue(cid, 100) == 1 then
	registerCreatureEvent(cid, "PlayerDeath")
	return TRUE
end

Or do I actually have to script in like,
Code:
  if getPlayerStorageValue(cid, 100) == 1 then
 doConvinceCreature(cid, doSummonCreature(inf.monster, getThingPos(cid)))

Not really sure what I would put to get the same monster to summon when player logs back on :S
 
Okay I was talkin to my friend, and he told me that if i did get it to work, it would bug if played was in pz, logged out and logged back in cause the monster cant go in pz... How would I make a talkaction !summonpet that would summon the pet you got from the egg? If any1 can even just give me what id put for finding the pet the player got, i could prob figure out the rest.
 
Back
Top