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

MoveEvent TFS 1.3 Waypoints

Pox

Advanced OT User
Joined
Apr 28, 2020
Messages
163
Solutions
10
Reaction score
170
waypoints4.gif

Tag is MoveEvent because thats the mainpart of this function

Activate waypoint by stepping on SQM with ActionID.
Opens waypoint window when stepping on activated waypoint

Can config that you require other storagevalues before you can activate, example needs to complete a quest before you can activate certain waypoints.

movements/movements.xml
XML:
<movevent event="StepIn" fromaid="1000" toaid="1004" script="waypoints.lua" />

movements/scripts/waypoints.lua
Lua:
function onStepIn(creature, item, position, fromPosition)
    local waypoint = nil
    for i=1,#waypoints do
        if item.actionid == waypoints[i].actionId then
            waypoint = waypoints[i]
        end
    end
    if creature:getStorageValue(999) == 1 then
        creature:setStorageValue(999,0)
        return true
    end
    if waypoint then
        if waypoint.requireQuest.Check then
            if creature:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                creature:teleportTo(fromPosition)
                creature:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if creature:getStorageValue(waypoint.storage) ~= 1 then
            creature:setStorageValue(waypoint.storage,1)
            creature:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        creature:registerEvent("Waypoints")
        local window = ModalWindow(3000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        for i=1,#waypoints do
            if creature:getStorageValue(waypoints[i].storage) == 1 then
                if waypoints[i].actionId ~= item.actionid then
                    window:addChoice(i, waypoints[i].name)
                end
            end
        end

        window:addButton(105,"Select")
        window:addButton(103,"Cancel")
        window:setDefaultEnterButton(105)
        window:setDefaultEscapeButton(103)
        window:sendToPlayer(creature)

        return true
    end   
    return true
end

creaturescripts/creaturescripts.xml
XML:
<event type="ModalWindow" name="Waypoints" script="waypoints.lua" />

creaturescripts/scripts/waypoints.lua
Lua:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 3000 then
        if buttonId == 105 then
            player:unregisterEvent("Waypoints") 
            player:setStorageValue(999,1)
            player:teleportTo(waypoints[choiceId].position)
            player:getPosition():sendMagicEffect(15)
            return true
        end
    end
end

lib/core/core.lua
Lua:
dofile('data/lib/core/waypoints.lua')

lib/core/waypoints.lua
Lua:
waypoints = {
    [1] = {
        name = "Ahola Forest",
        actionId = 1000,
        storage = "3500",
        position = Position(977, 1064, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [2] = {
        name = "Dragon Nest",
        actionId = 1001,
        storage = "3501",
        position = Position(970, 1060, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [3] = {
        name = "Cyclops Mountain",
        actionId = 1002,
        storage = "3502",
        position = Position(968, 1065, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [4] = {
        name = "Hell Gate",
        actionId = 1003,
        storage = "3503",
        position = Position(983, 1060, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [5] = {
        name = "Demona",
        actionId = 1004,
        storage = "3504",
        position = Position(982, 1069, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    }
}
 
I'm really surprised this thread hasn't gotten more attention. Good job man, works on TFS 1.3+ almost flawlessly.

Randomly I will receive a cmd error "data/movements/scripts/waypoints.lua:8: attempt to call method 'getStorageValue' (a nil value)", not every time just 1/20 transports or so.
 
I'm really surprised this thread hasn't gotten more attention. Good job man, works on TFS 1.3+ almost flawlessly.

Randomly I will receive a cmd error "data/movements/scripts/waypoints.lua:8: attempt to call method 'getStorageValue' (a nil value)", not every time just 1/20 transports or so.

Try with these changes below instead.
line8 is just a "cooldown" so you dont open the waypoint window after teleporting

movements/scripts/waypoints.lua
Lua:
function onStepIn(creature, item, position, fromPosition)
    local waypoint = nil
    for i=1,#waypoints do
        if item.actionid == waypoints[i].actionId then
            waypoint = waypoints[i]
        end
    end
  
    if checkCooldown[creature:getName()] ~= nil then
        if checkCooldown[creature:getName()] > os.time() - 2 then
            return true
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if creature:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                creature:teleportTo(fromPosition)
                creature:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if creature:getStorageValue(waypoint.storage) ~= 1 then
            creature:setStorageValue(waypoint.storage,1)
            creature:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        creature:registerEvent("Waypoints")
        local window = ModalWindow(3000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        for i=1,#waypoints do
            if creature:getStorageValue(waypoints[i].storage) == 1 then
                if waypoints[i].actionId ~= item.actionid then
                    window:addChoice(i, waypoints[i].name)
                end
            end
        end

        window:addButton(105,"Select")
        window:addButton(103,"Cancel")
        window:setDefaultEnterButton(105)
        window:setDefaultEscapeButton(103)
        window:sendToPlayer(creature)

        return true
    end 
    return true
end

creaturescripts/scripts/waypoints.lua
Lua:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if buttonId == 105 then
        player:unregisterEvent("Waypoints") 
        checkCooldown[player:getName()] = os.time()
        player:teleportTo(waypoints[choiceId].position)
        player:getPosition():sendMagicEffect(15)
        return true
    end
end

lib/core/waypoints.lua
Lua:
checkCooldown = {}

waypoints = {
    [1] = {
        name = "Ahola Forest",
        actionId = 1000,
        storage = "3500",
        position = Position(977, 1064, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [2] = {
        name = "Dragon Nest",
        actionId = 1001,
        storage = "3501",
        position = Position(970, 1060, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [3] = {
        name = "Cyclops Mountain",
        actionId = 1002,
        storage = "3502",
        position = Position(968, 1065, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [4] = {
        name = "Hell Gate",
        actionId = 1003,
        storage = "3503",
        position = Position(983, 1060, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    },
    [5] = {
        name = "Demona",
        actionId = 1004,
        storage = "3504",
        position = Position(982, 1069, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
    }
}
 
No more errors! Script works flawlessly! I would say maybe include a message such as "You cannot travel so quickly!", or if you wanted to really make it fancy, could say "You cannot travel so quickly, please wait X seconds."

Also, maybe a cost per travel, such as a golden token or something. That would really elevate the script.
P.S. these are just suggestions, your script is really sweet as it is, and if you don't want to change anything that is fine! Really good script.

movements/scripts/waypoints.lua
line 11 added
Lua:
function onStepIn(creature, item, position, fromPosition)
    local waypoint = nil
    for i=1,#waypoints do
        if item.actionid == waypoints[i].actionId then
            waypoint = waypoints[i]
        end
    end
 
    if checkCooldown[creature:getName()] ~= nil then
        if checkCooldown[creature:getName()] > os.time() - 2 then
        creature:say("You cannot travel so quickly!", TALKTYPE_MONSTER_SAY)
            return true
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if creature:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                creature:teleportTo(fromPosition)
                creature:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
       
        if not creature:isPlayer() then
            return false
        end
        if creature:getStorageValue(waypoint.storage) ~= 1 then
            creature:setStorageValue(waypoint.storage,1)
            creature:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        creature:registerEvent("Waypoints")
        local window = ModalWindow(3000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        for i=1,#waypoints do
            if creature:getStorageValue(waypoints[i].storage) == 1 then
                if waypoints[i].actionId ~= item.actionid then
                    window:addChoice(i, waypoints[i].name)
                end
            end
        end

        window:addButton(105,"Select")
        window:addButton(103,"Cancel")
        window:setDefaultEnterButton(105)
        window:setDefaultEscapeButton(103)
        window:sendToPlayer(creature)

        return true
    end
    return true
end
EDIT: There was an error that populates whenever an NPC or monster walks on tile, fixed by adding at line 25:
Lua:
 if not creature:isPlayer() then
            return false
        end
 
Last edited:
No more errors! Script works flawlessly! I would say maybe include a message such as "You cannot travel so quickly!", or if you wanted to really make it fancy, could say "You cannot travel so quickly, please wait X seconds."

Also, maybe a cost per travel, such as a golden token or something. That would really elevate the script.
P.S. these are just suggestions, your script is really sweet as it is, and if you don't want to change anything that is fine! Really good script.

movements/scripts/waypoints.lua
line 11 added
Lua:
function onStepIn(creature, item, position, fromPosition)
    local waypoint = nil
    for i=1,#waypoints do
        if item.actionid == waypoints[i].actionId then
            waypoint = waypoints[i]
        end
    end

    if checkCooldown[creature:getName()] ~= nil then
        if checkCooldown[creature:getName()] > os.time() - 2 then
        creature:say("You cannot travel so quickly!", TALKTYPE_MONSTER_SAY)
            return true
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if creature:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                creature:teleportTo(fromPosition)
                creature:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
      
        if not creature:isPlayer() then
            return false
        end
        if creature:getStorageValue(waypoint.storage) ~= 1 then
            creature:setStorageValue(waypoint.storage,1)
            creature:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        creature:registerEvent("Waypoints")
        local window = ModalWindow(3000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        for i=1,#waypoints do
            if creature:getStorageValue(waypoints[i].storage) == 1 then
                if waypoints[i].actionId ~= item.actionid then
                    window:addChoice(i, waypoints[i].name)
                end
            end
        end

        window:addButton(105,"Select")
        window:addButton(103,"Cancel")
        window:setDefaultEnterButton(105)
        window:setDefaultEscapeButton(103)
        window:sendToPlayer(creature)

        return true
    end
    return true
end
EDIT: There was an error that populates whenever an NPC or monster walks on tile, fixed by adding at line 25:
Lua:
 if not creature:isPlayer() then
            return false
        end

I didnt add text because for the cooldown because it would show up right after traveling, the player check was smart, I totally missed that missed that

Change creaturescripts/scripts/waypoints.lua to this:
Lua:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if buttonId == 105 then
        player:unregisterEvent("Waypoints")
        
        if waypoints[choiceId].cost.check then
            if not player:removeItem(waypoints[choiceId].cost.itemId,waypoints[choiceId].cost.amount) then
                player:say("You cant afford to travel to ".. waypoints[choiceId].name ..".",TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        
        checkCooldown[player:getName()] = os.time()
        player:teleportTo(waypoints[choiceId].position)
        player:getPosition():sendMagicEffect(15)
        return true
    end
end

And lib/core/waypoints.lua to this:
You can now set cost per waypoint

Lua:
checkCooldown = {}

waypoints = {
    [1] = {
        name = "Ahola Forest",
        actionId = 1000,
        storage = "3500",
        position = Position(977, 1064, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = true, itemId = ITEMID, amount = 1}
    }
}
 
I'm really surprised this thread hasn't gotten more attention. Good job man, works on TFS 1.3+ almost flawlessly.
Because there are scripts like this already made.

This one requires a lot more (unnecessary) work to add and configure new waypoints.
 
There are many systems like that, that work way better, @oen432 's probably being the best one.

We appreciate you for contributing the community and your effort, but check other the community resources next time, maybe your time could be spent in something better!

Anyway, as said, Thank you!
 
Ah i thought I saw this script somewhere else, I think they both function basically the same right? Good job to both of you!
 
Because there are scripts like this already made.

This one requires a lot more (unnecessary) work to add and configure new waypoints.

There are many systems like that, that work way better, @oen432 's probably being the best one.

We appreciate you for contributing the community and your effort, but check other the community resources next time, maybe your time could be spent in something better!

Anyway, as said, Thank you!

Just because I dislike unecessary comments like this "a lot more work" - Yeah copy paste lines in a different file than your script, but sure it requires more files, which kinda sucks...
"that work way better" - Mmmh, mine as more flexibility tho, just that it at the moment require more files which kinda sucks..

So I moved everything to revscript instead, now just one file for everything!
And instead of different actionid and storage, the storage is the same as actionid.

data/scripts/waypoints.lua
Lua:
local waypointList = {
    [1] = {
        name = "Ahola Forest",
        actionId = 2000,
        position = Position(1045, 1132, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    },
    [2] = {
        name = "Ahola Forest2",
        actionId = 2001,
        position = Position(1050, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = true, itemId = 16101, amount = 1}
    },
    [3] = {
        name = "Ahola Forest3",
        actionId = 2003,
        position = Position(1041, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    }
}

local cooldowns = {}

local waypoints = MoveEvent()
function waypoints.onStepIn(player,item,position,fromPosition)
    if not player:isPlayer() then
        return false
    end
        if cooldowns[player:getName()] ~= nil then
            if cooldowns[player:getName()] > os.time() - 2 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. cooldowns[player:getName()] - (os.time() - 2) .."seconds before traveling again.")
                    return false
            end
        end
    local waypoint = false

    for i=1,#waypointList do
        if waypointList[i].actionId == item.actionid then
            waypoint = waypointList[i]
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if player:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                player:teleportTo(fromPosition)
                player:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if player:getStorageValue(waypoint.actionId) ~= 1 then
            player:setStorageValue(waypoint.actionId,1)
            player:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        player:registerEvent("revWaypoints")
        local window = ModalWindow(5000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        local unlockedWps = 0

        for i=1,#waypointList do
            if player:getStorageValue(waypointList[i].actionId) == 1 then
                if waypointList[i].actionId ~= item.actionid then
                    unlockedWps = unlockedWps+1
                    window:addChoice(i, waypointList[i].name)
                end
            end
        end

        window:addButton(110,"Select")
        window:addButton(111,"Cancel")
        window:setDefaultEnterButton(110)
        window:setDefaultEscapeButton(111)
        if unlockedWps ~= 0 then
            window:sendToPlayer(player)
        end
      
        return true
    end
end

for j=1,#waypointList do
    waypoints:aid(waypointList[j].actionId)
end

waypoints:type("stepin")
waypoints:register()

local wpWindow = CreatureEvent("revWaypoints")
wpWindow:type("modalwindow")

function wpWindow.onModalWindow(player,modalWindowId,buttonId,choiceId)
    if modalWindowId == 5000 then
        if buttonId == 110 then
            local travel = true
            if waypointList[choiceId].cost.check then
                        if not player:removeItem(waypointList[choiceId].cost.itemId,waypointList[choiceId].cost.amount) then
                                    travel = false
                                    print("test")
                        end
            end
            if travel then
                cooldowns[player:getName()] = os.time()
                player:unregisterEvent("revWaypoints")
                player:teleportTo(waypointList[choiceId].position)
                player:getPosition():sendMagicEffect(15)
            else
                player:say("You cant afford to travel to ".. waypointList[choiceId].name ..".",TALKTYPE_MONSTER_SAY)
            end
          
            return true
        end
    end
end

wpWindow:register()
 
Last edited:
Mmmh, mine as more flexibility tho
People didn't ask for more options like cost or quests so I didn't even think about making them, it's nice that you did.

And instead of different actionid and storage, the storage is the same as actionid.
Stop with multiple action ids. Use only one, tile position should be all that you need to determine which waypoint it is. Mappers will have less work and it will be way easier to maintain. You don't even have to set storage for each waypoint manually, start at X and based on waypoint index in table, add X+index to get waypoint storage.
 
Just a note for viewers, if you want to have players travel only one way (eg from Thais to demona but not back to Thais) set the cost at demona to be itemID 99999.
 
Last edited:
the only other feature I think would make this script elite, would be a selective showing of waypoints.
for example, when you go to the Thais waypoint tile, it will show Aloha forest
but when you go to Aloha forest waypoint tile, it will NOT show Thais, only Aloha forest 2, 3
and when you go to Aloha forest2, it will only show Aloha forest and Aloha forest 3

More clearly:
Thais -> Aloha forest/Aloha forest 2/Aloha forest 3 ----> user picks Aloha forest
Aloha forest -> Aloha forest 2/Aloha forest 3 ---> user picks Aloha forest 2
Aloha forest 2 -> Aloha forest/Aloha forest 3

I hope that is clear enough. Also to clarify, I do not need this script myself, I just think more people would use it with this feature.
 
the only other feature I think would make this script elite, would be a selective showing of waypoints.
for example, when you go to the Thais waypoint tile, it will show Aloha forest
but when you go to Aloha forest waypoint tile, it will NOT show Thais, only Aloha forest 2, 3
and when you go to Aloha forest2, it will only show Aloha forest and Aloha forest 3

More clearly:
Thais -> Aloha forest/Aloha forest 2/Aloha forest 3 ----> user picks Aloha forest
Aloha forest -> Aloha forest 2/Aloha forest 3 ---> user picks Aloha forest 2
Aloha forest 2 -> Aloha forest/Aloha forest 3

I hope that is clear enough. Also to clarify, I do not need this script myself, I just think more people would use it with this feature.

This feature could be added for sure
 
Just because I dislike unecessary comments like this "a lot more work" - Yeah copy paste lines in a different file than your script, but sure it requires more files, which kinda sucks...
"that work way better" - Mmmh, mine as more flexibility tho, just that it at the moment require more files which kinda sucks..

So I moved everything to revscript instead, now just one file for everything!
And instead of different actionid and storage, the storage is the same as actionid.

data/scripts/waypoints.lua
Lua:
local waypointList = {
    [1] = {
        name = "Ahola Forest",
        actionId = 2000,
        position = Position(1045, 1132, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    },
    [2] = {
        name = "Ahola Forest2",
        actionId = 2001,
        position = Position(1050, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = true, itemId = 16101, amount = 1}
    },
    [3] = {
        name = "Ahola Forest3",
        actionId = 2003,
        position = Position(1041, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    }
}

local cooldowns = {}

local waypoints = MoveEvent()
function waypoints.onStepIn(player,item,position,fromPosition)
    if not player:isPlayer() then
        return false
    end
        if cooldowns[player:getName()] ~= nil then
            if cooldowns[player:getName()] > os.time() - 2 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. cooldowns[player:getName()] - (os.time() - 2) .."seconds before traveling again.")
                    return false
            end
        end
    local waypoint = false

    for i=1,#waypointList do
        if waypointList[i].actionId == item.actionid then
            waypoint = waypointList[i]
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if player:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                player:teleportTo(fromPosition)
                player:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if player:getStorageValue(waypoint.actionId) ~= 1 then
            player:setStorageValue(waypoint.actionId,1)
            player:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        player:registerEvent("revWaypoints")
        local window = ModalWindow(5000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        local unlockedWps = 0

        for i=1,#waypointList do
            if player:getStorageValue(waypointList[i].actionId) == 1 then
                if waypointList[i].actionId ~= item.actionid then
                    unlockedWps = unlockedWps+1
                    window:addChoice(i, waypointList[i].name)
                end
            end
        end

        window:addButton(110,"Select")
        window:addButton(111,"Cancel")
        window:setDefaultEnterButton(110)
        window:setDefaultEscapeButton(111)
        if unlockedWps ~= 0 then
            window:sendToPlayer(player)
        end
     
        return true
    end
end

for j=1,#waypointList do
    waypoints:aid(waypointList[j].actionId)
end

waypoints:type("stepin")
waypoints:register()

local wpWindow = CreatureEvent("revWaypoints")
wpWindow:type("modalwindow")

function wpWindow.onModalWindow(player,modalWindowId,buttonId,choiceId)
    if modalWindowId == 5000 then
        if buttonId == 110 then
            local travel = true
            if waypointList[choiceId].cost.check then
                        if not player:removeItem(waypointList[choiceId].cost.itemId,waypointList[choiceId].cost.amount) then
                                    travel = false
                                    print("test")
                        end
            end
            if travel then
                cooldowns[player:getName()] = os.time()
                player:unregisterEvent("revWaypoints")
                player:teleportTo(waypointList[choiceId].position)
                player:getPosition():sendMagicEffect(15)
            else
                player:say("You cant afford to travel to ".. waypointList[choiceId].name ..".",TALKTYPE_MONSTER_SAY)
            end
         
            return true
        end
    end
end

wpWindow:register()

Is it possible to have this amazing script working with Release OTServBR-Global Stable v1.1.1 · opentibiabr/otservbr-global (https://github.com/opentibiabr/otservbr-global/releases/tag/stable-v1.1.1)
 
sure but you will have to convert it to revscript because otservbr people don't care about users using xml to register scripts anymore
I see so if I wanna make this script,

Check Area = x, x, x > to area = x, x, x if 15 players is in the room otherwise allow players to enter unless Boss is dead
Boss = the boss for room -- if boss dies then >>> Teleporter = gets created upon where boss dies. So no corpses is there from Boss.
^Entering tp thats boss creates upon death = setStorageID TP despawn = time 10 minutes
Max players from "enter" teleport from "entrance tile, tp (actionID)

Like I have to devide it into seperate folders as well?
 
Im not good on this but i tried:

Movements:

Lua:
local waypointTile = MoveEvent()

function waypointTile.onStepIn(creature, item, position, fromPosition)
    local waypoint = nil
    for i=1,#waypoints do
        if item.actionid == waypoints[i].actionId then
            waypoint = waypoints[i]
        end
    end
    if creature:getStorageValue(999) == 1 then
        creature:setStorageValue(999,0)
        return true
    end
    if waypoint then
        if waypoint.requireQuest.Check then
            if creature:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                creature:teleportTo(fromPosition)
                creature:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if creature:getStorageValue(waypoint.storage) ~= 1 then
            creature:setStorageValue(waypoint.storage,1)
            creature:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        creature:registerEvent("Waypoints")
        local window = ModalWindow(3000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        for i=1,#waypoints do
            if creature:getStorageValue(waypoints[i].storage) == 1 then
                if waypoints[i].actionId ~= item.actionid then
                    window:addChoice(i, waypoints[i].name)
                end
            end
        end

        window:addButton(105,"Select")
        window:addButton(103,"Cancel")
        window:setDefaultEnterButton(105)
        window:setDefaultEscapeButton(103)
        window:sendToPlayer(creature)

        return true
    end   
    return true
end

waypointTile:type("stepin")
waypointTile:aid(1000,1001,1002,1003,1004)
waypointTile:register()

creaturescript:

Code:
local wayModal = CreatureEvent ("wayModal")

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 3000 then
        if buttonId == 105 then
            player:unregisterEvent("Waypoints")
            player:setStorageValue(999,1)
            player:teleportTo(waypoints[choiceId].position)
            player:getPosition():sendMagicEffect(15)
            return true
        end
    end
end

wayModal:type("ModalWindow")
wayModal:register()

Lib core and waypoints.lua on lib core the same.

I got an error " Nil Value " on console.
As i think from the creaturescript im not sure on wayModal:type("ModalWindow")
Same as @chrallaz i try on otservbr updated to last version by @EduardoDantas
 
Just because I dislike unecessary comments like this "a lot more work" - Yeah copy paste lines in a different file than your script, but sure it requires more files, which kinda sucks...
"that work way better" - Mmmh, mine as more flexibility tho, just that it at the moment require more files which kinda sucks..

So I moved everything to revscript instead, now just one file for everything!
And instead of different actionid and storage, the storage is the same as actionid.

data/scripts/waypoints.lua
Lua:
local waypointList = {
    [1] = {
        name = "Ahola Forest",
        actionId = 2000,
        position = Position(1045, 1132, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    },
    [2] = {
        name = "Ahola Forest2",
        actionId = 2001,
        position = Position(1050, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = true, itemId = 16101, amount = 1}
    },
    [3] = {
        name = "Ahola Forest3",
        actionId = 2003,
        position = Position(1041, 1128, 7),
        requireQuest = {check = false, storage = 5000, value = 5000},
        cost = {check = false, itemId = 16101, amount = 1}
    }
}

local cooldowns = {}

local waypoints = MoveEvent()
function waypoints.onStepIn(player,item,position,fromPosition)
    if not player:isPlayer() then
        return false
    end
        if cooldowns[player:getName()] ~= nil then
            if cooldowns[player:getName()] > os.time() - 2 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to wait ".. cooldowns[player:getName()] - (os.time() - 2) .."seconds before traveling again.")
                    return false
            end
        end
    local waypoint = false

    for i=1,#waypointList do
        if waypointList[i].actionId == item.actionid then
            waypoint = waypointList[i]
        end
    end

    if waypoint then
        if waypoint.requireQuest.Check then
            if player:getStorageValue(waypoint.requireQuest.storage) < waypoint.requireQuest.value then
                player:teleportTo(fromPosition)
                player:say("You have not completed the prerequisite quest to unlock waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
                return false
            end
        end
        if player:getStorageValue(waypoint.actionId) ~= 1 then
            player:setStorageValue(waypoint.actionId,1)
            player:say("You have unlocked waypoint to ".. waypoint.name ..".", TALKTYPE_MONSTER_SAY)
            return true
        end

        player:registerEvent("revWaypoints")
        local window = ModalWindow(5000, "Waypoints", "Waypoint: " .. waypoint.name .. "\n")

        local unlockedWps = 0

        for i=1,#waypointList do
            if player:getStorageValue(waypointList[i].actionId) == 1 then
                if waypointList[i].actionId ~= item.actionid then
                    unlockedWps = unlockedWps+1
                    window:addChoice(i, waypointList[i].name)
                end
            end
        end

        window:addButton(110,"Select")
        window:addButton(111,"Cancel")
        window:setDefaultEnterButton(110)
        window:setDefaultEscapeButton(111)
        if unlockedWps ~= 0 then
            window:sendToPlayer(player)
        end
     
        return true
    end
end

for j=1,#waypointList do
    waypoints:aid(waypointList[j].actionId)
end

waypoints:type("stepin")
waypoints:register()

local wpWindow = CreatureEvent("revWaypoints")
wpWindow:type("modalwindow")

function wpWindow.onModalWindow(player,modalWindowId,buttonId,choiceId)
    if modalWindowId == 5000 then
        if buttonId == 110 then
            local travel = true
            if waypointList[choiceId].cost.check then
                        if not player:removeItem(waypointList[choiceId].cost.itemId,waypointList[choiceId].cost.amount) then
                                    travel = false
                                    print("test")
                        end
            end
            if travel then
                cooldowns[player:getName()] = os.time()
                player:unregisterEvent("revWaypoints")
                player:teleportTo(waypointList[choiceId].position)
                player:getPosition():sendMagicEffect(15)
            else
                player:say("You cant afford to travel to ".. waypointList[choiceId].name ..".",TALKTYPE_MONSTER_SAY)
            end
         
            return true
        end
    end
end

wpWindow:register()
it doesn't work for me how do i work with revscripts in tfs 1.4?
 
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/waypoints.lua:onModalWindow
data/creaturescripts/scripts/waypoints.lua:6: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/waypoints.lua:6: in function <data/creaturescripts/scripts/waypoints.lua:1>
Hello, can you help me guys?
When i have only 1 waypoint i get this error in the console
When i have 2 waypoints the code works normally. 0 errors.

i use global otx 10.99
 
Back
Top