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

Anyone can help me On my event. tfs 1.3

Mr Erimyth

Member
Joined
Apr 8, 2009
Messages
163
Reaction score
11
Location
Brazil
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getStorageValue(configExf.stats) == 1 then
        player:teleportTo(cid, configExf.randpos[math.random(1, #configExf.randpos)])
        position:sendMagicEffect(CONST_ME_TELEPORT)
        destination:sendMagicEffect(CONST_ME_TELEPORT)
    else
        player:teleportTo(configExf.teleportPla)
        position:sendMagicEffect(CONST_ME_TELEPORT)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You need waith event start!.')
end

return true
end

Erroo in console..

Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/eforest/magicTp.lua:onStepIn
attempt to index a number value
stack traceback:
        [C]: in ?
        [C]: in function 'teleportTo'
        data/movements/scripts/eforest/magicTp.lua:12: in function <data/movements/scripts/eforest/magicTp.lua:1>
 
To extend on previous answer:
Since you are calling teleportTo function from the player object, the "cid" reference is already created from the player object. So you don't need to pass it along as a parameter anymore.
 
also gonna note that destination:sendMagicEffect wont work if you dont have a variable called destination
local destination = configExf.randpos[math.random(#configExf.randpos)]
then player:teleportTo(destination)
destination:sendMagicEffect
 
Attempt to index a number value
Line 12 is
Code:
player:teleportTo(configExf.teleportPla)

My guess is that configExf.teleportPla is a number, while player:teleportTo requires an array of 3 position values (X,Y,Z)
 
Attempt to index a number value
Line 12 is
Code:
player:teleportTo(configExf.teleportPla)

My guess is that configExf.teleportPla is a number, while player:teleportTo requires an array of 3 position values (X,Y,Z)
the error is the first one since he has cid there
it only takes 1 main argument and cid is the first there, so it's taken and used as a position
however it's a number, not a position. that's why it's giving the error that there was an attempt to index a number value
if configExf was a number, you'd see the error pop up when it's used here: if player:getStorageValue(configExf.stats) == 1 then
 
the error is the first one since he has cid there
it only takes 1 main argument and cid is the first there, so it's taken and used as a position
however it's a number, not a position. that's why it's giving the error that there was an attempt to index a number value
if configExf was a number, you'd see the error pop up when it's used here: if player:getStorageValue(configExf.stats) == 1 then

in that case the script above is posted incompletely (probably config arrays before the function itself), which gave the wrong line count and got me confused :)
 
@Karain and @Znote and @Static_

Thank you for replying

here is my full scrips... ERROS IN CONSOLE = NOTHING

Talkactions - Here starting event...

Code:
function onSay(player, words, param, channel)
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if(param == '')then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Caso queira abrir o evento, digite: /eforest on")
        return false
    end
    if(param == "on")then
        if(Game.getStorageValue(configExf.stats) >=1)then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "O Enchanted Forest ja esta aberto.")
            return false
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Enchanted Forest Started!")
        doStartExf()
    end
    return false
end

Until here everything is fine, everything works is created a teleport in the correct area with correct actionid.


---------------------------------

Now begin the mistakes. -> When floor in teleport with actionid created, nothing happens

Movements "ENTERTP"
Code:
function onStepIn(creature, item, position, fromPosition)
local arena = configExf.arena
    if(not isPlayer(cid)) then
        return true
    end
 
        if(Game.getStorageValue(configExf.stats) >=1)then
        player:teleportTo(configExf.arena)  
    end
 
    return true
 
end

When I go with GOD using the command. " /gotopos 32256, 31919, 7 "and when flooring in the tiles of the event that should teleport randon, nothing happens

Here Movements of Randon Tiles.

Code:
local destination = configExf.randpos[math.random(#configExf.randpos)]
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getStorageValue(configExf.stats) == 1 then
       player:teleportTo(destination)
       destination:sendMagicEffect
return true
end

HERE IS MY LIB Fron Config Events. Please anyone can help me ?
Code:
configExf = {
     Area_Arena = {{x = 32221, y = 31882, z = 7}, {x = 32269, y = 31928, z = 7}},
    arena = {x = 32256, y = 31919, z = 7},
     teleportPos = {32301, 31896, 6},
    teleportPla = {32301, 31896, 6},
    stats = 201201180701,
    timetostart = 60,
    prize = 6571,
    templepos = {32369,  32241,  7},
    randpos = {{32244, 31909, 7},{32253, 31908, 7},{32258, 31902, 7},{32248, 31897, 7},{32253, 31893, 7},{32261, 31889, 7},{32264, 31887, 7},{32242, 31886, 7},{32231, 31889, 7},{32226, 31893, 7},{32232, 31905, 7},{32235, 31897, 7},{32251, 31913, 7},{32255, 31913, 7},{32259, 31913, 7},{32230, 31905, 7}}
}
local TELEPORT_POSITION = Position(32301, 31896, 6)
local TELEPORT_ACTIONID = 19027
local TELEPORT_ITEMID = 1387


function doStartExf()
    Game.broadcastMessage("Teleport for Enchanted Forest Event was created in Event Room.", MESSAGE_EVENT_ADVANCE)
    local tp = Game.createItem(TELEPORT_ITEMID, 1, TELEPORT_POSITION)
    if not tp then
        error("Nao foi possivel criar o teleport na posicao especificada.")
    end
    tp:setActionId(TELEPORT_ACTIONID)
    setGlobalStorageValue(configExf.stats, 0)
    Game.broadcastMessage("The Exchanted Forest event will start in " .. configExf.timetostart .. " seconds.", MESSAGE_EVENT_ADVANCE)
    addEvent(doInitExf, configExf.timetostart*1000)
    end
 
function doInitExf()

if getGlobalStorageValue(configExf.stats) == 0 then
    Game.broadcastMessage("The Exchanted Forest event is starting...")
    setGlobalStorageValue(configExf.stats, 1)
end

end

function doCloseExf()

setGlobalStorageValue(configExf.stats, -1)
    local tp = Game.removeItem(TELEPORT_ITEMID, 1, TELEPORT_POSITION)
    if not tp then
        error("Nao foi possivel remover o teleport na posicao especificada.")
    end

doCleanExfRoom()
end

function doCleanExfRoom()

    local pos = player:getPosition()

    if pos.z == configExf.Area_Arena[1].z then
        if pos.x >= configExf.Area_Arena[1].x and pos.y >= configExf.Area_Arena[1].y then
            if pos.x <= configExf.Area_Arena[2].x and pos.y <= configExf.Area_Arena[2].y then
            Player(players):teleportTo(Player(players):getTown():getTemplePosition())
                return true
            end
        end
    end
    return false
end

If all this happens the event is already running .... And to end the event is when the player clicks the flag in the center of the map. And he will be the winner and the event will be finalized and all of the event will be teleported to the temple.

Script actions flag.

Code:
function onUse(cid, item)

if getGlobalStorageValue(configExf.stats) == 1 then
    doTeleportThing(cid, configExf.templepos)
    doCloseExf()
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You won The Exchanted Forest event and have found a Master Surprise Bag!")
    doBroadcastMessage(getPlayerName(cid) .. " has won The Exchanted Forest event.")
    doPlayerAddItem(cid, configExf.prize)
else
    doPlayerSendCancel(cid, "Sorry, the event is closed")
end

return true
end
 
Last edited:
@Karain and @Znote and @Static_

Thank you for replying

here is my full scrips... ERROS IN CONSOLE = NOTHING

Talkactions - Here starting event...

Code:
function onSay(player, words, param, channel)
    if not player:getGroup():getAccess() then
        return true
    end
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    if(param == '')then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Caso queira abrir o evento, digite: /eforest on")
        return false
    end
    if(param == "on")then
        if(Game.getStorageValue(configExf.stats) >=1)then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "O Enchanted Forest ja esta aberto.")
            return false
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Enchanted Forest Started!")
        doStartExf()
    end
    return false
end

Until here everything is fine, everything works is created a teleport in the correct area with correct actionid.


---------------------------------

Now begin the mistakes. -> When floor in teleport with actionid created, nothing happens

Movements "ENTERTP"
Code:
function onStepIn(creature, item, position, fromPosition)
local arena = configExf.arena
    if(not isPlayer(cid)) then
        return true
    end
 
        if(Game.getStorageValue(configExf.stats) >=1)then
        player:teleportTo(configExf.arena) 
    end
 
    return true
 
end

When I go with GOD using the command. " /gotopos 32256, 31919, 7 "and when flooring in the tiles of the event that should teleport randon, nothing happens

Here Movements of Randon Tiles.

Code:
local destination = configExf.randpos[math.random(#configExf.randpos)]
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getStorageValue(configExf.stats) == 1 then
       player:teleportTo(destination)
       destination:sendMagicEffect
return true
end

HERE IS MY LIB Fron Config Events. Please anyone can help me ?
Code:
configExf = {
     Area_Arena = {{x = 32221, y = 31882, z = 7}, {x = 32269, y = 31928, z = 7}},
    arena = {x = 32256, y = 31919, z = 7},
     teleportPos = {32301, 31896, 6},
    teleportPla = {32301, 31896, 6},
    stats = 201201180701,
    timetostart = 60,
    prize = 6571,
    templepos = {32369,  32241,  7},
    randpos = {{32244, 31909, 7},{32253, 31908, 7},{32258, 31902, 7},{32248, 31897, 7},{32253, 31893, 7},{32261, 31889, 7},{32264, 31887, 7},{32242, 31886, 7},{32231, 31889, 7},{32226, 31893, 7},{32232, 31905, 7},{32235, 31897, 7},{32251, 31913, 7},{32255, 31913, 7},{32259, 31913, 7},{32230, 31905, 7}}
}
local TELEPORT_POSITION = Position(32301, 31896, 6)
local TELEPORT_ACTIONID = 19027
local TELEPORT_ITEMID = 1387


function doStartExf()
    Game.broadcastMessage("Teleport for Enchanted Forest Event was created in Event Room.", MESSAGE_EVENT_ADVANCE)
    local tp = Game.createItem(TELEPORT_ITEMID, 1, TELEPORT_POSITION)
    if not tp then
        error("Nao foi possivel criar o teleport na posicao especificada.")
    end
    tp:setActionId(TELEPORT_ACTIONID)
    setGlobalStorageValue(configExf.stats, 0)
    Game.broadcastMessage("The Exchanted Forest event will start in " .. configExf.timetostart .. " seconds.", MESSAGE_EVENT_ADVANCE)
    addEvent(doInitExf, configExf.timetostart*1000)
    end
 
function doInitExf()

if getGlobalStorageValue(configExf.stats) == 0 then
    Game.broadcastMessage("The Exchanted Forest event is starting...")
    setGlobalStorageValue(configExf.stats, 1)
end

end

function doCloseExf()

setGlobalStorageValue(configExf.stats, -1)
    local tp = Game.removeItem(TELEPORT_ITEMID, 1, TELEPORT_POSITION)
    if not tp then
        error("Nao foi possivel remover o teleport na posicao especificada.")
    end

doCleanExfRoom()
end

function doCleanExfRoom()

    local pos = player:getPosition()

    if pos.z == configExf.Area_Arena[1].z then
        if pos.x >= configExf.Area_Arena[1].x and pos.y >= configExf.Area_Arena[1].y then
            if pos.x <= configExf.Area_Arena[2].x and pos.y <= configExf.Area_Arena[2].y then
            Player(players):teleportTo(Player(players):getTown():getTemplePosition())
                return true
            end
        end
    end
    return false
end

If all this happens the event is already running .... And to end the event is when the player clicks the flag in the center of the map. And he will be the winner and the event will be finalized and all of the event will be teleported to the temple.

Script actions flag.

Code:
function onUse(cid, item)

if getGlobalStorageValue(configExf.stats) == 1 then
    doTeleportThing(cid, configExf.templepos)
    doCloseExf()
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You won The Exchanted Forest event and have found a Master Surprise Bag!")
    doBroadcastMessage(getPlayerName(cid) .. " has won The Exchanted Forest event.")
    doPlayerAddItem(cid, configExf.prize)
else
    doPlayerSendCancel(cid, "Sorry, the event is closed")
end

return true
end

Since you got meta tag functions in (some of) your scripts, convert all of them to avoid unwanted code to the executed - avoid mixing legacy code with new-gen code.
Try adding prints to your code to see if any parts are executed;
Lua:
print("if statment x is getting checked")
if x then
     print("x is true, if statment is executed")
end

Add that to all if statments (before and after) to see where the code "breaks" returns.
 
my code wasnt meant to be written literally, you still have to complete destination:sendMagicEffect(effecthere) and you should put destination inside the function
otherwise destination will be evaluated only once on script load and it wont be a random position every time
 
Back
Top