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

Action pokeballs

Clary

New Member
Joined
Mar 7, 2008
Messages
1,007
Reaction score
1
NOTE i didn't make this script, Nahruto did.

As the title says this script is for catch pokemons~

You will need this global functions.

PHP:
_warpzone = 2147483648 -- start storing strings here (THIS IS THE ABSOLUTE MAXIMUM VALUE FOR THIS)
_maxlength = 1024 -- multiply by 3 to get the true length.
 
setPlayerStorageInteger = setPlayerStorageValue
getPlayerStorageInteger = getPlayerStorageValue
 
function setPlayerStorageString(cid, key, value)
    if #value > (_maxlength-1) * 3 - 1 then -- Last word is reserved for 0 termination of the string.
        error("Storage string is too long")
    end
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
 
    local word = 0
    local wordwrap = 0
    local wordcount = 0
    local i = 1
    while i <= #value do
        local byte = string.byte(string.sub(value, i, i))
        word = bit.bor(word, bit.lshift(byte, wordwrap))
        wordwrap = wordwrap + 8
        if wordwrap == 24 then
            --[[
                In the ideal world we would be able to store 4 characters per word,
                however, as the default return value for getPlayerStorageValue is
                -1, we can't use the last bit.
            ]]--
            setPlayerStorageInteger(cid, key + wordcount, word)
            word = 0
            wordwrap = 0
            wordcount = wordcount + 1
        end
        i = i + 1
    end
    -- store the last word
    setPlayerStorageInteger(cid, key + wordcount, word)
end
 
function getPlayerStorageString(cid, key)
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
 
    local wordcount = 0
    local str = ""
    while true do
        if wordcount >= _maxlength then
            break
        end
        local word = getPlayerStorageInteger(cid, key + wordcount)
        if word == -1 then
            -- end of string
            break
        else 
            -- Extract the 3 characters from the value
            byte = bit.band(word, 255)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 65280), 8)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 16711680), 16)
            if byte == 0 then break else str = str .. string.char(byte) end
        end
        wordcount = wordcount + 1
    end
    return str
end

and this

PHP:
function doConvinceSummon(cid, creature, amount, pos)
summonplayerpos = {x=pos.x, y=pos.y, z=pos.z, stackpos=253}
summonplayer = getThingfromPos(summonplayerpos)


    if(summonplayer ~= nil and summonplayer.itemid > 0) then    
        doPlayerSendCancel(cid,"There is not enough room to summon here.")
        ret = 0
    else
        convince = doSummonCreature(creature, pos)
        doConvinceCreature(cid, convince)
        ret = 1
end

        return ret
end


ok now the script

in data/actions/scripts create pokeball.lua
inside put.

PHP:
local notAllowed = {"Ferumbras", "Demon"}
local storage = {
    status = 25650,
    pokeName = 25651
}
local actionid_used = 7510
 
