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:
let's start by adding a location with:
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:
if we click on teleport we'll be directly teleported to that location which we saved.
let's add some more locations:
in your config you can decide how much locations each player can have 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:
let's delete shop as an example:
I guess this pretty much explained how the system works.
now for the installation
You need to add these tables to your database:
login.lua:
above "return true"
creaturescripts.xml:
in creaturescripts folder:
name it "teleport.lua"
talkactions.xml:
in talkactions folder:
name it "teleport.lua"
global.lua
the config is located in the global.lua
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.
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:
let's start by adding a location with:
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:
if we click on teleport we'll be directly teleported to that location which we saved.
let's add some more locations:
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:
let's delete shop as an example:
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: