kimokimo
Kimo
So i've created this RevScript for growth task in dangerous depths quest from real tibia.
Basicly it spawns barrels that are supposed to be pushed to a room and use the barrel to explode it inside the room to gain a point.
Barrels should explode on thier own if left for 5 minutes without exploding.
So this script basicly does this,
1- Player spawns a barrel, it gets stored in a table with it's id and position.
2- addEvent is excuted to explode barrel after x minutes if it's in the table.
3- if player use(explode) a barrel it will be removed from the table and exploded.
4- player moving the barrel will update it's position in table for later use for the addEvent
My question is, is there a better way to get the same results safely?
Dangerous Depths Quest (https://tibia.fandom.com/wiki/Dangerous_Depths_Quest#Explosive_Growth)
events/player.lua
Basicly it spawns barrels that are supposed to be pushed to a room and use the barrel to explode it inside the room to gain a point.
Barrels should explode on thier own if left for 5 minutes without exploding.
So this script basicly does this,
1- Player spawns a barrel, it gets stored in a table with it's id and position.
2- addEvent is excuted to explode barrel after x minutes if it's in the table.
3- if player use(explode) a barrel it will be removed from the table and exploded.
4- player moving the barrel will update it's position in table for later use for the addEvent
My question is, is there a better way to get the same results safely?
Dangerous Depths Quest (https://tibia.fandom.com/wiki/Dangerous_Depths_Quest#Explosive_Growth)
events/player.lua
Lua:
if isInArray({26141, 26142}, item:getId()) then
if item:getCustomAttribute('ID') then
if barrels[item:getCustomAttribute('ID')] then
barrels[item:getCustomAttribute('ID')].pos = toPosition
end
end
end
Lua:
local transformid = {
[28594] = 1946,
[1946] = 28594
}
local config = {
{
fromPosition = Position(33877, 32060, 14),
toPosition = Position(33888, 32068, 14),
roomCenter = Position(33882, 32064, 14),
stgRoom = Storage.DangerousDepths.Scouts.FirstBarrel
},
{
fromPosition = Position(33906, 32026, 14),
toPosition = Position(33916, 32037, 14),
roomCenter = Position(33913, 32034, 14),
stgRoom = Storage.DangerousDepths.Scouts.SecondBarrel
},
{
fromPosition = Position(33865, 32009, 14),
toPosition = Position(33874, 32020, 14),
roomCenter = Position(33870, 32015, 14),
stgRoom = Storage.DangerousDepths.Scouts.ThirdBarrel
},
{
fromPosition = Position(33837, 31984, 14),
toPosition = Position(33852, 31991, 14),
roomCenter = Position(33847, 31988, 14),
stgRoom = Storage.DangerousDepths.Scouts.FourthBarrel
},
{
fromPosition = Position(33923, 31982, 14),
toPosition = Position(33942, 31998, 14),
roomCenter = Position(33932, 31991, 14),
stgRoom = Storage.DangerousDepths.Scouts.FifthBarrel
}
}
local function checkPos(item)
if item then
for i = 1, #config do
local thing = config[i]
local fromPos, toPos, stgRoom = thing.fromPosition, thing.toPosition, thing.stgRoom
if item:getPosition():isInRange(fromPos, toPos) then
local spectator = Game.getSpectators(thing.roomCenter, false, false, 5, 5, 5, 5)
for s = 1, #spectator do
local spec = spectator[s]
if spec:isPlayer() then
if spec:getStorageValue(stgRoom) < 1 then
spec:setStorageValue(Storage.DangerousDepths.Scouts.BarrelCount, spec:getStorageValue(Storage.DangerousDepths.Scouts.BarrelCount) + 1)
spec:setStorageValue(stgRoom, 1)
end
end
end
end
end
end
end
local function explode(id)
if not barrels[id] then
return false
end
local thing = barrels[id]
local tile = Tile(thing.pos)
local barrel = tile:getItemById(26141)
if barrel then
local c = Game.getPlayers()[1]
addEvent(function()
local position = thing.pos
local fromPosition = Position(position.x - 6, position.y - 6, position.z)
local toPosition = Position(position.x + 6, position.y + 6, position.z)
for x = fromPosition.x, toPosition.x do
for y = fromPosition.y, toPosition.y do
for z = fromPosition.z, toPosition.z do
if Tile(Position(x, y, z)) then
if Tile(Position(x, y, z)) then
local posEffect = Tile(Position(x, y, z)):getPosition()
local creature = Tile(Position(x, y, z)):getTopCreature()
posEffect:sendMagicEffect(CONST_ME_FIREAREA)
end
end
end
end
end
checkPos(barrel)
c:say("KABOOM!!", TALKTYPE_MONSTER_SAY, false, false, position)
if barrel then
table.remove(barrels[id])
barrel:remove()
local barrelCounter = Game.getStorageValue(GlobalStorage.DangerousDepths.BarrelCounter)
Game.setStorageValue(GlobalStorage.DangerousDepths.BarrelCounter, barrelCounter - 1)
end
end, 5 * 1000)
barrel:transform(26142)
c:say("Tsssss...!", TALKTYPE_MONSTER_SAY, false, false, thing.pos)
end
end
local barrelItself = Action()
function barrelItself.onUse(player, item)
if not item:getCustomAttribute('ID') then
return true
end
local getBarrel
if not barrels[item:getCustomAttribute('ID')] then
return true
end
for i = 1, #config do
local thing = config[i]
local fromPos, toPos = thing.fromPosition, thing.toPosition
if item:getPosition():isInRange(fromPos, toPos) then
explode(item:getCustomAttribute('ID'))
end
end
return true
end
barrelItself:id(26141)
barrelItself:register()
local dangerousDepthLever = Action()
function dangerousDepthLever.onUse(player, item)
if not player then
return true
end
local posBarril = Position(33838, 32077, 14)
local stgCount = player:getStorageValue(Storage.DangerousDepths.Scouts.BarrelCount)
local BarrelTimer = player:getStorageValue(Storage.DangerousDepths.Scouts.BarrelTimer)
if item:getId() == 1946 then
item:transform(transformid[item:getId()])
return true
end
if item:getId() == 28594 then
if player:getStorageValue(Storage.DangerousDepths.Scouts.Growth) == 1 and stgCount < 5 then
if Game.getStorageValue(GlobalStorage.DangerousDepths.GrowthBarrel) <= os.time() then
local barrel = Game.createItem(26141, 1, posBarril)
Game.setStorageValue(GlobalStorage.DangerousDepths.GrowthBarrel, os.time() + 1 * 60 * 1000)
Game.setStorageValue(GlobalStorage.DangerousDepths.BarrelCounter, Game.getStorageValue(GlobalStorage.DangerousDepths.BarrelCounter) + 1)
local barrelCounter = Game.getStorageValue(GlobalStorage.DangerousDepths.BarrelCounter)
if barrel:setCustomAttribute("ID", barrelCounter) then
barrels[barrelCounter] = {pos = barrel:getPosition()}
addEvent(explode, 5 * 60 * 1000, barrelCounter)
end
item:transform(transformid[item:getId()])
else
local eq = Game.getStorageValue(GlobalStorage.DangerousDepths.GrowthBarrel) - os.time()
player:sendCancelMessage("You need to wait ".. secondsToClock(eq).." before another barrel arrive.")
end
end
end
return true
end
dangerousDepthLever:aid(57234)
dangerousDepthLever:register()