CreatureEvent [TFS 1.1] Fast Travel To Unlocked Locations, modalwindow

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by RazorBlade, Apr 4, 2015.

  1. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    If you've seen any of my other systems that are released, you'll know they're inspired by Skyrim. So here's another! I decided to play around and make a fast travel system that allows players to instantly teleport to a certain location that they have previously visited.

    Pics or it didn't happen:
    Say !travel
    [​IMG]
    Notice there's nothing in the list yet
    [​IMG]
    Go find a location
    [​IMG]
    Go find another for good measure
    [​IMG]
    We have one option for a location.
    [​IMG]
    Expand it to see all the sublocations within it
    [​IMG]
    Select Depot then click Travel or hit "enter" on your keyboard. Oh look! We're at the depot.
    [​IMG]
    "Used" a map with actionid 5004, allowing me to discover some new locations in a far away land
    [​IMG]
    More location options!
    [​IMG]
    Expand Solare. Looks pretty similar because both locations only have two sublocations with the same names for this example.
    [​IMG]
    Travel to the depot, and we find ourselves in a strange new place that we never visited before.
    [​IMG]

    So here is everything you need:
    Recommended: [TFS 1.x] lib folder in "data" like 0.4
    In creaturescripts.xml:
    Code (Text):
    1.  
    2. <event type="modalwindow" name="fasttravel_modal" script="fasttravel.lua"/>
    3.  
    In login.lua, register the event:
    Code (Text):
    1.  
    2. player:registerEvent("fasttravel_modal")
    3.  
    In creaturescripts/scripts create fasttravel.lua and enter:
    Code (Text):
    1.  
    2. function onModalWindow(player, modalWindowId, buttonId, choiceId)
    3.     player:locationWindowChoice(modalWindowId, buttonId, choiceId)
    4.     player:travelWindowChoice(modalWindowId, buttonId, choiceId)
    5.     return true
    6. end
    7.  
    8.  
    If you use the system by @zbizu [TFS 1.x] lib folder in "data" like 0.4 then just create the script fasttravel.lua in data/lib and enter:
    Code (Text):
    1.  
    2. -- config
    3. local modalId = 1001
    4. local choice = nil
    5. tlocations = {
    6.     [1] = {name = "Infernus", storage = 37101,
    7.         sublocations = {
    8.             [1] = {pos = {x = 7000, y = 2000, z = 7}, name = "Temple", storage = 37102},
    9.             [2] = {pos = {x = 7031, y = 1955, z = 7}, name = "Depot", storage = 37103},
    10.         }
    11.     },
    12.     [2] = {name = "Solare", storage = 37111,
    13.         sublocations = {
    14.             [1] = {pos = {x = 2000, y = 4000, z = 7}, name = "Temple", storage = 37112},
    15.             [2] = {pos = {x = 2000, y = 4150, z = 7}, name = "Depot", storage = 37113},
    16.         }
    17.     },
    18.  
    19. }
    20.  
    21. sublocations = {
    22.     [37102] = 37101,
    23.     [37103] = 37101,
    24.     [37112] = 37111,
    25.     [37113] = 37111
    26. }
    27.  
    28. function Player:sendLocationWindow()
    29.     local window = ModalWindow(modalId, "Fast Travel", "You can fast travel to any of the below locations.")
    30.     local choices = 0
    31.    
    32.     for i = 1, #tlocations do
    33.         if self:getStorageValue(tlocations[i]["storage"]) == 1 then
    34.             window:addChoice(i, tlocations[i]["name"])
    35.             choices = choices + 1
    36.         end
    37.     end
    38.     if choices > 0 then
    39.         window:addButton(1, "Expand")
    40.         window:setDefaultEnterButton(1)
    41.     end
    42.     window:addButton(2, "Exit")
    43.     window:setDefaultEscapeButton(2)
    44.     window:sendToPlayer(self)
    45.     return true
    46. end
    47.  
    48. function Player:sendTravelWindow(location)
    49.     local window = ModalWindow(modalId + 1, location["name"], "You can fast travel to any of the below locations.")
    50.     local choices = 0
    51.     for i = 1, #location["sublocations"] do
    52.         if self:getStorageValue(location["sublocations"][i]["storage"]) == 1 then
    53.             window:addChoice(i, location["sublocations"][i]["name"])
    54.             choices = choices + 1
    55.         end
    56.     end
    57.     if choices > 0 then
    58.         window:addButton(1, "Travel")
    59.         window:setDefaultEnterButton(1)
    60.     end
    61.     window:addButton(2, "Back")
    62.     window:setDefaultEscapeButton(2)
    63.     window:sendToPlayer(self)
    64.     return true
    65. end
    66.  
    67. function Player:locationWindowChoice(windowId, buttonId, choiceId)
    68.     if windowId == modalId then
    69.         if buttonId == 1 then
    70.             choice = choiceId
    71.             self:sendTravelWindow(tlocations[choiceId])
    72.             return true
    73.         end
    74.         return false
    75.     end
    76.     return false
    77. end
    78.  
    79. function Player:travelWindowChoice(windowId, buttonId, choiceId)
    80.     if windowId == modalId + 1 then
    81.         if buttonId == 1 then
    82.             self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have arrived at " .. tlocations[choice]["sublocations"][choiceId]["name"] .. " in " .. tlocations[choice]["name"] .. ".")
    83.             self:teleportTo(tlocations[choice]["sublocations"][choiceId]["pos"])
    84.             self:setDirection(DIRECTION_SOUTH)
    85.             return true
    86.         elseif buttonId == 2 then
    87.             self:sendLocationWindow()
    88.         end
    89.         return false
    90.     end
    91.    
    92.     return false
    93. end
    94.  
    95.  
    96.  
    Otherwise, create the script as above and save it in your main "data/" folder, then enter this in global.lua:
    Code (Text):
    1.  
    2. dofile('data/fasttravel.lua')
    3.  
    In talkactions.xml:
    Code (Text):
    1.  
    2. <talkaction words="!travel" script="fasttravel.lua"/>
    3.  
    In talkactions/scripts create fasttravel.lua and enter:
    Code (Text):
    1.  
    2. function onSay(player, words, param)
    3.     if getCreatureCondition(player, CONDITION_INFIGHT) == false or getTilePzInfo(player:getPosition()) then
    4.         player:sendLocationWindow()
    5.     else
    6.         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot fast travel while in combat.")
    7.     end
    8.     return false
    9. end
    10.  
    Example of stepping onto a tile to discover a location:
    Movements.xml:
    Code (Text):
    1.  
    2. <movevent event="StepIn" itemid="7351" script="discover.lua"/>
    3.  
    in movements/scripts, discover.lua:
    Code (Text):
    1.  
    2. function onStepIn(creature, item, position, fromPosition)
    3.     local player = Player(creature)
    4.     if not Player(player) then
    5.         return false
    6.     end
    7.     if item.actionid > 37100 and item.actionid < 38000 then
    8.         local storage = player:getStorageValue(item.actionid)
    9.         if storage ~= 1 then
    10.             player:setStorageValue(item.actionid, 1)
    11.             player:setStorageValue(sublocations[item.actionid], 1)
    12.             player:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered " .. tlocations[sublocations[item.actionid] - 37100]["sublocations"][item.actionid - 37101]["name"] .." in " .. tlocations[sublocations[item.actionid] - 37100]["name"] .. "!")
    13.         end
    14.     end
    15.    
    16.     return true
    17. end
    18.  
    19.  
    20.  
    I decided to make script so that a player can use a map and based on the actionid of that map, they can automatically discover one or more locations.
    I chose two different maps, but the id of the item does not matter as long as it's set in actions.xml.
    In actions.xml:
    Code (Text):
    1.  
    2. <action itemid="1956" script="YOUR_FOLDER/travelmap.lua"/>
    3. <action itemid="1957" script="YOUR_FOLDER/travelmap.lua"/>
    4.  
    in actions/scripts/YOUR_FOLDER, create travelmap.lua and enter:
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    3.     local versions = {
    4.     [5001] = {storages = {37101, 37102, 37103}},
    5.     [5002] = {storages = {37101, 37104}},
    6.     [5003] = {storages = {37111, 37112, 37113}},
    7.     [5004] = {storages = {37101, 37102, 37103, 37111, 37112, 37113}},
    8.     }
    9.     local discover = false
    10.     local player = Player(cid)
    11.     if not Player(player) then
    12.         return false
    13.     end
    14.     if versions[item.actionid] then
    15.         for i = 1, #versions[item.actionid]["storages"] do
    16.        
    17.             if player:getStorageValue(versions[item.actionid]["storages"][i]) ~= 1 then
    18.                 player:setStorageValue(versions[item.actionid]["storages"][i], 1)
    19.                 discover = true
    20.             end
    21.         end
    22.         if discover then
    23.             player:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered new locations that you can travel to!")
    24.         end
    25.     else
    26.         return false
    27.     end
    28.     return true
    29. end
    30.  
    The actionid (5001-5004 in this case) must be set on the map or other item of your choice, and then you can add storage values to that value in the table. You must include both the location storage and any sublocation storages within that location that you want to use if you want anything to appear in the sublocation list.



    If you have any bugs or questions, post here. I won't answer PMs because if you have a problem, someone else probably does as well and I will only post solutions here so that everyone can see them.

    This was tested on TFS 1.1 Final Release

    EDIT:
    I've adjusted the code in both lib/fastravel.lua and movements/scripts/discover.lua to accommodate the changes to how Unique IDs are handled. This system will now work fully in the final release of TFS 1.1

    If you enjoy this, you should also check out my new action which goes hand-in-hand with this system: [TFS 1.1] Discover skills, quests, locations, spells from books like Skyrim
     
    Last edited: Jul 15, 2015
    HeberPcL, daiver, Codex NG and 5 others like this.
  2. Mariuskens

    Mariuskens Sword Art Online 2D-MMORPG

    Joined:
    Nov 21, 2008
    Messages:
    862
    Likes Received:
    80
    Best Answers:
    0
    AWESOME!
     
    RazorBlade likes this.
  3. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Added a movement script and made some changes to lib/fasttravel.lua
     
  4. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Added a second set of menus so that you can choose a location, like a city, then choose a destination within that city. It requires that you use unique id as well as actionid. Set the actionid the same for any locations in the the city or other overall location, then use uniqueid as the specific location within that city.
     
  5. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Added a description and walkthrough as to how to use and configure the system
     
  6. Colors

    Colors

    Joined:
    Mar 22, 2013
    Messages:
    905
    Likes Received:
    247
    Best Answers:
    0
    You should put some screenshots... There's way too much text haha
     
  7. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    I'll do that when I have a chance. :p I'm very close to my 10000 char limit so I'm gonna have to pastebin some of it I think xD
     
  8. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Added pics and removed some text. Also added a new script to use an item (like a map or book) to discover new locations instantly.
    @Mariuskens @Colors @zbizu
     
  9. Mariuskens

    Mariuskens Sword Art Online 2D-MMORPG

    Joined:
    Nov 21, 2008
    Messages:
    862
    Likes Received:
    80
    Best Answers:
    0
    okay soon i test it im in my server testing first floor
     
    RazorBlade likes this.
  10. zbizu

    zbizu ‌‌Luakami

    Joined:
    Nov 22, 2010
    Messages:
    2,437
    Likes Received:
    1,327
    Best Answers:
    0
    stop tagging me here ffs
    once is enough, if I cared, I'd watch this thread
     
  11. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    So moody :p
     
  12. Mariuskens

    Mariuskens Sword Art Online 2D-MMORPG

    Joined:
    Nov 21, 2008
    Messages:
    862
    Likes Received:
    80
    Best Answers:
    0
    Now better ty
     
  13. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
  14. Fresh

    Fresh Ktoś mi kupi premiuma ?

    Joined:
    Oct 21, 2009
    Messages:
    1,365
    Likes Received:
    74
    Best Answers:
    0
  15. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Congratulations, did you want a medal? I made this without referencing your script or the improved version that zbizu made, because I didn't know they existed when I made it. I made this as an addition to my server and so I decided to share it. Besides, it doesn't even work like yours. Mine is for the purpose of revisiting any old location within cities, spawns, quests, and uses submenus to organize, plus allows the player to teleport from anywhere, not just a selection of pre-determined locations. I based my system on the fast travel system of skyrim. Since my system works very differently from yours, your comment is essentially invalid.
     
    Last edited: Apr 11, 2015
    Sir Knighter likes this.
  16. Sir Knighter

    Sir Knighter ArchLight Developer Premium User

    Joined:
    Jun 29, 2009
    Messages:
    3,403
    Likes Received:
    801
    Best Answers:
    0
    Answered my own question, :) Awesome script
     
    Last edited: Jul 15, 2015
  17. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Yeah, thanks ;D
    To answer the question publicly for anyone else wondering, you can teleport when in PZ even if you have battle still, but outside PZ you must lose battle to use the teleport.


    EDIT:

    In addition, I will be removing the stepIn portion to discover a location as it no longer works in TFS 1.1+. Mark removed the ability to have multiple items with the same unique ID. I will add a workaround shortly.

    Edit2:
    I've removed the stepIn discovery and added a slightly modified version. I've also updated the main script in lib/fasttravel.lua to include the workaround that was needed after unique IDs became actually unique. This release should work 100% on TFS 1.1 final release now.
     
    Last edited: Jul 15, 2015
  18. Extrodus

    Extrodus OTList.net Founder

    Joined:
    Dec 22, 2008
    Messages:
    2,182
    Likes Received:
    264
    Best Answers:
    0
    If anyone wants to make it so when a player steps on a tile the fast travel window comes up, simply create a script in movements called "fast_travel.lua" then add this text to it..

    Code (Text):
    1.  
    2. function onStepIn(player, item, position, fromPosition)
    3.   if item:getUniqueId(13337) then
    4.   player:sendLocationWindow()
    5.   else
    6.   player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot fast travel while in combat.")
    7.   end
    8.   return false
    9. end
    10.  
    movements.xml
    Code (Text):
    1. <movevent event="StepIn" uniqueid="13337" script="travel.lua"/>
    Now in your map editor, simply set a tiles uniqueID to 13337 and test it out!
     
  19. RazorBlade

    RazorBlade Snek

    Joined:
    Nov 7, 2009
    Messages:
    2,007
    Likes Received:
    597
    Best Answers:
    0
    Actionid would be better because TFS 1.1 no longer supports duplicate uid.
     
  20. Extrodus

    Extrodus OTList.net Founder

    Joined:
    Dec 22, 2008
    Messages:
    2,182
    Likes Received:
    264
    Best Answers:
    0
    You could use actionids, its just with this script on the tile I step on, I already have an actionid on it since they are used as "discovery" tiles; so I have to make multiple uids = 13337, 13338, 13339 for it to work.

    EDIT: Actually, thinking about it, we could do
    Code (Text):
    1. if item:getActionId >= 37000 then
    So if the items action id is equal to or greater than 37000 (the main number used for this system) it will bring up the window? I'll try it once I get back home, since it would be much more efficient!

    Edit 2:
    Here we go, I modified the original movements files to keep it more organized and now you no longer need to set anything in the map if you have already added the action id.

    in movements/scripts, discover.lua:
    Code (Text):
    1.  
    2. function onStepIn(player, item, position, fromPosition)
    3.   if item.actionid > 37100 and item.actionid < 38000 then
    4.   local storage = player:getStorageValue(item.actionid)
    5.   if storage ~= 1 then
    6.   player:setStorageValue(item.actionid, 1)
    7.   player:setStorageValue(sublocations[item.actionid], 1)
    8.   player:sendTextMessage(MESSAGE_INFO_DESCR, "You have re-activated a shrine, you're actions will forever be remembered!")
    9.   end
    10.   end
    11.    if item.actionid > 37100 and item.actionid < 38000 or item.actionid > 5000 and item.actionid < 5005 then
    12.        player:sendLocationWindow()
    13.      else
    14.        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot fast travel while in combat.")
    15.   end
    16.  
    17.   return true
    18. end
    19.  
    Edit 3:
    For anyone who wants it, I've slightly modified the script to be mostly based off a movement script.

    Using the 5001-5005 action ids, you will discover multiple locations.
    Using the 37100-38000 action ids, you will discover single locations.
    When stepping on any tile with these actionids, it will trigger the modal window.

    I found this useful for the project I'm working on, it makes the starting of the server much more user friendly.

    Code (Text):
    1.  
    2. function onStepIn(player, item, position, fromPosition)
    3.     -- Config for Discovering Multiple Locations
    4.     local versions = {
    5.     [5001] = {storages = {37101, 37102, 37103, 37104, 37111, 37112}},
    6.     [5002] = {storages = {37101, 37104}},
    7.     [5003] = {storages = {37111, 37112, 37113}},
    8.     [5004] = {storages = {37101, 37102, 37103, 37111, 37112, 37113}},
    9.     }
    10.     local discover = false
    11.    
    12.     -- Discovering Locations using above actionIDs
    13.     if versions[item.actionid] then
    14.         for i = 1, #versions[item.actionid]["storages"] do
    15.        
    16.             if player:getStorageValue(versions[item.actionid]["storages"][i]) ~= 1 then
    17.                 player:setStorageValue(versions[item.actionid]["storages"][i], 1)
    18.                 discover = true
    19.             end
    20.         end
    21.         if discover then
    22.             player:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered new locations that you can travel to!")
    23.         end
    24.     end
    25.    
    26.     -- Activating one location through actionID
    27.     if item.actionid > 37100 and item.actionid < 38000 then
    28.         local storage = player:getStorageValue(item.actionid)
    29.         if storage ~= 1 then
    30.             player:setStorageValue(item.actionid, 1)
    31.             player:setStorageValue(sublocations[item.actionid], 1)
    32.             player:sendTextMessage(MESSAGE_INFO_DESCR, "You have re-activated a shrine, your actions will forever be remembered!")
    33.         end
    34.     end
    35.    
    36.     -- Fast Travel Modal Window
    37.     if item.actionid > 37100 and item.actionid < 38000 or item.actionid > 5000 and item.actionid < 5005 then
    38.             player:sendLocationWindow()
    39.         else
    40.             player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot fast travel while in combat.")
    41.     end
    42. end
    43.  
     
    Last edited: Sep 14, 2015

Share This Page

Loading...