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

Lua Catch monsters

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, otlanders, hope you guys are fine :).
im trying to modify this script.
these are the features:
1-.Use X ítem on monster
2-.% succes rate
3-.If monster captured (ex. Wolf) it soul get contained until use

my requeriments are these:
-If i capture a Wolf, when i use the ítem it should summon a Hunting Wolf (instead of a normal and weak Wolf)
-If i capture a Bear, when i use the ítem it should summon a Hunting Bear (adding Hunting [Monster Name])

but im experiencing difficulties adding hunting to prefix, hole you guys could try help.

script(TFS 0.4):
Lua:
-- Options for releasing the monster with another item --
local useBreakWithItem = false -- Enable this feature
local breakWithItem = 7428 -- Item to release the monster with.
-- Item Options --
local setActionId = 1001 -- Action id that will be set for an used item.
local breakChanse = 0 -- Break chanse. For example: if breakChanse = 500 then break chanse will be ((CurrentHp/monsterMaxHp)*monsterMaxHp)/500).
-- Limits --
local playerLevel = 8 -- Player level needed.
local monsterStatus = "convinced" -- Keep it as "convinced" if you want the monster to be like a pet for the releaser, otherwise make it "wild".
local avalibleMonsters = {"Dog", "Wolf", "Bear", "Tiger" ,"Elephant"} -- Monsters that is possible to catch. ALWAYS write the name exactly as it is written in the monster files(It maters in this case).
local validVocations = {0, 1, 2, 3, 4, 5, 6, 7, 8} -- Vocationids of vocations that are able to use this item.
-- Effects --
local breakEffect = CONST_ME_POFF -- This effect will apear on the item when it breakes.
local usedEffect = CONST_ME_POFF -- This effect will apear on the item if it is used.
local successEffect = CONST_ME_MAGIC_GREEN -- This effect will apear on the monster when it's catched.
local releaseEffect = CONST_ME_FIREWORK_RED -- This effect will apear when the monster is released.
-- Messages --
local emptyDesc = "It\'s empty." -- Description that will be set for the item when the monster is released.
local messageColor = TALKTYPE_ORANGE_1
local successMessages = {"You\'ve succefully caught the monster.", "Success!!"} -- Success messages when the creature is caught.
local failureMessages = {"You\'ve failed to catch the monster.", "The monster ran away."} -- Failure messages.
local usedMessages = {"This item is already used", "You\'ve already used this item."} -- One of these messages apears if the item is already used.
local abortMessages = {"You\'ve failed to catch the monster.", "The monster is too strong."} -- Abort messages if the monster is in the ignore list above.
local notOnGroundMessage = {"Please put the item on the ground first.", "You can\'t release the creature in your backpack."} -- These messages apears if the item is not on the ground.
local inOnInvalidGround = {"The item is on a protected zone.", "You can\'t release the monster here."} -- These messages apears if the item is on a protected zone.
local tooLowLevel = {"You are too low level to use this item, you'll need level ".. playerLevel .." or higher."}
local invalidVocation = {"You are not able to use this item."}
--------------- END OF CONFIG -------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLevel(cid) < playerLevel then
        sendMessage(cid, tooLowLevel, messageColor)
        return true
    end
    if not isInArray(validVocations, getPlayerVocation(cid)) then
        sendMessage(cid, invalidVocation, messageColor)
        return true
    end
    if useBreakWithItem then
        if item.itemid == breakWithItem and releaseMonster(cid, itemEx, toPosition) then
            return true
        end
    else
        if releaseMonster(cid, item, toPosition) then
            return true
        end
    end
    if item.actionid > 100 then
        if item.actionid ~= setActionId then
            doItemSetAttribute(item.uid, "aid", setActionId)
        end
        sendMessage(cid, usedMessages, messageColor)
        doSendMagicEffect(getCreaturePosition(cid), usedEffect)
        return true
    end
    if isMonster(itemEx.uid) then
        monsterFullHp, monsterHp = getCreatureMaxHealth(itemEx.uid), getCreatureHealth(itemEx.uid)
        formula = (monsterHp/monsterFullHp)*monsterFullHp
        chanse, bchanse = math.random(1, formula), math.floor(formula)
        if (chanse+breakChanse) >= bchanse then
            s = 0
            for i = 1, #avalibleMonsters do
                if getCreatureName(itemEx.uid) ~= avalibleMonsters[i] then
                    s = s + 1
                end
            end
            if s == #avalibleMonsters then
                sendMessage(cid, abortMessages, messageColor)
                doSendMagicEffect(getCreaturePosition(cid), breakEffect)
                return true
            end
            doItemSetAttribute(item.uid, "description", "It contains a captured ".. getCreatureName(itemEx.uid) ..".")
            doItemSetAttribute(item.uid, "aid", setActionId)
            doRemoveCreature(itemEx.uid)
            sendMessage(cid, successMessages, messageColor)
            doSendMagicEffect(toPosition, successEffect)
        else
            if getCreatureMaster(itemEx.uid) ~= cid then
                doRemoveItem(item.uid, 1)
            end
            doSendMagicEffect(getCreaturePosition(cid), breakEffect)
            sendMessage(cid, failureMessages, messageColor)
        end
    else
        doSendMagicEffect(getCreaturePosition(cid), breakEffect)
    end
    return true
