Script Converted - [TFS 1.X] Waypoints like in Diablo

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Waypoints
If you find waypoint tile and step on it, you will unlock access to that waypoint. If you step on a waypoint that you have already unlocked then window with list of all of your unlocked waypoints will show and you will be able to teleport to chosen waypoint.


Installation

  1. Open data/movements/movements.xml.
  2. Add
    XML:
    Código:
    <movevent event="StepIn" actionid="4236" script="waypoints.lua" />
  3. Open data/creaturescripts/creaturescripts.xml.
  4. Add
    XML:
    Código:
    <event type="ModalWindow" name="WaypointsModal" script="modal_windows.lua"/>
  5. Download waypoints.rar from attachment at the bottom of this post.
  6. Copy waypoints.lua to data/movements/scripts/waypoints.lua.
  7. Copy modal_windows.lua to data/creaturescripts/scripts/modal_windows.lua.
Configuration
Every configuration is in - data/movements/scripts/waypoints.lua.
WINDOW_ID - ignore that.
BUTTON_ACCEPT - ignore that.
BUTTON_CLOSE - ignore that.

WAYPOINTS_STORAGE - base storage id, change if already in use (make sure that from WAYPOINTS_STORAGE to WAYPOINTS_STORAGE + Number of waypoints aren't used as a storage for anything else).

WAYPOINTS - list of waypoints available
name - name that will be shown on the list and when waypoint is activated
position - position of that tile on the map, this is where player will be teleported

Changelog
[1.0.0] - 2019-03-22

  • Release version

Credits: Oen432
 

Adjuntos

  • waypoints-1_0_0.rar
    1,4 KB · Visitas: 3

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Convertir el Script en Revscript,

Una vez descargado el waypoints, nos vamos a data/scripts/creaturescripts/others

Archivo: modal_windows.lua

Entonces tendremos:
Código:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
  onWaypointsModal(player, modalWindowId, buttonId, choiceId)
end

Le añadiremos lo siguiente:
Código:
local WindowsMod = CreatureEvent("WindowsMod")

function WindowsMod.onModalWindow(player, modalWindowId, buttonId, choiceId)
  onWaypointsModal(player, modalWindowId, buttonId, choiceId)
end

WindowsMod:register()

Luego para el siguiente archivo nos iremos en data/scripts/movements/others

Archivo: waypoints.lua

Entonces tendremos:
Código:
local WINDOW_ID = 4203
local BUTTON_ACCEPT = 0
local BUTTON_CLOSE = 1

local WAYPOINTS_STORAGE = 41875
local WAYPOINTS = {
  [1] = {
    name = "Start",
    position = Position(1000, 1000, 7)
  },
  [2] = {
    name = "Waypoint 1",
    position = Position(978, 1000, 7)
  },
  [3] = {
    name = "Waypoint 2",
    position = Position(1000, 976, 7)
  },
  [4] = {
    name = "Waypoint 3",
    position = Position(1026, 1000, 7)
  },
  [5] = {
    name = "Waypoint 4",
    position = Position(1000, 1016, 7)
  }
}

function onStepIn(player, item, position, fromPosition)
  if player:isPlayer() and fromPosition:getDistance(position) == 1 then
   
    for i = 1, #WAYPOINTS do
      local waypoint = WAYPOINTS[i]
      if position == waypoint.position and player:getStorageValue(WAYPOINTS_STORAGE + i) ~= 1 then
        player:setStorageValue(WAYPOINTS_STORAGE + i, 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "New waypoint unlocked!\n-- " .. waypoint.name .. " --")
        return true
      end
    end

    local empty = true
    for i = 1, #WAYPOINTS do
      local waypoint = WAYPOINTS[i]
      if position == waypoint.position and player:getStorageValue(WAYPOINTS_STORAGE + i) == 1 then
        empty = false
        break
      end
    end

    if not empty then
      player:registerEvent("WaypointsModal")
     
      local title = "Waypoints"
      local message = "Choose your destination."
     
      local window = ModalWindow(WINDOW_ID, title, message)

      window:addButton(BUTTON_ACCEPT, "Teleport")
      window:addButton(BUTTON_CLOSE, "Close")

      for i = 1, #WAYPOINTS do
        local waypoint = WAYPOINTS[i]
        if player:getStorageValue(WAYPOINTS_STORAGE + i) == 1 then
          window:addChoice(i, waypoint.name)
        end
      end

      window:setDefaultEnterButton(BUTTON_ACCEPT)
      window:setDefaultEscapeButton(BUTTON_CLOSE)

      window:sendToPlayer(player)
    end
  end
    return true
end

function onWaypointsModal(player, modalWindowId, buttonId, choiceId) 
  player:unregisterEvent("WaypointsModal")

  if modalWindowId == WINDOW_ID then
      if buttonId == BUTTON_ACCEPT then
        if player:getStorageValue(WAYPOINTS_STORAGE + choiceId) == 1 then
          player:teleportTo(WAYPOINTS[choiceId].position)
          WAYPOINTS[choiceId].position:sendMagicEffect(CONST_ME_ENERGYAREA)
        end
      end
  end
end

Que remplazaremos por:
Código:
local WINDOW_ID = 4203
local BUTTON_ACCEPT = 0
local BUTTON_CLOSE = 1

local WAYPOINTS_STORAGE = 41875
local WAYPOINTS = {
  [1] = {
    name = "Start",
    position = Position(1000, 1000, 7)
  },
  [2] = {
    name = "Waypoint 1",
    position = Position(978, 1000, 7)
  },
  [3] = {
    name = "Waypoint 2",
    position = Position(1000, 976, 7)
  },
  [4] = {
    name = "Waypoint 3",
    position = Position(1026, 1000, 7)
  },
  [5] = {
    name = "Waypoint 4",
    position = Position(1000, 1016, 7)
  }
}

local TpWay = MoveEvent()

function TpWay.onStepIn(player, item, position, fromPosition)
  if player:isPlayer() and fromPosition:getDistance(position) == 1 then
   
    for i = 1, #WAYPOINTS do
      local waypoint = WAYPOINTS[i]
      if position == waypoint.position and player:getStorageValue(WAYPOINTS_STORAGE + i) ~= 1 then
        player:setStorageValue(WAYPOINTS_STORAGE + i, 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "New waypoint unlocked!\n-- " .. waypoint.name .. " --")
        return true
      end
    end

    local empty = true
    for i = 1, #WAYPOINTS do
      local waypoint = WAYPOINTS[i]
      if position == waypoint.position and player:getStorageValue(WAYPOINTS_STORAGE + i) == 1 then
        empty = false
        break
      end
    end

    if not empty then
      player:registerEvent("WaypointsModal")
     
      local title = "Waypoints"
      local message = "Choose your destination."
     
      local window = ModalWindow(WINDOW_ID, title, message)

      window:addButton(BUTTON_ACCEPT, "Teleport")
      window:addButton(BUTTON_CLOSE, "Close")

      for i = 1, #WAYPOINTS do
        local waypoint = WAYPOINTS[i]
        if player:getStorageValue(WAYPOINTS_STORAGE + i) == 1 then
          window:addChoice(i, waypoint.name)
        end
      end

      window:setDefaultEnterButton(BUTTON_ACCEPT)
      window:setDefaultEscapeButton(BUTTON_CLOSE)

      window:sendToPlayer(player)
    end
  end
    return true
end

function TpWay.onWaypointsModal(player, modalWindowId, buttonId, choiceId) 
  player:unregisterEvent("WaypointsModal")

  if modalWindowId == WINDOW_ID then
      if buttonId == BUTTON_ACCEPT then
        if player:getStorageValue(WAYPOINTS_STORAGE + choiceId) == 1 then
          player:teleportTo(WAYPOINTS[choiceId].position)
          WAYPOINTS[choiceId].position:sendMagicEffect(CONST_ME_ENERGYAREA)
        end
      end
  end
end

TpWay:type("stepin")
TpWay:id(4236)
TpWay:register()


Tendremos así el script convertido en Revscript.
No lo hé podido probar aun, pero en gran mayoría el 98% de los scripts TFS 1.x son compatibles con el TFS 1.3 en Revscript.
 
Arriba