• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Issue with using an event to make a replica of rl tibia scarab coin script

tokenzz

:thinking:
Joined
Feb 2, 2013
Messages
778
Solutions
2
Reaction score
345
Hiho,

I've been trying to make an exact replica of real tibia's scarab coin + coal basin = teleport

video:

Skip to 00:32

This is what I'm trying to accomplish. So far, I've made this work:
https://gyazo.com/0d2e356e99efffaeedd4280613caacf2

Source: OTHire (0.3.6/0.3.7/0.4) tfs scripts usually work

Solved by using a different function and make some edits

What I'm looking to accomplish the event (standing in the blue fire + throwing the coin) is something like this event: https://github.com/otland/forgottenserver/blob/master/src/events.cpp (Player:eek:nMoveItem(item, count, fromPosition, toPosition))

However, I don't have it.

Therefore, I'm asking you, got any clue of how I could solve this without using a similar event?

Kind regards,

t0kenz



EDIT:

https://gyazo.com/40bb01f4669cb945c26dc6f346f374f5

This is how it is in real tibia. I assume I've got an idea how I can fix the issue now
 
Last edited:
Assuming you used, or something similar.
<movevent event="AddItem" tileitem="1" actionid="45581" script="test43.lua"/>
function onAddItem(moveitem, tileitem, pos, cid)
 
Assuming you used, or something similar.
<movevent event="AddItem" tileitem="1" actionid="45581" script="test43.lua"/>
function onAddItem(moveitem, tileitem, pos, cid)
Yeah, I figured out I should use this function instead. I'll be changing a few things in the script and if anyone is interested in it, I'll post it in the scripts section.
 
Short follow up on my previous issue. These are the edits I made, but I have encountered another issue now. There are a bunch of "testing code" still used in this script, so don't mind that please ;-)

Code:
--]] Made by t0kenz [[-- 
--]] OTLand username: tokenzz [[--


--    <!-- The Ancients Tombs Quest -->
--    <moveevent event="StepIn" actionid="13002" script="Quests/The Ancient Tombs Quest/helmet.lua"/>
--    <moveevent event="AddItem" tileitem="1" itemid="2159" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6010" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6006" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6008" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6017" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="5999" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6012" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6004" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6014" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>



local config = {
    [1] = { -- Vashresamun
        coalbasin_pos = {x = 33276, y = 32552, z = 14, stackpos = 1},
        playerCheck = {x = 33276, y = 32553, z = 14}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33271, y = 32553, z = 14},
        tile_aid_back = 6010,
        tp_out = {x = 33277, y = 32553, z = 14}
        },
    [2] = { -- Dipthrah
        coalbasin_pos = {x = 33073, y = 32589, z = 13, stackpos = 1},
        playerCheck = {x = 33073, y = 32590, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33079, y = 32589, z = 13},
        tile_aid_back = 6006,
        tp_out = {x = 33072, y = 32590, z = 13}
        },
    [3] = { -- Mahrdis
        coalbasin_pos = {x = 33240, y = 32855, z = 13, stackpos = 1},
        playerCheck = {x = 33073, y = 32590, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33246, y = 32850, z = 13},
        tile_aid_back = 6008,
        tp_out = {x = 33239, y = 32856, z = 13}
        },
    [4] = { -- Morguthis
        coalbasin_pos = {x = 33233, y = 32692, z = 13, stackpos = 1},
        playerCheck = {x = 33234, y = 32692, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33234, y = 32687, z = 13},
        tile_aid_back = 6017,
        tp_out = {x = 33235, y = 32694, z = 13}
        },
    [5] = { -- Omruc
        coalbasin_pos = {x = 33098, y = 32816, z = 13, stackpos = 1},
        playerCheck = {x = 33097, y = 32816, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33093, y = 32824, z = 13},
        tile_aid_back = 5999,
        tp_out = {x = 33097, y = 32815, z = 13}
        },
    [6] = {
        coalbasin_pos = {x = 33135, y = 32682, z = 12, stackpos = 1},
        playerCheck = {x = 33135, y = 32683, z = 12}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33130, y = 32683, z = 12},
        tile_aid_back = 6012,
        tp_out = {x = 33136, y = 32683, z = 12}
        },
    [7] = {
        coalbasin_pos = {x = 33293, y = 32741, z = 13, stackpos = 1},
        playerCheck = {x = 33293, y = 32742, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33299, y = 32742, z = 13},
        tile_aid_back = 6004,
        tp_out = {x = 33292, y = 32742, z = 13}
        },
    [8] = {
        coalbasin_pos = {x = 33161, y = 32831, z = 10, stackpos = 1},
        playerCheck = {x = 33162, y = 32831, z = 10}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33156, y = 32832, z = 10},
        tile_aid_back = 6014,
        tp_out = {x = 33162, y = 32832, z = 10}
        },     
}





