• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

RevScripts check 3 storage at same time

T

Tibia Demon

Guest
i try to check all the 3 storage here in same time. it only check 1.
i already add actionid to all grounds = 40490
i use cplayerpos later dont need to remove it.
Lua:
local storagechecker = MoveEvent()
storagechecker:type("stepin")

local actionId = 40490
local Storagetable = {
    [1] = {storage = 20115, cplayerpos = {x = 1011, y = 1012, z = 7}},
    [2] = {storage = 20116, cplayerpos = {x = 1012, y = 1014, z = 7}},
    [3] = {storage = 20117, cplayerpos = {x = 1014, y = 1013, z = 7}}
}

function storagechecker.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
    for _, storages in ipairs(Storagetable) do
        if player:getStorageValue(storages.storage) == 1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "you have got your reward.")
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            player:teleportTo(fromPosition)
            return true
        end
    end
end

storagechecker:aid(actionId)
storagechecker:register()
 
Solution
keeps sending effect CONST_ME_MAGIC_GREEN too fast without stopping or tping player
if questConfig[index].requiredStandingTime > (os.mtime() - tileStandingPlayers[playerId].standingTime) then
I put a 3 second cooldown on the effect.
Lua:
local actionId = 40490

local tileStandingPlayers = {} -- will hold information about the players. [creatureId] = {standingTime = 0, tableIndex = 0}
local kickPosition = Position(1008, 1013, 7)
local questConfig = {
    {storage = 20115, requiredStandingTime = 1000, tilePosition = Position(1011, 1012, 7)}, -- requiredStandingTime is in milliseconds.
    {storage = 20116, requiredStandingTime = 2000, tilePosition = Position(1012, 1014, 7)},
    {storage = 20117, requiredStandingTime = 3000, tilePosition =...
OP
OP
T

Tibia Demon

Guest
Added some prints. Let me know what prints to console.

Lua:
local function tileChecker(playerId, startedTime)
    -- recreate the player, to ensure they still exist
    local player = Player(playerId)
    if not player then
        return
    end
  
    -- check if table has been reset.
    if not tileStandingPlayers[playerId] or startedTime ~= tileStandingPlayers[playerId].standingTime then
        return
    end
  
    -- check if player has left the tile location
    local index = tileStandingPlayers[playerId].tableIndex 
    if questConfig[index].tilePosition ~= player:getPosition() then
        return
    end
  
    -- check if time has elapsed
    print("requiredStandingTime: " .. questConfig[index].requiredStandingTime)
    print("elapsedTime: " .. (os.mtime() - tileStandingPlayers[playerId].standingTime))
    if questConfig[index].requiredStandingTime < (os.mtime() - tileStandingPlayers[playerId].standingTime) then
        -- if not enough time has elapsed, then loop function
        questConfig[index].tilePosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        addEvent(tileChecker, 250, playerId, startedTime)
        return
    end
  
  
    -- enough time has elapsed, so give storage and teleport player off the tile
    player:setStorageValue(questConfig[index].storage, 1)
    questConfig[index].tilePosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(kickPosition)
    kickPosition:sendMagicEffect(CONST_ME_HITAREA)
  
    -- and finally, let's clean up the table.
    tileStandingPlayers[playerId] = nil
  
    -- while we're at it, let's tell the player if they have completed all the tiles
    for v, k in pairs(questConfig) do
        if player:getStorageValue(k.storage) ~= 1 then
            player:say("There's still some more tiles to go!", TALKTYPE_MONSTER_SAY)
            return
        end
    end
    player:say("You've completed all of the tiles!", TALKTYPE_MONSTER_SAY)
end
requiredStandingTime: 10000
elapsedTime: 256
requiredStandingTime: 11000
elapsedTime: 3852 this time my pc freezed
requiredStandingTime: 15000
elapsedTime: 260
Post automatically merged:

one record more
requiredStandingTime: 10000
elapsedTime: 265
requiredStandingTime: 11000
elapsedTime: 252
requiredStandingTime: 15000
elapsedTime: 256
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,304
Solutions
547
Reaction score
4,566
requiredStandingTime: 10000
elapsedTime: 256
requiredStandingTime: 11000
elapsedTime: 3852
requiredStandingTime: 15000
elapsedTime: 260
Ah backwards.

Change < to > on this line

if questConfig[index].requiredStandingTime < (os.mtime() - tileStandingPlayers[playerId].standingTime) then
Post automatically merged:

Sorry on my phone
 
OP
OP
T

Tibia Demon

Guest
Ah backwards.

Change < to > on this line

if questConfig[index].requiredStandingTime < (os.mtime() - tileStandingPlayers[playerId].standingTime) then
Post automatically merged:

Sorry on my phone
keeps sending effect CONST_ME_MAGIC_GREEN too fast without stopping or tping player
if questConfig[index].requiredStandingTime > (os.mtime() - tileStandingPlayers[playerId].standingTime) then
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,304
Solutions
547
Reaction score
4,566
keeps sending effect CONST_ME_MAGIC_GREEN too fast without stopping or tping player
if questConfig[index].requiredStandingTime > (os.mtime() - tileStandingPlayers[playerId].standingTime) then
I put a 3 second cooldown on the effect.
Lua:
local actionId = 40490

local tileStandingPlayers = {} -- will hold information about the players. [creatureId] = {standingTime = 0, tableIndex = 0}
local kickPosition = Position(1008, 1013, 7)
local questConfig = {
    {storage = 20115, requiredStandingTime = 1000, tilePosition = Position(1011, 1012, 7)}, -- requiredStandingTime is in milliseconds.
    {storage = 20116, requiredStandingTime = 2000, tilePosition = Position(1012, 1014, 7)},
    {storage = 20117, requiredStandingTime = 3000, tilePosition = Position(1014, 1013, 7)}
}


local function tileChecker(playerId, startedTime, effectInterval)
    -- recreate the player, to ensure they still exist
    local player = Player(playerId)
    if not player then
        return
    end
  
    -- check if table has been reset.
    if not tileStandingPlayers[playerId] or startedTime ~= tileStandingPlayers[playerId].standingTime then
        return
    end
  
    -- check if player has left the tile location
    local index = tileStandingPlayers[playerId].tableIndex 
    if questConfig[index].tilePosition ~= player:getPosition() then
        return
    end
  
    -- check if time has elapsed
    if questConfig[index].requiredStandingTime > (os.mtime() - tileStandingPlayers[playerId].standingTime) then
        -- if not enough time has elapsed, then loop function
        effectInterval = effectInterval - 250
        if effectInterval <= 0 then
            effectInterval = 3000
            questConfig[index].tilePosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
        addEvent(tileChecker, 250, playerId, startedTime, effectInterval)
        return
    end
  
  
    -- enough time has elapsed, so give storage and teleport player off the tile
    player:setStorageValue(questConfig[index].storage, 1)
    questConfig[index].tilePosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(kickPosition)
    kickPosition:sendMagicEffect(CONST_ME_HITAREA)
  
    -- and finally, let's clean up the table.
    tileStandingPlayers[playerId] = nil
  
    -- while we're at it, let's tell the player if they have completed all the tiles
    for v, k in pairs(questConfig) do
        if player:getStorageValue(k.storage) ~= 1 then
            player:say("There's still some more tiles to go!", TALKTYPE_MONSTER_SAY)
            return
        end
    end
    player:say("You've completed all of the tiles!", TALKTYPE_MONSTER_SAY)
end




local StepIn_questnorthtp = MoveEvent()
StepIn_questnorthtp:type("stepin")

function StepIn_questnorthtp.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
  
    local hasAllStorages = true
  
    -- loop through table
    for v, k in pairs(questConfig) do
        -- find the current tile
        if position == k.tilePosition then
            -- check if player has this storage
            if player:getStorageValue(k.storage) ~= 1 then
                -- if the player doesn't have this storage, then start the timer, and allow player onto the tile.
                local currentTime = os.mtime()
                local playerId = player:getId()
                tileStandingPlayers[playerId] = {standingTime = currentTime, tableIndex = v}
                addEvent(tileChecker, 250, playerId, currentTime, 0)
                return true -- since we want the player to stay on the tile, we break the loop here, as there is no point in checking the rest of the positions.
            end
        end
  
        -- regardless of tile, let's check if they've completed all the tiles
        if player:getStorageValue(k.storage) ~= 1 then
            hasAllStorages = false
        end
    end
  
    -- if the script get's here, we know the player already has this tile's storage, so we can teleport them
    player:teleportTo(fromPosition)
  
    -- and here we give the player information about the tiles
    if hasAllStorages then
        player:say("You've completed all of the tiles!", TALKTYPE_MONSTER_SAY)
    else
        player:say("You've completed this tile already. There's still some more tiles to go!", TALKTYPE_MONSTER_SAY)
    end
    return true
end

StepIn_questnorthtp:aid(actionId)
StepIn_questnorthtp:register()
 
Solution
OP
OP
T

Tibia Demon

Guest
I put a 3 second cooldown on the effect.
Lua:
local actionId = 40490

local tileStandingPlayers = {} -- will hold information about the players. [creatureId] = {standingTime = 0, tableIndex = 0}
local kickPosition = Position(1008, 1013, 7)
local questConfig = {
    {storage = 20115, requiredStandingTime = 1000, tilePosition = Position(1011, 1012, 7)}, -- requiredStandingTime is in milliseconds.
    {storage = 20116, requiredStandingTime = 2000, tilePosition = Position(1012, 1014, 7)},
    {storage = 20117, requiredStandingTime = 3000, tilePosition = Position(1014, 1013, 7)}
}


local function tileChecker(playerId, startedTime, effectInterval)
    -- recreate the player, to ensure they still exist
    local player = Player(playerId)
    if not player then
        return
    end
 
    -- check if table has been reset.
    if not tileStandingPlayers[playerId] or startedTime ~= tileStandingPlayers[playerId].standingTime then
        return
    end
 
    -- check if player has left the tile location
    local index = tileStandingPlayers[playerId].tableIndex
    if questConfig[index].tilePosition ~= player:getPosition() then
        return
    end
 
    -- check if time has elapsed
    if questConfig[index].requiredStandingTime > (os.mtime() - tileStandingPlayers[playerId].standingTime) then
        -- if not enough time has elapsed, then loop function
        effectInterval = effectInterval - 250
        if effectInterval <= 0 then
            effectInterval = 3000
            questConfig[index].tilePosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
        addEvent(tileChecker, 250, playerId, startedTime, effectInterval)
        return
    end
 
 
    -- enough time has elapsed, so give storage and teleport player off the tile
    player:setStorageValue(questConfig[index].storage, 1)
    questConfig[index].tilePosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(kickPosition)
    kickPosition:sendMagicEffect(CONST_ME_HITAREA)
 
    -- and finally, let's clean up the table.
    tileStandingPlayers[playerId] = nil
 
    -- while we're at it, let's tell the player if they have completed all the tiles
    for v, k in pairs(questConfig) do
        if player:getStorageValue(k.storage) ~= 1 then
            player:say("There's still some more tiles to go!", TALKTYPE_MONSTER_SAY)
            return
        end
    end
    player:say("You've completed all of the tiles!", TALKTYPE_MONSTER_SAY)
end




local StepIn_questnorthtp = MoveEvent()
StepIn_questnorthtp:type("stepin")

function StepIn_questnorthtp.onStepIn(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
 
    local hasAllStorages = true
 
    -- loop through table
    for v, k in pairs(questConfig) do
        -- find the current tile
        if position == k.tilePosition then
            -- check if player has this storage
            if player:getStorageValue(k.storage) ~= 1 then
                -- if the player doesn't have this storage, then start the timer, and allow player onto the tile.
                local currentTime = os.mtime()
                local playerId = player:getId()
                tileStandingPlayers[playerId] = {standingTime = currentTime, tableIndex = v}
                addEvent(tileChecker, 250, playerId, currentTime, 0)
                return true -- since we want the player to stay on the tile, we break the loop here, as there is no point in checking the rest of the positions.
            end
        end
 
        -- regardless of tile, let's check if they've completed all the tiles
        if player:getStorageValue(k.storage) ~= 1 then
            hasAllStorages = false
        end
    end
 
    -- if the script get's here, we know the player already has this tile's storage, so we can teleport them
    player:teleportTo(fromPosition)
 
    -- and here we give the player information about the tiles
    if hasAllStorages then
        player:say("You've completed all of the tiles!", TALKTYPE_MONSTER_SAY)
    else
        player:say("You've completed this tile already. There's still some more tiles to go!", TALKTYPE_MONSTER_SAY)
    end
    return true
end

StepIn_questnorthtp:aid(actionId)
StepIn_questnorthtp:register()
thank you working perfect now!
 

Similar threads

Top