function onUse(cid, item, fromPos, item2, toPos)
    local pokeballStatus = getPlayerStorageValue(cid, storage.status)
    local pokeName = getPlayerStorageString(cid, storage.pokeName)
    pos = getPlayerPosition(cid) pos.stackpos = 0
    if getTilePzInfo(toPos) == 0 and getTilePzInfo(pos) == 0 then
        if pokeballStatus == -1 then
            toPos.stackpos = 253
            local pokeThing = getThingfromPos(toPos)
            if isCreature(pokeThing.uid) == TRUE then
                if isPlayer(pokeThing.uid) == FALSE then
                    local pokename_ = getCreatureName(pokeThing.uid)
                    if item.actionid ~= actionid_used then
                    --    local maxHealth = 400
                    --    local creatureHealth = getCreatureHealth(pokeThing.uid)
                    --    local divNum = (string.len(maxHealth)-1)^2
                    --    local result = math.floor((creatureHealth/divNum)/10)
                    --    local chance = math.random(1, math.random(4, math.random(7, math.max(result, 7))))
                    --    if chance == result then
                            if isInTable(notAllowed, pokename_) == TRUE then
                                doPlayerSendCancel(cid, "You cannot catch this creature")
                            else
                                setPlayerStorageString(cid, storage.pokeName, pokename_)
                                doRemoveCreature(pokeThing.uid)
                                doSendDistanceShoot(fromPos, toPos, 37)
                                setPlayerStorageValue(cid, storage.status, 1)
                                doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                                doSetItemActionId(item.uid, actionid_used)
                            end
                    --    else
                    --        doSendMagicEffect(fromPos, 2)
                    --        doPlayerSendCancel(cid, "The Pokemom Escaped")
                    --    end
                    elseif item.actionid == actionid_used and pokename_  == pokeName then
                        doPlayerSay(cid, pokeName .. " Back!!", TALKTYPE_SAY)
                        doRemoveCreature(pokeThing.uid)
                        doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                        setPlayerStorageValue(cid, storage.status, 1)
                        doSendDistanceShoot(fromPos, toPos, 37)
                    else
                        doSendMagicEffect(fromPos, 2)
                        doPlayerSendCancel(cid, "This pokeball is already used")
                    end
                else
                    doPlayerSendCancel(cid, "You cannot catch this creature")
                end
            else
                doPlayerSendCancel(cid, "Creature not found")
            end
        elseif pokeballStatus == 1 then
            summons = getCreatureSummons(cid)
        --    if #summons >= 2 then
        --        doPlayerSendCancel(cid, "You cannot call more pokemons")
        --    else
                doConvinceSummon(cid, pokeName, 0, toPos)
                doSendDistanceShoot(fromPos, toPos, 37)
                doPlayerSay(cid, pokeName .. " Go!!", TALKTYPE_SAY)
                setPlayerStorageValue(cid, storage.status, -1)
                doSetItemSpecialDescription(item.uid, "it is empty.")
        --    end
        end
    else
        doPlayerSendCancel(cid, "You cannot use pokeballs in protection zone.")
    end
    return 1
end 
 
function isInTable(t, val)
    for _, v in pairs(t) do
        if v == val then
            return TRUE
        end
    end
    return LUA_ERROR
end

FOR TFS
PHP:
local notAllowed = {"Ferumbras", "Demon"}
local storage = {
    status = 15244,
    pokeName = 15212
}
local actionid_used = 7510
 
