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

Lua converting script from Tfs 1.1 - 1.2

Massiah

mApScripthoSt
Joined
Sep 10, 2008
Messages
38
Reaction score
1
Location
U.S.A
Been a while since I've been around the OT community and alot has changed. But im glad to be back and I'm trying to learn new things. I'm running Tfs 1.2 10.77 and I found an awesome system I would like to use, but its made for Tfs 1.1 and I cant seem to get it to work. Anyone know what I need to do to convert this? I've tried everything I can think of and searched for a long time to no avail! any help would be appreciated!
Here's the system:
https://otland.net/threads/tfs-1-1-...at-for-rpg-servers.230015/page-4#post-2306582

The Error I'm getting:
Code:
 Lua Script Error: [MoveEvents Interface]
data/movements/scripts/catacombs/teleporter.lua:eek:onStepIn
data/movements/scripts/catacombs/teleporter.lua:6: attempt to index local 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/movements/scripts/catacombs/teleporter.lua:6: in function <data/movements/scripts/catacombs/teleporter.lua:3>

and my teleporter.lua
Code:
local choose = {}

function onStepIn(cid, item, position, fromPosition)

local player = Player(cid)
local pos = player:getPosition()

if not player then
return true
end

if getPlayerStorageValue(cid, 6661) == 1 then
return sendCatacombWindow(cid)
end

return true
end
 
Try this:

Code:
local choose = {}

function onStepIn(cid, item, position, fromPosition)
    local player = Player(cid)
    if player then
        if player:getStorageValue(6661) == 1 then
            return sendCatacombWindow(cid)
        end
    return true
end
 
Error removed but the modal window doesn't pop up ;/

The player has that storage 6661 equal 1?

If yes add print("Test") above return sendCatacombWindow(cid) and see if its printing it.

Edit: I've just looked the code, it wont work, it has to be rewritten.

I'm doing it tomorrow. Going to sleep right now; cya.
 
The only major difference from 1.0 to 1.1/1.2 is we no longer use the cid conversion for the most part.
So remove anywhere you see cid in the parameters of an interface, an interface is onUse, onStepIn, etc.. and replace it with player, also remove local player = Player(cid) this line of code is no longer needed.
 
catacombs.lua
Code:
places =
{
[1] = {placeName = "Zenoya Graveyard", placeStorage = 6661, placepos = {x = 443, y = 527, z = 8}},
[2] = {placeName = "Azshara West Catacomb", placeStorage = 6662, placepos = {x = 246, y = 485, z = 8}},
[3] = {placeName = "Azshara North Catacomb", placeStorage = 6663, placepos = {x = 259, y = 401, z = 7}}
}

function getCatacombByName(name)
   for k, v in pairs(places) do
     if v.placeName:lower() == name:lower() then
       return k
     end
   end
   return false
end

function sendCatacombWindow(player)
   CatacombWindow = ModalWindow(1900, "Catacombs Teleporter", "Select place:")

   if CatacombWindow:getId() == 1900 then
     CatacombWindow:addButton(1, "Teleport")
     CatacombWindow:setDefaultEnterButton(1)
     CatacombWindow:addButton(2, "Cancel")
     CatacombWindow:setDefaultEscapeButton(2)

     for i = 1, #places do
       if player:getStorageValue(places[i].placeStorage) == 1 then
         CatacombWindow:addChoice(i, places[i].placeName)
       end
     end   
   end
   CatacombWindow:sendToPlayer(player)
   return true
end
catacomb_window.lua
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)

  local pos = player:getPosition()

  if modalWindowId ~= 1900 then
  return false
  end
 
  if buttonId == 1 then -- Teleport
 
  if player:getStorageValue(places[choiceId].placeStorage) == 1 then
  pos:sendMagicEffect(11)
  player:teleportTo(places[choiceId].placepos)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have succesfully teleported to ' .. places[choiceId].placeName .. '.')
     places[choiceId].placepos:sendMagicEffect(11)
  else
  sendCatacombWindow(player)
  end
 
  elseif buttonId == 255 then
  player:popupFYI("Please use a button.")
  sendCatacombWindow(player)
  end
 
   return true
