Hello There, Guest! Login Register


[ Snippet ] Unlimited Map support
#1
Alright guys,
since i want to be a part of this community i decided to release a few snippet's from my script to provide your guys hopefully "usefull" informations and tricks when it comes to a "I want to make a script by myself now" scenario. There are maybe easier or better solutions for the Code on the snippets and since im not a professional lua programmer thats okay for me. You are not forced to use my snippets !

As the most of the scripts here support a limit of 5 Maps that can be traveled i want to show you how i made "Umlimited Map support" for my ExpShare script.

The setup:
Path = {
"Pokecenter Cerulean",
"Cerulean City",
"Route 4",
}
Thats a basic table filled with the MapNames your want to be moved to, you can either set them by your own or let the "users" set them on a configuration file. This table is needed in further progress !

The core functions:


function firstMap()
• This is basicly just a check if you are on the first Map or your Pathtable. Should be self explanatory
function firstMap()
    if getMapName() == Path[1] then
        return true
    else
        return false
    end
end

function lastMap()
• Same as the "firstMap" function this is just a check if your are on the last Map of your Pathtable
function lastMap()
    if getMapName() == Path[#Path] then
        return true
    else
        return false
    end
end

function getCurrentMap()
• This functions checks where you currently at by comparing your current MapName with the ones on the Pathtable, when the MapName on the Pathtable is equal to your current position it return the index value ( 'i' on that case )
function getCurrentMap()
    for i = 1, #Path, 1 do
        if getMapName() == Path[i] then
            return i
        end
    end
end

function moveTo(id)
• This function let your bot finally move, its basicly just a movement based on the Pathtable's index numbers. The desired map still have to be "reachable" from your current position. Its not a pathfind !
function moveTo(id)
    return moveToMap(Path[id])
end

function onPathAction()
• This is our last function for the unlimited map support, its calls the 'moveTo' function until the last map on your Pathtable is reached by calling the 'getCurrentMap()' function and increasing the returning value by 1 or incase you want to go back ( if Pokemon 1 is not longer usable for example ) by decreasing the value by 1
function onPathAction()
    if isPokemonUsable(1) then
        if not lastMap() then
            moveTo(getCurrentMap() + 1)
        else
            -- Do stuff on destination / lastMap
       end
    else
       if not firstMap() then
           moveTo(getCurrentMap() - 1 )
       else
           -- Do stuff on first Map ( healing for example )
       end
   end
end


Congratulations !
You finally can offer the "unlimited Map support" feature on your script, or use it private if you dont want to release it
No support for scripts from other authors or edited scripts ( except config.lua ). If you change something on the "core" and it isnt working anymore then you can fix it by your own.
Feel free to contact me for informations and tips !

 
Reply
#2
hi sir. Can you add exceptions for Maps with multiple portal. Like in Route 2. Tried this from Viridian-Pewter but it says no action execute when in Route 2-Pewter
God Karp Trainer loading... *splash*splash Huh

 
Reply
#3
(2016-09-11, 08:33:39)redskhie hi sir. Can you add exceptions for Maps with multiple portal. Like in Route 2. Tried this from Viridian-Pewter but it says no action execute when in Route 2-Pewter

i expected this to happen, will work on the Map_exceptions today Smile
No support for scripts from other authors or edited scripts ( except config.lua ). If you change something on the "core" and it isnt working anymore then you can fix it by your own.
Feel free to contact me for informations and tips !

 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)