function onAddItem(moveItem, position, cid)
     
    -- If the scarab coin is placed on the coal basin (if going in)
    for i = 1, #config do
        if(getTileItemById(config[i].coalbasin_pos, config[i].scarab_coin).uid > 0) then -- check if there is a scarab coin placed on the coal basin in the tomb
            if moveItem.itemid == 2159 and isPlayer(config[i].playerCheck) then
                doRemoveItem(getThingFromPos(config[i].coalbasin_pos).uid, 1)
                doTeleportThing(cid, config[i].tp_in)
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
                doSendMagicEffect(position, CONST_ME_TELEPORT)
                doSendMagicEffect(config[i].coalbasin_pos, CONST_ME_HITBYFIRE)
                break
            end
        end
        return true
    end
end



function onStepIn(cid, item, position, fromPosition) 
     if not isPlayer(cid) then
         return true
     end
    -- if going out 
    for i = 1, #config do
        if item.actionid == config[i].tile_aid_back then
            doTeleportThing(cid, config[i].tp_out)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            doSendMagicEffect(position, CONST_ME_TELEPORT)
            break
        end
    end
    return true
end

Pretty sure that the issue is " if(getTileItemById(config.coalbasin_pos, config.scarab_coin).uid > 0) then -- check if there is a scarab coin placed on the coal basin in the tomb"

However, I receive no errors in console while calling this function but it simply doesn't work. Any clue?

Kind regards,

t0kenz
 
Again, Use the stack position modifier you had previously, or change the stackpos to check correctly. 0 = floor, 1 = coal basin
Tried it in vashresamun, no difference. Or did I simply misunderstand you?
Code:
--]] Made by t0kenz [[--
--]] OTLand username: tokenzz [[--


--    <!-- The Ancients Tombs Quest -->
--    <moveevent event="StepIn" actionid="13002" script="Quests/The Ancient Tombs Quest/helmet.lua"/>
--    <moveevent event="AddItem" tileitem="1" itemid="2159" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6010" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6006" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6008" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6017" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="5999" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6012" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6004" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>
--    <moveevent event="StepIn" actionid="6014" script="Quests/The Ancient Tombs Quest/coalbasin_onadditem.lua"/>



local config = {
    [1] = { -- Vashresamun
        coalbasin_pos = {x = 33276, y = 32552, z = 14, stackpos = 1},
        playerCheck = {x = 33276, y = 32553, z = 14, stackpos = 0}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33271, y = 32553, z = 14},
        tile_aid_back = 6010,
        tp_out = {x = 33277, y = 32553, z = 14}
        },
    [2] = { -- Dipthrah
        coalbasin_pos = {x = 33073, y = 32589, z = 13, stackpos = 1},
        playerCheck = {x = 33073, y = 32590, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33079, y = 32589, z = 13},
        tile_aid_back = 6006,
        tp_out = {x = 33072, y = 32590, z = 13}
        },
    [3] = { -- Mahrdis
        coalbasin_pos = {x = 33240, y = 32855, z = 13, stackpos = 1},
        playerCheck = {x = 33073, y = 32590, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33246, y = 32850, z = 13},
        tile_aid_back = 6008,
        tp_out = {x = 33239, y = 32856, z = 13}
        },
    [4] = { -- Morguthis
        coalbasin_pos = {x = 33233, y = 32692, z = 13, stackpos = 1},
        playerCheck = {x = 33234, y = 32692, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33234, y = 32687, z = 13},
        tile_aid_back = 6017,
        tp_out = {x = 33235, y = 32694, z = 13}
        },
    [5] = { -- Omruc
        coalbasin_pos = {x = 33098, y = 32816, z = 13, stackpos = 1},
        playerCheck = {x = 33097, y = 32816, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33093, y = 32824, z = 13},
        tile_aid_back = 5999,
        tp_out = {x = 33097, y = 32815, z = 13}
        },
    [6] = {
        coalbasin_pos = {x = 33135, y = 32682, z = 12, stackpos = 1},
        playerCheck = {x = 33135, y = 32683, z = 12}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33130, y = 32683, z = 12},
        tile_aid_back = 6012,
        tp_out = {x = 33136, y = 32683, z = 12}
        },
    [7] = {
        coalbasin_pos = {x = 33293, y = 32741, z = 13, stackpos = 1},
        playerCheck = {x = 33293, y = 32742, z = 13}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33299, y = 32742, z = 13},
        tile_aid_back = 6004,
        tp_out = {x = 33292, y = 32742, z = 13}
        },
    [8] = {
        coalbasin_pos = {x = 33161, y = 32831, z = 10, stackpos = 1},
        playerCheck = {x = 33162, y = 32831, z = 10}, -- Check if player is standing on the tile
        scarab_coin = 2159,
        tp_in = {x = 33156, y = 32832, z = 10},
        tile_aid_back = 6014,
        tp_out = {x = 33162, y = 32832, z = 10}
        },    
}