end
function sendMessage(cid, table, color)
    if table[1] == nil then
        return nil
    end
    messageId = math.random(1, #table)
    doCreatureSay(cid, table[messageId], color)
end
function releaseMonster(cid, itemEx, toPosition)
    if itemEx.actionid == setActionId then
        for i = 1, #avalibleMonsters do
            desc = getItemDescriptions(itemEx.uid).special
            local fromS, toS = desc:find(avalibleMonsters[i])
            if toS then
                if toPosition.x ~= CONTAINER_POSITION then
                    if not getTilePzInfo(getThingPos(itemEx.uid)) then
                        monsPar = doCreateMonster(desc:sub(fromS, toS), toPosition)
                        if monsterStatus == "convinced" then
                            doConvinceCreature(cid, monsPar)
                        end
                        doItemSetAttribute(itemEx.uid, "aid", 0)
                        doItemSetAttribute(itemEx.uid, "description", emptyDesc)
                        doSendMagicEffect(getCreaturePosition(monsPar), releaseEffect)
                    else
                        sendMessage(cid, inOnInvalidGround, messageColor)
                        doSendMagicEffect(getCreaturePosition(cid), breakEffect)
                    end
                    return true
                else
                    sendMessage(cid, notOnGroundMessage, messageColor)
                    doSendMagicEffect(getCreaturePosition(cid), breakEffect)
                end
                break
            end
        end
    end
    return false
end
 
I would just create a new monster called "hunting wolf", and summon that creature instead of the one caught by the player.

I remember a thread awhile ago that people were wanting to "name" their summons.
The entire process looked very tedious and slightly buggy.

But if you want to try it,
Basically you'll want to summon the creature in a far off place, rename it there, then teleport it to the target destination.

But, if a player/client has "seen" that particular summon/monster before,
in that it has the same cid as a previously seen monster,
then the name will appear the same as before, for that player/client.
 
I would just create a new monster called "hunting wolf", and summon that creature instead of the one caught by the player.

I remember a thread awhile ago that people were wanting to "name" their summons.
The entire process looked very tedious and slightly buggy.

But if you want to try it,
Basically you'll want to summon the creature in a far off place, rename it there, then teleport it to the target destination.

But, if a player/client has "seen" that particular summon/monster before,
in that it has the same cid as a previously seen monster,
then the name will appear the same as before, for that player/client.
yeah, i0ve thought that, but since the server is kinda low rate RPG, a "hunting Wolf" would be very, very hard to capture as wild. thats why im requesting to add a prefix Hunting [Monster]
 
yeah, i0ve thought that, but since the server is kinda low rate RPG, a "hunting Wolf" would be very, very hard to capture as wild. thats why im requesting to add a prefix Hunting [Monster]
Use item on monster. "Wolf" captured. (wolf.xml)
Use item on ground. "[Hunting] Wolf" | "Hunting [Wolf]" summoned. (hunting_wolf.xml)

It's literally as easy as that.
Tell players the script will summon them a wolf with 'hunting' prefix. Players gasp and awe at your scripting prowess.
Just never tell them that it's a totally different monster, and they won't second guess you.
 
Use item on monster. "Wolf" captured. (wolf.xml)
Use item on ground. "[Hunting] Wolf" | "Hunting [Wolf]" summoned. (hunting_wolf.xml)

It's literally as easy as that.
Tell players the script will summon them a wolf with 'hunting' prefix. Players gasp and awe at your scripting prowess.
Just never tell them that it's a totally different monster, and they won't second guess you.
So, the script should be something like this?
Lua:
monsPar = doCreateMonster(hunting desc:sub(fromS, toS), toPosition)

i've never add a prefix to a variable.
 
Last edited:
I literally do not know how to be more clear.
Someone else will have to help you.
 
Back
Top