Project Zomboid

Project Zomboid

Monkey's Fast Travel With Return
S4ro 25 Jul, 2023 @ 4:28am
BUG
Hey Monkey,hi ty for you mod, can you add a check for the return ticket needs to be in the main inventory, actually you can redeem the return ticket from a container and this is not deleted after teleport. ty
< >
Showing 1-2 of 2 comments
S4ro 3 Aug, 2023 @ 3:16am 
this is the code with the control

require "lua_timers"
require "FTWR_Actions"

FTWR_Context = FTWR_Context or {}

local function splitString(inputString, delimiter)
local result = {} -- The resulting array

-- Loop through the string and find matches for the delimiter
for match in string.gmatch(inputString, "[^" .. delimiter .. "]+") do
table.insert(result, match) -- Add each match to the result array
end

return result
end

FTWR_Context.DoReturn = function(player, item)
print("Returning with ticket " .. item:getDisplayName());
if item:getDisplayName() ~= "Return Ticket" then
local splitResult = splitString(item:getDisplayName(), '#');
local x = splitResult[2]
local y = splitResult[3]
local z = splitResult[4]

getPlayer():getInventory():DoRemoveItem(item)
timer:Simple(11, function()
FTWR.TeleportPlayer(tonumber(x), tonumber(y), tonumber(z), false)
end)

if not timer:Exists("tpReturnDelay") then
timer:Create("tpReturnDelay", 1, 10, function()
if timer:RepsLeft("tpReturnDelay") == 2 then
getPlayer():playEmote("saluteformal")
end
getPlayer():setHaloNote("Teleporting to the return ticket's destination in " ..
timer:RepsLeft("tpReturnDelay"))
print("Teleporting to the return ticket's destination in " .. timer:RepsLeft("tpReturnDelay"))
end)
end
else
getPlayer():setHaloNote("Return Ticket seems to be invalid. Please contact our customer care!");
end
end

FTWR_Context.SetReturnTicketContextMenu = function(player, context, items)
if timer:Exists("tpReturnDelay") then
return;
end

-- If multiple selections = No Display
if #items > 1 then
return;
end

local item = items[1];

if item.items then
item = item.items[1];
end

-- if one of the selected items isn't ReturnTicket = No Display
if item:getFullType() ~= "FTWR.ReturnTicket" then
return;
end

-- Verifica se il ticket di ritorno è nell'inventario principale del giocatore
local mainInventory = getPlayer():getInventory()
if not mainInventory:contains(item) then
return;
end

if item:getDisplayName() == "Return Ticket" then
return;
end

context:addOption(getText("ContextMenu_return_ticket"), playerObj, FTWR_Context.DoReturn, item);
end

Events.OnFillInventoryObjectContextMenu.Add(FTWR_Context.SetReturnTicketContextMenu)
Monkey  [developer] 3 Aug, 2023 @ 7:42am 
Fixed!
< >
Showing 1-2 of 2 comments
Per page: 1530 50