function onAddItem(moveItem, position, cid)
    
    -- If the scarab coin is placed on the coal basin (if going in)
    for i = 1, #config do
        if(getTileItemById(config[i].coalbasin_pos, config[i].scarab_coin).uid > 0) then -- check if there is a scarab coin placed on the coal basin in the tomb
            if moveItem.itemid == 2159 and isPlayer(config[i].playerCheck) then
                doRemoveItem(getThingFromPos(config[i].coalbasin_pos).uid, 1)
                doTeleportThing(cid, config[i].tp_in)
                doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
                doSendMagicEffect(position, CONST_ME_TELEPORT)
                doSendMagicEffect(config[i].coalbasin_pos, CONST_ME_HITBYFIRE)
                break
            end
        end
        return true
    end
end



function onStepIn(cid, item, position, fromPosition)
     if not isPlayer(cid) then
         return true
     end
    -- if going out
    for i = 1, #config do
        if item.actionid == config[i].tile_aid_back then
            doTeleportThing(cid, config[i].tp_out)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
            doSendMagicEffect(position, CONST_ME_TELEPORT)
            break
        end
    end
    return true
end
 
I can't explain all the issues.. but here is something untested.
Code:
-- <movevent event="AddItem" tileitem="1" actionid="45581" script="test43.lua"/>

local config = {
  [1] = { -- Vashresamun
      basin_tile_aid = 11111,
      playerCheck = {x = 33276, y = 32553, z = 14}, -- Check if player is standing on the tile
      tp_in = {x = 33271, y = 32553, z = 14},
      tile_aid_back = 6010,
      tp_out = {x = 33277, y = 32553, z = 14}
      }
}

--function onAddItem(moveItem, position, cid)
function onAddItem(moveitem, tileitem, pos, cid)

   if moveitem.itemid ~= 2159 then
     return true
   end

   -- If the scarab coin is placed on the coal basin (if going in)
   for i = 1, #config do
     if tileitem.actionid == config[i].basin_tile_aid and isPlayer(getThingFromPos(config[i].playerCheck).uid) then
       doRemoveItem(moveitem.uid)
       doTeleportThing(cid, config[i].tp_in)
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
       doSendMagicEffect(position, CONST_ME_TELEPORT)
       doSendMagicEffect(config[i].coalbasin_pos, CONST_ME_HITBYFIRE)
       break
     end
   end

   return true
end



function onStepIn(cid, item, position, fromPosition)

  if not isPlayer(cid) then
     return true
  end

  -- if going out
  for i = 1, #config do
     if item.actionid == config[i].tile_aid_back then
        doTeleportThing(cid, config[i].tp_out)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doSendMagicEffect(position, CONST_ME_TELEPORT)
        break
     end
  end

  return true
end
 
This is what is causing my problem, tried removing it and it works. However, what could I do to replace this?
Check @Xikini's answer, however you need to add/set stackpos in playercheck to 255 (something he forgot)

Or use isPlayer(getTopCreature(config.playerCheck))
 
Back
Top