function onUse(cid, item, fromPos, item2, toPos)
    local pokeballStatus = getPlayerStorageValue(cid, storage.status)
    local pokeName = getPlayerStorageString(cid, storage.pokeName)
    pos = getPlayerPosition(cid) pos.stackpos = 0
    if getTilePzInfo(toPos) == 0 and getTilePzInfo(pos) == 0 then
        if pokeballStatus <= 0 then
            toPos.stackpos = 253
            local pokeThing = getThingfromPos(toPos)
            if isCreature(pokeThing.uid) == TRUE then
                if isPlayer(pokeThing.uid) == FALSE then
                    local pokename_ = getCreatureName(pokeThing.uid)
                    if item.actionid ~= actionid_used then
                    --    local maxHealth = 400
                    --    local creatureHealth = getCreatureHealth(pokeThing.uid)
                    --    local divNum = (string.len(maxHealth)-1)^2
                    --    local result = math.floor((creatureHealth/divNum)/10)
                    --    local chance = math.random(1, math.random(4, math.random(7, math.max(result, 7))))
                    --    if chance == result then
                            if isInTable(notAllowed, pokename_) == TRUE then
                                doPlayerSendCancel(cid, "You cannot catch this creature")
                            else
                                setPlayerStorageString(cid, storage.pokeName, pokename_)
                                doRemoveCreature(pokeThing.uid)
                                doSendDistanceShoot(fromPos, toPos, 37)
                                setPlayerStorageValue(cid, storage.status, 1)
                                doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                                doSetItemActionId(item.uid, actionid_used)
                            end
                    --    else
                    --        doSendMagicEffect(fromPos, 2)
                    --        doPlayerSendCancel(cid, "The Pokemom Escaped")
                    --    end
                    elseif item.actionid == actionid_used and pokename_  == pokeName then
                        doCreatureSay(cid, pokeName .. " Back!!", TALKTYPE_SAY)
                        doRemoveCreature(pokeThing.uid)
                        doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                        setPlayerStorageValue(cid, storage.status, 1)
                        doSendDistanceShoot(fromPos, toPos, 37)
                    else
                        doSendMagicEffect(fromPos, 2)
                        doPlayerSendCancel(cid, "This pokeball is already used")
                    end
                else
                    doPlayerSendCancel(cid, "You cannot catch this creature")
                end
            else
                doPlayerSendCancel(cid, "Creature not found")
            end
        elseif pokeballStatus == 1 then
        --    summons = getCreatureSummons(cid)
        --    if #summons >= 2 then
        --        doPlayerSendCancel(cid, "You cannot call more pokemons")
        --    else
                doConvinceSummon(cid, pokeName, 0, toPos)
                doSendDistanceShoot(fromPos, toPos, 37)
                doCreatureSay(cid, pokeName .. " Go!!", TALKTYPE_SAY)
                setPlayerStorageValue(cid, storage.status, 0)
                doSetItemSpecialDescription(item.uid, "it is empty.")
        --    end
        end
    else
        doPlayerSendCancel(cid, "You cannot use pokeballs in protection zone.")
    end
    return 1
end 
 
function isInTable(t, val)
    for _, v in pairs(t) do
        if v == val then
            return TRUE
        end
    end
    return LUA_ERROR
end

in data/actions/actions.xml add

Code:
<action itemid="xxxx" script="pokeball.lua" allowfaruse="1" blockwalls="1" />

change the xxxx for the id of the item you choose to be the "pokeball", it should be able to be used with crosshair.

there are some pokeballs sprites.

Credits:
-Remere for get/setPlayerStorageString functions.
-Gorgaz for the doConvinceSummon function.
-Nahruto for use his imagination and the script.
 
Last edited:
This version should work ok on TFS.

Code:
local notAllowed = {"Ferumbras", "Demon"}
local storage = {
    status = 15244,
    pokeName = 15212
}
local actionid_used = 7510
 
