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

Solved modal window teleporter creaturescript

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys, i have this teleporter tile made in modalwindow, but everytime a player uses it, it gives me an error in console

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tp.lua:onModalWindow
attempt to index a number value
stack traceback:
        [C]: in ?
        [C]: in function 'teleportTo'
        data/creaturescripts/scripts/tp.lua:24: in function <data/creaturescripts/scripts/tp.lua:1>

can anyone help mefix it? and perhaps if isn't too much add a cancel button? cos when the player steps in the tile, he see the locations, but maybe he regrets using it, and a cancel button is missing for that, altho the error is the most important thing ;C


creaturescript

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
   if modalWindowId == 1001 then
      if buttonId == 1 or buttonId == 29 or buttonId == 0 then
         local pos = 0
         if (choiceId == 1) then
            pos = {x=1000, y=1000, z=7}
         elseif (choiceId == 2) then
            pos = {x=2174, y=515, z=7}
         elseif (choiceId == 3) then
            pos = {x=1589, y=437, z=7}
         elseif (choiceId == 4) then
            pos = {x=800, y=934, z=7}
         elseif (choiceId == 5) then
            pos = {x=3076, y=549, z=6}
         elseif (choiceId == 6) then
            pos = {x=689, y=1247, z=7}
         elseif (choiceId == 7) then
            pos = {x=2028, y=1395, z=4}
         elseif (choiceId == 8) then
            pos = {x=129, y=1256, z=15}
         elseif (choiceId == 9) then
            pos = {x=539, y=1725, z=6}
         end
         player:teleportTo(pos, false)
      end
   end
   return true
end

movement
Code:
local modaldialog = {
   title = "Teleporter",
   message = "A que ciudad quieres ir?",
   buttons = {
      { id = 1, text = "go" },
   },
   buttonEnter = 1,
   buttonEscape = 2,
   choices = {
      { id = 1, text = "garuda" },
      { id = 2, text = "edring" },
      { id = 3, text = "liberty bay" },
      { id = 4, text = "infernum" },
      { id = 5, text = "pofulthorn" },
      { id = 6, text = "azurthis" },
      { id = 7, text = "rathleton" },
      { id = 8, text = "carlin" },
      { id = 9, text = "roshamuul" }
   },
   popup = true
}

function onStepIn(creature, item, position, fromPosition)
   modalWindow = ModalWindow(1001, modaldialog.title, modaldialog.message)
   if modalWindow:getId() == 1001 then
      for _, v in ipairs(modaldialog.buttons) do
              modalWindow:addButton(v.id, v.text)
      end
      for _, v in ipairs(modaldialog.choices) do
                modalWindow:addChoice(v.id, v.text)
      end
      modalWindow:setDefaultEnterButton(modaldialog.buttonEnter)
      modalWindow:setPriority(modaldialog.popup)
      modalWindow:setDefaultEscapeButton(modaldialog.buttonEscape)
   end
   modalWindow:sendToPlayer(creature)
   creature:registerEvent("ModalOffline")
   return true
end
 
maybe one of your choices is undefined and pos isn't being reassigned
try to print(choiceId) and see what id is going unchecked
you should also be using Position(x, y, z), not the old way of doing in 0.x
for example, pos = Position(129, 1256, 15)
 
maybe one of your choices is undefined and pos isn't being reassigned
try to print(choiceId) and see what id is going unchecked
you should also be using Position(x, y, z), not the old way of doing in 0.x
for example, pos = Position(129, 1256, 15)
this error happens to every position :/
do you mean instead of pos = {x=689, y=1247, z=7} i should use Position = {x=689, y=1247, z=7}??
 
i wrote my example already
you're supposed to replace {x = 689, y = 1247, z = 7} with Position(689, 1247, 7)
 
Solution
Back
Top