Hello There, Guest! Login Register


[Lua Function]Simplified Validation on allPokemonName to perform Catch
#1
hi all,
I have scripted a function that simplify the code to verify all the pokemon name in a single line input

Parameter => listPokemon
Type => String
Description => Type in the pokemon name that needed to catch with comma (,) to split each of them

Code :

function catchListedPokemon(listPokemon)
    -- Seperate each PokemonName by comma (,)
    opponentPokemon = getOpponentName()
    for pokemons in string.gmatch(listPokemon, "([^,]+)") do
        if pokemons == opponentPokemon then
            return true
        end
    end
    return false
end

Sample:

catchListedPokemon("Zubat,Geodude,Onix")

Put it under the function of onBattleAction()
Code to Put:

if isWildBattle() and (isOpponentShiny() or catchListedPokemon("Zubat,Geodude,Onix")) then
        if useItem("Ultra Ball") or useItem("Great Ball") or useItem("Pokeball") then
            return
    end
end
 
Reply
#2
Nice function.

But, why a string?
A string is not designed to store data.
You should not store data in a string.

It would be better and faster with a table:

catchListedPokemon({"Zubat", "Geodude", "Onix"})

http://www.lua.org/pil/2.5.html
http://www.lua.org/pil/3.6.html
http://lua-users.org/wiki/TablesTutorial
 
Reply
#3
Noted. Thanks for your advice and i will try to change the code once I'm free >_< ~
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)