RazorBlade
Retired Snek
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:
So here is everything you need:
Recommended: [TFS 1.x] lib folder in "data" like 0.4
In creaturescripts.xml:
In login.lua, register the event:
In creaturescripts/scripts create fasttravel.lua and enter:
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:
Otherwise, create the script as above and save it in your main "data/" folder, then enter this in global.lua:
In talkactions.xml:
In talkactions/scripts create fasttravel.lua and enter:
Example of stepping onto a tile to discover a location:
Movements.xml:
in movements/scripts, discover.lua:
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:
in actions/scripts/YOUR_FOLDER, create travelmap.lua and enter:
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
Pics or it didn't happen:
Say !travel
Notice there's nothing in the list yet
Go find a location
Go find another for good measure
We have one option for a location.
Expand it to see all the sublocations within it
Select Depot then click Travel or hit "enter" on your keyboard. Oh look! We're at the depot.
"Used" a map with actionid 5004, allowing me to discover some new locations in a far away land
More location options!
Expand Solare. Looks pretty similar because both locations only have two sublocations with the same names for this example.
Travel to the depot, and we find ourselves in a strange new place that we never visited before.
Notice there's nothing in the list yet
Go find a location
Go find another for good measure
We have one option for a location.
Expand it to see all the sublocations within it
Select Depot then click Travel or hit "enter" on your keyboard. Oh look! We're at the depot.
"Used" a map with actionid 5004, allowing me to discover some new locations in a far away land
More location options!
Expand Solare. Looks pretty similar because both locations only have two sublocations with the same names for this example.
Travel to the depot, and we find ourselves in a strange new place that we never visited before.
So here is everything you need:
Recommended: [TFS 1.x] lib folder in "data" like 0.4
In creaturescripts.xml:
Code:
<event type="modalwindow" name="fasttravel_modal" script="fasttravel.lua"/>
Code:
player:registerEvent("fasttravel_modal")
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
player:locationWindowChoice(modalWindowId, buttonId, choiceId)
player:travelWindowChoice(modalWindowId, buttonId, choiceId)
return true
end
Code:
-- config
local modalId = 1001
local choice = nil
tlocations = {
[1] = {name = "Infernus", storage = 37101,
sublocations = {
[1] = {pos = {x = 7000, y = 2000, z = 7}, name = "Temple", storage = 37102},
[2] = {pos = {x = 7031, y = 1955, z = 7}, name = "Depot", storage = 37103},
}
},
[2] = {name = "Solare", storage = 37111,
sublocations = {
[1] = {pos = {x = 2000, y = 4000, z = 7}, name = "Temple", storage = 37112},
[2] = {pos = {x = 2000, y = 4150, z = 7}, name = "Depot", storage = 37113},
}
},
}
sublocations = {
[37102] = 37101,
[37103] = 37101,
[37112] = 37111,
[37113] = 37111
}
function Player:sendLocationWindow()
local window = ModalWindow(modalId, "Fast Travel", "You can fast travel to any of the below locations.")
local choices = 0
for i = 1, #tlocations do
if self:getStorageValue(tlocations[i]["storage"]) == 1 then
window:addChoice(i, tlocations[i]["name"])
choices = choices + 1
end
end
if choices > 0 then
window:addButton(1, "Expand")
window:setDefaultEnterButton(1)
end
window:addButton(2, "Exit")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sendTravelWindow(location)
local window = ModalWindow(modalId + 1, location["name"], "You can fast travel to any of the below locations.")
local choices = 0
for i = 1, #location["sublocations"] do
if self:getStorageValue(location["sublocations"][i]["storage"]) == 1 then
window:addChoice(i, location["sublocations"][i]["name"])
choices = choices + 1
end
end
if choices > 0 then
window:addButton(1, "Travel")
window:setDefaultEnterButton(1)
end
window:addButton(2, "Back")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:locationWindowChoice(windowId, buttonId, choiceId)
if windowId == modalId then
if buttonId == 1 then
choice = choiceId
self:sendTravelWindow(tlocations[choiceId])
return true
end
return false
end
return false
end
function Player:travelWindowChoice(windowId, buttonId, choiceId)
if windowId == modalId + 1 then
if buttonId == 1 then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have arrived at " .. tlocations[choice]["sublocations"][choiceId]["name"] .. " in " .. tlocations[choice]["name"] .. ".")
self:teleportTo(tlocations[choice]["sublocations"][choiceId]["pos"])
self:setDirection(DIRECTION_SOUTH)
return true
elseif buttonId == 2 then
self:sendLocationWindow()
end
return false
end
return false
end
Otherwise, create the script as above and save it in your main "data/" folder, then enter this in global.lua:
Code:
dofile('data/fasttravel.lua')
In talkactions.xml:
Code:
<talkaction words="!travel" script="fasttravel.lua"/>
In talkactions/scripts create fasttravel.lua and enter:
Code:
function onSay(player, words, param)
if getCreatureCondition(player, CONDITION_INFIGHT) == false or getTilePzInfo(player:getPosition()) then
player:sendLocationWindow()
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot fast travel while in combat.")
end
return false
end
Example of stepping onto a tile to discover a location:
Movements.xml:
Code:
<movevent event="StepIn" itemid="7351" script="discover.lua"/>
in movements/scripts, discover.lua:
Code:
function onStepIn(creature, item, position, fromPosition)
local player = Player(creature)
if not Player(player) then
return false
end
if item.actionid > 37100 and item.actionid < 38000 then
local storage = player:getStorageValue(item.actionid)
if storage ~= 1 then
player:setStorageValue(item.actionid, 1)
player:setStorageValue(sublocations[item.actionid], 1)
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"] .. "!")
end
end
return true
end
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:
<action itemid="1956" script="YOUR_FOLDER/travelmap.lua"/>
<action itemid="1957" script="YOUR_FOLDER/travelmap.lua"/>
in actions/scripts/YOUR_FOLDER, create travelmap.lua and enter:
Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local versions = {
[5001] = {storages = {37101, 37102, 37103}},
[5002] = {storages = {37101, 37104}},
[5003] = {storages = {37111, 37112, 37113}},
[5004] = {storages = {37101, 37102, 37103, 37111, 37112, 37113}},
}
local discover = false
local player = Player(cid)
if not Player(player) then
return false
end
if versions[item.actionid] then
for i = 1, #versions[item.actionid]["storages"] do
if player:getStorageValue(versions[item.actionid]["storages"][i]) ~= 1 then
player:setStorageValue(versions[item.actionid]["storages"][i], 1)
discover = true
end
end
if discover then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have discovered new locations that you can travel to!")
end
else
return false
end
return true
end
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: