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

TalkAction Unique Teleportation System v1 for TFS 1.0 only

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,254
Solutions
27
Reaction score
721
Location
Germany
Hello guys,

has been some time since I released something here.

Today I'm here with a unique teleportation system.
You can go wherever you want on your map (except protection zones / houses) and save the position with it where you are currently standing at.

rather then much writing I'll just show everything with pictures.

You type !teleport to execute it, at first it'll be empty like this:
tp_system_window1.png


let's start by adding a location with:
tp_system_command1.png

it saves the tile you are standing on as the location of the name.
you can name it w/e you want I just used test1 as example
now it looks like this:
tp_system_window2.png

if we click on teleport we'll be directly teleported to that location which we saved.

let's add some more locations:
tp_system_window3.png


in your config you can decide how much locations each player can have at once
Code:
 maxPortPoints = 10 -- in this case he can have 10 at once.

if the player hits his max count of locations but needs to save this new one badly and doesn't use one of his older ones, then he can delete it.

!deleteTeleport then this window pops up:
tp_system_window4.png


let's delete shop as an example:
tp_system_window5.png


I guess this pretty much explained how the system works.
now for the installation

You need to add these tables to your database:
Code:
CREATE TABLE IF NOT EXISTS `player_teleport` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `player_id` int(11) NOT NULL,
  `slot` int(11) NOT NULL,
  `posx` int(11) NOT NULL DEFAULT '0',
  `posy` int(11) NOT NULL DEFAULT '0',
  `posz` int(11) NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL COMMENT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

login.lua:
above "return true"
Code:
player:registerEvent("Teleport")

creaturescripts.xml:
Code:
<event type="modalWindow" name="Teleport" script="teleport.lua"/>

in creaturescripts folder:
name it "teleport.lua"
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
  local player = Player(cid)
  local playerGuid = player:getGuid()
  if modalWindowId == 1 then
  if buttonId == 0x00 then -- Select
  if not teleport.canTeleportWhileInfight and getCreatureCondition(cid, CONDITION_INFIGHT) == false then
  local resultId = db.storeQuery("SELECT `posx`, `posy`, `posz`, `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .. " AND slot = ".. choiceId)
  if resultId ~= false then
  local pos = {x = result.getDataInt(resultId, "posx"), y = result.getDataInt(resultId, "posy"), z = result.getDataInt(resultId, "posz")}
  local portName = result.getDataString(resultId, "name")
  player:teleportTo(pos, true)
  player:sendTextMessage(22, "You have successfully transported yourself to ".. portName ..".")
  Position(player:getPosition()):sendMagicEffect(CONST_ME_TELEPORT)
  end
  result.free(resultId)
  else
  player:sendCancelMessage("You cannot teleport while beeing infight.")
  end
  elseif buttonId == 0x01 then -- Cancel
  return false
  end
  elseif modalWindowId == 2 then
  if buttonId == 0x00 then -- Delete
  local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
  local portName = result.getDataString(slot, "name")
  db.query("DELETE FROM `player_teleport` WHERE `player_id` = " .. playerGuid .. " AND slot = ".. choiceId .."")
  player:sendTextMessage(22, "You have successfully removed ".. portName ..".")
  result.free(slot)
  elseif buttonId == 0x01 then -- Cancel
  return false
  end
  end
  return true
end

talkactions.xml:
Code:
<talkaction words="!teleport" separator=" " script="teleport.lua"/>
<talkaction words="!saveTeleport" separator=" " script="teleport.lua"/>
<talkaction words="!deleteTeleport" separator=" " script="teleport.lua"/>

in talkactions folder:
name it "teleport.lua"
Code:
function onSay(cid, words, param)
   local player = Player(cid)
   if teleport.premiumOnly and player:getPremiumDays() < 1 and player:getGroup():getId() < 4 then
     return player:sendCancelMessage("You need a premium account to use this.")
   end
   if words == "!saveTeleport" then
     if not Tile(player:getPosition()):getHouse() and not getTilePzInfo(player:getPosition()) then
       player:savePortPosition(string.lower(param))
     else
       player:sendCancelMessage("You can't save positions in a house / protection zone")
     end
   elseif words == "!teleport" then
     local modal = ModalWindow(1, "Teleport List", "Choose your destination:")
     playerGuid = player:getGuid()
     local ret = false
     for var = 1, teleport.maxPortPoints do
       local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. var .."")
       if slot ~= false then
         local portName = result.getDataString(slot, "name")
         modal:addChoice(var, "".. portName .."")
         result.free(slot)
         ret = true
       end
     end
     if ret then
       modal:addButton(0x00, "Teleport")
       modal:setDefaultEnterButton(0x00)
     end
     modal:addButton(0x01, "Cancel")
     modal:setDefaultEscapeButton(0x01)
     modal:sendToPlayer(player)
   elseif words == "!deleteTeleport" then
     local modal = ModalWindow(2, "Teleport List", "Choose which to delete:")
     playerGuid = player:getGuid()
     local ret = false
     for var = 1, teleport.maxPortPoints do
       local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. var .."")
       if slot ~= false then
         local portName = result.getDataString(slot, "name")
         modal:addChoice(var, "".. portName .."")
         result.free(slot)
         ret = true
       end
     end
     if ret then
       modal:addButton(0x00, "Delete")
       modal:setDefaultEnterButton(0x00)
     end
  modal:addButton(0x01, "Cancel")
  modal:setDefaultEscapeButton(0x01)
  modal:sendToPlayer(player)
   end
   return false
end

global.lua
Code:
teleport = {
   maxPortPoints = 10,
   canTeleportWhileInfight = false,
   premiumOnly = false
}

function Player.savePortPosition(self, description)
  local playerGuid = self:getGuid()
  local pos = self:getPosition()
  local port = 0

  for i = 1, teleport.maxPortPoints do
  local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. i .."")
  if slot == false then
  port = i
  ret = true
  break
  end
  result.free(slot)
  end

  if ret then
  db.query("INSERT INTO `player_teleport` (`player_id`, `slot`, `posx`, `posy`, `posz`, `name`) VALUES (".. playerGuid ..", ".. port ..", ".. pos.x ..", ".. pos.y ..", ".. pos.z ..", '".. description .."');")
  self:sendTextMessage(22, "You have successfully saved the transportation point. ".. description ..".")
  Position(pos):sendMagicEffect(CONST_ME_MAGIC_BLUE)
  else
  self:sendCancelMessage("You cannot have more then ".. teleport.maxPortPoints .." save points.")
  end
end

the config is located in the global.lua
Code:
teleport = {
   maxPortPoints = 10, -- how much locations can each player have at once.
   canTeleportWhileInfight = false, -- can the player teleport while having pz.
   premiumOnly = false -- should the player just be able to use it if he has premium acc.
}

I'll add more options and stuff from time to time.
If you still have questions or suggestions feel free to post them :)


kind regards, Evil Hero.
 
Last edited:
Thanks for sharing, great work! :)
 
Code:
         local posx = db.storeQuery("SELECT `posx` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
         local posX = result.getDataString(posx, "posx")
         local posy = db.storeQuery("SELECT `posy` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
         local posY = result.getDataString(posy, "posy")
         local posz = db.storeQuery("SELECT `posz` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
         local posZ = result.getDataString(posz, "posz")
         local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
         local portName = result.getDataString(slot, "name")
It's bad way, I recommend you to get position and name in one query instead of four (better optimization, mysql server don't have to operate more queries and send back results)

Here is example:
Code:
  local resultId = db.storeQuery("SELECT `posx`, `posy`, `posz`, `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .. " AND slot = ".. choiceId)
  if resultId ~= false then
    local pos = {x = result.getDataInt(resultId, "posx"), y = result.getDataInt(resultId, "posu"), z = result.getDataInt(resultId, "posz")}
    local portName = result.getDataString(resultId, "name")
    -- put here your magic code

    result.free(resultId)
  end
 
Well I'm not familiar with mysql so I didn't knew how to do it in one query, thanks for showing me, gonna change it :)
 
You should use metatable functions only when releasing a TFS 1.0 script.
 
Last edited:
You should only use metatable functions when releasing a TFS 1.0 only script.
Does it exist in 1.0 (old 0.2) branch? I though db/result metatable was only in 0.3.
 
Does it exist in 1.0 (old 0.2) branch? I though db/result metatable was only in 0.3.
I guess my sentence was a bit messed up, I meant that he should use the new metatable functions for Player's etc and not mix them with old functions like doPlayerSendCancel.
 
I guess my sentence was a bit messed up, I meant that he should use the new metatable functions for Player's etc and not mix them with old functions like doPlayerSendCancel.
just converted it fully now, completly forgot about it, since it was based on a really old script :p
 
It's not working for me, i was getting an errror in my console before i changed y = result.getDataInt(resultId, "posu") to y = result.getDataInt(resultId, "posy") Now no error and my player doesnt teleport.
 
It's not working for me, i was getting an errror in my console before i changed y = result.getDataInt(resultId, "posu") to y = result.getDataInt(resultId, "posy") Now no error and my player doesnt teleport.
I've been re working the script just a few minutes ago, you might want to re copy it, if you still get errors just post them :)
found the error, messed something up while copying it into the post, now it should work @sylvan
 
Last edited:
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'

Thats the errors i get now, not sure what exactly it means.
 
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'
[Warning - Event::checkScript] Can not load script: scripts/teleport.lua
data/talkactions/scripts/teleport.lua:7: 'then' expected near ')'

Thats the errors i get now, not sure what exactly it means.
Code:
function onSay(cid, words, param)
   local player = Player(cid)
   if teleport.premiumOnly and player:getPremiumDays() < 1 and player:getGroup():getId() < 4 then
     return player:sendCancelMessage("You need a premium account to use this.")
   end
   if words == "!saveTeleport" then
     if not Tile(player:getPosition()):getHouse() and not getTilePzInfo(player:getPosition()) then
       player:savePortPosition(string.lower(param))
     else
       player:sendCancelMessage("You can't save positions in a house / protection zone")
     end
   elseif words == "!teleport" then
     local modal = ModalWindow(1, "Teleport List", "Choose your destination:")
     playerGuid = player:getGuid()
     local ret = false
     for var = 1, teleport.maxPortPoints do
       local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. var .."")
       if slot ~= false then
         local portName = result.getDataString(slot, "name")
         modal:addChoice(var, "".. portName .."")
         result.free(slot)
         ret = true
       end
     end
     if ret then
       modal:addButton(0x00, "Teleport")
       modal:setDefaultEnterButton(0x00)
     end
     modal:addButton(0x01, "Cancel")
     modal:setDefaultEscapeButton(0x01)
     modal:sendToPlayer(player)
   elseif words == "!deleteTeleport" then
     local modal = ModalWindow(2, "Teleport List", "Choose which to delete:")
     playerGuid = player:getGuid()
     local ret = false
     for var = 1, teleport.maxPortPoints do
       local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. var .."")
       if slot ~= false then
         local portName = result.getDataString(slot, "name")
         modal:addChoice(var, "".. portName .."")
         result.free(slot)
         ret = true
       end
     end
     if ret then
       modal:addButton(0x00, "Delete")
       modal:setDefaultEnterButton(0x00)
     end
  modal:addButton(0x01, "Cancel")
  modal:setDefaultEscapeButton(0x01)
  modal:sendToPlayer(player)
   end
   return false
end
 
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/teleport.lua:eek:nSay
data/global.lua:454: attempt to call method 'sendMagicEffect' (a nil value)
stack traceback:
[C]: in function 'sendMagicEffect'
data/global.lua:454: in function 'savePortPosition'
data/talkactions/scripts/teleport.lua:8: in function <data/talkactions/scripts/teleport.lua:1>

Thats the error that comes up when i try to teleport, and in the game window says "cant teleport while beeing in fight" and i dont have battle bars.
 
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/teleport.lua:eek:nSay
data/global.lua:454: attempt to call method 'sendMagicEffect' (a nil value)
stack traceback:
[C]: in function 'sendMagicEffect'
data/global.lua:454: in function 'savePortPosition'
data/talkactions/scripts/teleport.lua:8: in function <data/talkactions/scripts/teleport.lua:1>

Thats the error that comes up when i try to teleport, and in the game window says "cant teleport while beeing in fight" and i dont have battle bars.
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
  local player = Player(cid)
  local playerGuid = player:getGuid()
  if modalWindowId == 1 then
  if buttonId == 0x00 then -- Select
  if not teleport.canTeleportWhileInfight and player:getCondition(CONDITION_INFIGHT) == false then
  local resultId = db.storeQuery("SELECT `posx`, `posy`, `posz`, `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .. " AND slot = ".. choiceId)
  if resultId ~= false then
  local pos = {x = result.getDataInt(resultId, "posx"), y = result.getDataInt(resultId, "posy"), z = result.getDataInt(resultId, "posz")}
  local portName = result.getDataString(resultId, "name")
  player:teleportTo(pos, true)
  player:sendTextMessage(22, "You have successfully transported yourself to ".. portName ..".")
  Position(player:getPosition()):sendMagicEffect(CONST_ME_TELEPORT)
  end
  result.free(resultId)
  else
  player:sendCancelMessage("You cannot teleport while beeing infight.")
  end
  elseif buttonId == 0x01 then -- Cancel
  return false
  end
  elseif modalWindowId == 2 then
  if buttonId == 0x00 then -- Delete
  local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. choiceId .."")
  local portName = result.getDataString(slot, "name")
  db.query("DELETE FROM `player_teleport` WHERE `player_id` = " .. playerGuid .. " AND slot = ".. choiceId .."")
  player:sendTextMessage(22, "You have successfully removed ".. portName ..".")
  result.free(slot)
  elseif buttonId == 0x01 then -- Cancel
  return false
  end
  end
  return true
end
Code:
function Player.savePortPosition(self, description)
  local playerGuid = self:getGuid()
  local pos = self:getPosition()
  local port = 0

  for i = 1, teleport.maxPortPoints do
  local slot = db.storeQuery("SELECT `name` FROM `player_teleport` WHERE `player_id` = " .. playerGuid .." AND slot = ".. i .."")
  if slot == false then
  port = i
  ret = true
  break
  end
  result.free(slot)
  end

  if ret then
  db.query("INSERT INTO `player_teleport` (`player_id`, `slot`, `posx`, `posy`, `posz`, `name`) VALUES (".. playerGuid ..", ".. port ..", ".. pos.x ..", ".. pos.y ..", ".. pos.z ..", '".. description .."');")
  self:sendTextMessage(22, "You have successfully saved the transportation point. ".. description ..".")
  Position(pos):sendMagicEffect(CONST_ME_MAGIC_BLUE)
  else
  self:sendCancelMessage("You cannot have more then ".. teleport.maxPortPoints .." save points.")
  end
end
 
Getting no errors in the console, in the game window it says "You cannot teleport while beeing fight" I have tried it with both options same result.
 
Back
Top