function onUse(cid, item, fromPos, item2, toPos)
    local pokeballStatus = getPlayerStorageValue(cid, storage.status)
    local pokeName = getPlayerStorageString(cid, storage.pokeName)
    pos = getPlayerPosition(cid) pos.stackpos = 0
    if getTilePzInfo(toPos) == 0 and getTilePzInfo(pos) == 0 then
        if pokeballStatus <= 0 then
            toPos.stackpos = 253
            local pokeThing = getThingfromPos(toPos)
            if isCreature(pokeThing.uid) == TRUE then
                if isPlayer(pokeThing.uid) == FALSE then
                    local pokename_ = getCreatureName(pokeThing.uid)
                    if item.actionid ~= actionid_used then
                    --    local maxHealth = 400
                    --    local creatureHealth = getCreatureHealth(pokeThing.uid)
                    --    local divNum = (string.len(maxHealth)-1)^2
                    --    local result = math.floor((creatureHealth/divNum)/10)
                    --    local chance = math.random(1, math.random(4, math.random(7, math.max(result, 7))))
                    --    if chance == result then
                            if isInTable(notAllowed, pokename_) == TRUE then
                                doPlayerSendCancel(cid, "You cannot catch this creature")
                            else
                                setPlayerStorageString(cid, storage.pokeName, pokename_)
                                doRemoveCreature(pokeThing.uid)
                                doSendDistanceShoot(fromPos, toPos, 37)
                                setPlayerStorageValue(cid, storage.status, 1)
                                doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                                doSetItemActionId(item.uid, actionid_used)
                            end
                    --    else
                    --        doSendMagicEffect(fromPos, 2)
                    --        doPlayerSendCancel(cid, "The Pokemom Escaped")
                    --    end
                    elseif item.actionid == actionid_used and pokename_  == pokeName then
                        doCreatureSay(cid, pokeName .. " Back!!", TALKTYPE_SAY)
                        doRemoveCreature(pokeThing.uid)
                        doSetItemSpecialDescription(item.uid, "it contains a " .. pokename_ .. ".")
                        setPlayerStorageValue(cid, storage.status, 1)
                        doSendDistanceShoot(fromPos, toPos, 37)
                    else
                        doSendMagicEffect(fromPos, 2)
                        doPlayerSendCancel(cid, "This pokeball is already used")
                    end
                else
                    doPlayerSendCancel(cid, "You cannot catch this creature")
                end
            else
                doPlayerSendCancel(cid, "Creature not found")
            end
        elseif pokeballStatus == 1 then
        --    summons = getCreatureSummons(cid)
        --    if #summons >= 2 then
        --        doPlayerSendCancel(cid, "You cannot call more pokemons")
        --    else
                doConvinceSummon(cid, pokeName, 0, toPos)
                doSendDistanceShoot(fromPos, toPos, 37)
                doCreatureSay(cid, pokeName .. " Go!!", TALKTYPE_SAY)
                setPlayerStorageValue(cid, storage.status, 0)
                doSetItemSpecialDescription(item.uid, "it is empty.")
        --    end
        end
    else
        doPlayerSendCancel(cid, "You cannot use pokeballs in protection zone.")
    end
    return 1
end 
 
function isInTable(t, val)
    for _, v in pairs(t) do
        if v == val then
            return TRUE
        end
    end
    return LUA_ERROR
end
 
so with that i'm gona capture only one pokemon? or i can capture more them one and the one i capture will be saved so i can capture more? like the real pokemon? :S
 
Error when i load this im using TFs 3 any1 can fix it?

[10/02/2009 13:47:17] Lua Script Error: [Action Interface]
[10/02/2009 13:47:17] data/actions/scripts/pokeball.lua:eek:nUse

[10/02/2009 13:47:17] data/actions/scripts/pokeball.lua:10: attempt to call global 'getPlayerStorageString' (a nil value)
[10/02/2009 13:47:17] stack traceback:
[10/02/2009 13:47:17] data/actions/scripts/pokeball.lua:10: in function <data/actions/scripts/pokeball.lua:8>
 
Muhaha never mind i editted some stuff in your script now it works on my TFS 3 server Woots
i made it so they can capture a creature then release it in the city or where ever
and the pokeball dissapeares xD its a bit diffrent verion then urs xD
Ty for the script man xD im enjoying it
 
Last edited:
i have wronk in action
PHP:
[14/03/2009 15:16:39] Lua Script Error: [Action Interface] 
[14/03/2009 15:16:39] data/actions/scripts/pokeball.lua:onUse

[14/03/2009 15:16:39] luaDoCreateMonster(). Monster name(268437673) not found

[14/03/2009 15:16:39] Lua Script Error: [Action Interface] 
[14/03/2009 15:16:39] data/actions/scripts/pokeball.lua:onUse

[14/03/2009 15:16:39] luaDoCreateNpc(). Npc name(268437673) not found
 
so the purpose of this script is to capture creatures?? bacause im thinking of making a new vocation "BeastMaster" and if the creatures you capture also fight for you then this is going to be great for that vocation, so if thats the deal then im going to edit the script and use it for that.
 
anyone of you can send me a server with this script tfs pokeball and operating please? I beg you :(
 
really nice script but it doesn't work on my engine (Tibia 8.54 TFS ). The script send me you cannot use pokeballs in protection zone wherever i've been. Anyone can fix it or explain me why it doesn't work?
 
Back
Top