end
azsharanorth.lua
Code:
local t = {
  pos = {x=259, y=400, z=7},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6663) < 1 then
  player:setStorageValue(6663, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara North Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
azsharawest.lua
Code:
local t = {
  pos = {x=246, y=486, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6662) < 1 then
  player:setStorageValue(6662, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara West Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
teleporter.lua
Code:
local choose = {}

function onStepIn(player, item, position, fromPosition)
  local pos = player:getPosition()

  if not player then
  return true
  end

  if player:getStorageValue(6661) == 1 then
     return sendCatacombWindow(player)
  end
 
  return true
end
zenoyagraveyard.lua
Code:
local t = {
  pos = {x=443, y=526, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6661) < 1 then
  player:setStorageValue(6661, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Zenoya Graveyard.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
 
Last edited:
catacombs.lua
Code:
places =
{
[1] = {placeName = "Zenoya Graveyard", placeStorage = 6661, placepos = {x = 443, y = 527, z = 8}},
[2] = {placeName = "Azshara West Catacomb", placeStorage = 6662, placepos = {x = 246, y = 485, z = 8}},
[3] = {placeName = "Azshara North Catacomb", placeStorage = 6663, placepos = {x = 259, y = 401, z = 7}}
}

function getCatacombByName(name)
   for k, v in pairs(places) do
     if v.placeName:lower() == name:lower() then
       return k
     end
   end
   return false
end

function sendCatacombWindow(player)
   CatacombWindow = ModalWindow(1900, "Catacombs Teleporter", "Select place:")

   if CatacombWindow:getId() == 1900 then
     CatacombWindow:addButton(1, "Teleport")
     CatacombWindow:setDefaultEnterButton(1)
     CatacombWindow:addButton(2, "Cancel")
     CatacombWindow:setDefaultEscapeButton(2)

     for i = 1, #places do
       if player:getStorageValue(places[i].placeStorage) == 1 then
         CatacombWindow:addChoice(i, places[i].placeName)
       end
     end 
   end
   CatacombWindow:sendToPlayer(player)
   return true
end
catacomb_window.lua
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)

  local pos = player:getPosition()

  if modalWindowId ~= 1900 then
  return false
  end

  if buttonId == 1 then -- Teleport

  if player:getStorageValue(places[choiceId].placeStorage) == 1 then
  pos:sendMagicEffect(11)
  player:teleportTo(places[choiceId].placepos)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have succesfully teleported to ' .. places[choiceId].placeName .. '.')
     places[choiceId].placepos:sendMagicEffect(11)
  else
  sendCatacombWindow(player)
  end

  elseif buttonId == 255 then
  player:popupFYI("Please use a button.")
  sendCatacombWindow(player)
  end

   return true
end
azsharanorth.lua
Code:
local t = {
  pos = {x=259, y=400, z=7},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6663) < 1 then
  player:setStorageValue(6663, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara North Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
azsharawest.lua
Code:
local t = {
  pos = {x=246, y=486, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6662) < 1 then
  player:setStorageValue(6662, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara West Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
teleporter.lua
Code:
local choose = {}

function onStepIn(player, item, position, fromPosition)
  local pos = player:getPosition()

  if not player then
  return true
  end

  if player:getStorageValue(6661) == 1 then
     return sendCatacombWindow(player)
  end

  return true
end
zenoyagraveyard.lua
Code:
local t = {
  pos = {x=443, y=526, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6661) < 1 then
  player:setStorageValue(6661, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Zenoya Graveyard.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
catacombs.lua
Code:
places =
{
[1] = {placeName = "Zenoya Graveyard", placeStorage = 6661, placepos = {x = 443, y = 527, z = 8}},
[2] = {placeName = "Azshara West Catacomb", placeStorage = 6662, placepos = {x = 246, y = 485, z = 8}},
[3] = {placeName = "Azshara North Catacomb", placeStorage = 6663, placepos = {x = 259, y = 401, z = 7}}
}

function getCatacombByName(name)
   for k, v in pairs(places) do
     if v.placeName:lower() == name:lower() then
       return k
     end
   end
   return false
end

function sendCatacombWindow(player)
   CatacombWindow = ModalWindow(1900, "Catacombs Teleporter", "Select place:")

   if CatacombWindow:getId() == 1900 then
     CatacombWindow:addButton(1, "Teleport")
     CatacombWindow:setDefaultEnterButton(1)
     CatacombWindow:addButton(2, "Cancel")
     CatacombWindow:setDefaultEscapeButton(2)

     for i = 1, #places do
       if player:getStorageValue(places[i].placeStorage) == 1 then
         CatacombWindow:addChoice(i, places[i].placeName)
       end
     end 
   end
   CatacombWindow:sendToPlayer(player)
   return true
end
catacomb_window.lua
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)

  local pos = player:getPosition()

  if modalWindowId ~= 1900 then
  return false
  end

  if buttonId == 1 then -- Teleport

  if player:getStorageValue(places[choiceId].placeStorage) == 1 then
  pos:sendMagicEffect(11)
  player:teleportTo(places[choiceId].placepos)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have succesfully teleported to ' .. places[choiceId].placeName .. '.')
     places[choiceId].placepos:sendMagicEffect(11)
  else
  sendCatacombWindow(player)
  end

  elseif buttonId == 255 then
  player:popupFYI("Please use a button.")
  sendCatacombWindow(player)
  end

   return true
end
azsharanorth.lua
Code:
local t = {
  pos = {x=259, y=400, z=7},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6663) < 1 then
  player:setStorageValue(6663, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara North Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
azsharawest.lua
Code:
local t = {
  pos = {x=246, y=486, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6662) < 1 then
  player:setStorageValue(6662, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Azshara West Catacomb.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end
teleporter.lua
Code:
local choose = {}

function onStepIn(player, item, position, fromPosition)
  local pos = player:getPosition()

  if not player then
  return true
  end

  if player:getStorageValue(6661) == 1 then
     return sendCatacombWindow(player)
  end

  return true
end
zenoyagraveyard.lua
Code:
local t = {
  pos = {x=443, y=526, z=8},
  effect = CONST_ME_TUTORIALARROW
}

function onStepIn(player, item, position, fromPosition)
  if not player then
  return true
  end

  if player:getStorageValue(6661) < 1 then
  player:setStorageValue(6661, 1)
  player:say('It looks like a teleporter..', TALKTYPE_MONSTER_SAY)
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: Zenoya Graveyard.')
  t.pos:sendMagicEffect(t.effect)
  end
  return true
end

If you don't use Player(player) you need to use player:isPlayer(), cause onStepIn will execute even if it is a monster.

Thats why I used Player(cid). If you use Player(playeruserdata) it will return the playeruserdata, if you use Player(monsteruserdata) it will return nil.

That script is pretty messy, doing a new stepin for each catacomb is not necessary. Thats why I said i'm going to rewrite it.
 
If you don't use Player(player) you need to use player:isPlayer(), cause onStepIn will execute even if it is a monster.

Thats why I used Player(cid). If you use Player(playeruserdata) it will return the playeruserdata, if you use Player(monsteruserdata) it will return nil.

That script is pretty messy, doing a new stepin for each catacomb is not necessary. Thats why I said i'm going to rewrite it.
I just edited the files :)
 
Error removed but the modal window doesn't pop up ;/

Add data\lib\core\catacomb.lua

Code:
Catacomb = {}

function Catacomb:new(name, tilepos, placepos, storage)
    return setmetatable({name=name, tilepos=Position(tilepos), placepos=Position(placepos), storage=storage}, {__index = Catacomb})
end

function Player:setFromPos(pos)
    self:setStorageValue(64213, pos.x)
    self:setStorageValue(64214, pos.y)
    self:setStorageValue(64215, pos.z)
    return true
end

function Player:getFromPos()
    local x, y, z = self:getStorageValue(64213), self:getStorageValue(64214), self:getStorageValue(64215)
    if x > 0 and y > 0 and z > 0 then
        return {x=x, y=y, z=z}
    else
        return false
    end
end

function Player:sendCatacombModalWindow(catacombs)
    local CatacombWindow = ModalWindow(1900, "Catacombs Teleporter", "Select place:")
    local send = false
    CatacombWindow:addButton(1, "Teleport")
    CatacombWindow:setDefaultEnterButton(1)
    CatacombWindow:addButton(2, "Cancel")
    CatacombWindow:setDefaultEscapeButton(2)
    for id, catacomb in ipairs(catacombs) do
        if self:getStorageValue(catacomb.storage) == 1 then
            send = true
            CatacombWindow:addChoice(id, catacomb.name)
        end
    end
    if send then
        return CatacombWindow:sendToPlayer(self)
    else
        return false
    end
end

function getCatacombIdByPos(catacombs, pos)
    for id, catacomb in ipairs(catacombs) do
        if catacomb.tilepos == pos then
            return id
        end
    end
end

-- Catacomb:new(Name, TilePos, CatacombPoss, storageID)
-- TilePos is the position that the player has to step to receive the storage and CatacombPoss is the destination.
CatacombList = {
    [1] = Catacomb:new("Zenoya Graveyard", {x=130, y=423, z=7}, {x=128, y=420, z=7}, 5000),
    [2] = Catacomb:new("Azshara West Catacomb",  {x=132, y=423, z=7}, {x=130, y=420, z=7}, 5001),
    [3] = Catacomb:new("Azshara North Catacomb", {x=134, y=423, z=7}, {x=132, y=420, z=7}, 5002),
}

Edit data\lib\core\core.lua and add this line:
Code:
dofile('data/lib/core/catacomb.lua')

Add data\movements\scripts\catacombs.lua:

Code:
function onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if player then
        player:registerEvent("catacombw")
        local id = getCatacombIdByPos(CatacombList, position)
        if id then
            if player:getStorageValue(CatacombList[id].storage) < 1 then
                player:setStorageValue(CatacombList[id].storage, 1)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have unlocked Catacomb Teleporter: ' .. CatacombList[id].name .. '.')
                position:sendMagicEffect(11)
            end
        else
            player:setFromPos(fromPosition)
            if not player:sendCatacombModalWindow(CatacombList) then
                player:teleportTo(fromPosition, true)
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't use this teleporter.")
            end
        end
    end
end

movements.xml:
Code:
    <movevent event="StepIn" actionid="4614" script="catacombs.lua" />
Obs: Every tile should have the actionid 4614. (The teleporter and the tile that the player steps in to discover the catacomb)

Add data\creaturescripts\scripts\catacombw.lua:

Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    local player = Player(cid)
    if player then
        if modalWindowId == 1900 then
            if buttonId == 1 then
                if player:getStorageValue(CatacombList[choiceId].storage) == 1 then
                    player:teleportTo(CatacombList[choiceId].placepos)
                    CatacombList[choiceId].placepos:sendMagicEffect(11)
                else
                    player:sendCatacombModalWindow(CatacombList)
                end
            elseif buttonId == 2 then
                local frompos = player:getFromPos()
                if frompos then
                    player:teleportTo(frompos, true)
                end
            end
        end
    end
    return true
end

creaturescripts.xml:
Code:
    <event type="ModalWindow" name="catacombw" script="catacombw.lua"/>

Tested here and it's working.
 
Man you guys are awesome! Both systems work great! I went ahead and used @MatheusMkalo version because you can add new catacombs in one script without creating a script for each teleport. You guys showing your dedication gives me inspiration to better myself so I can also contribute to the OT community. Thanks for your time and effort!
 
Back
Top Bottom