local config = {
walls = {
[1] = {position = Position(1276, 995, 7), chance = 100, id = 1546},
[2] = {position = Position(1412, 1000, 6), chance = 20, id = 1546},
},
levers = {notPulled = 1945, pulled = 1946}
}
local function revertThings(leverPosition)
for _, wall in ipairs(config.walls) do
local tile = Tile(wall.position)
if tile then
local wallItem = tile:getItemById(wall.id)
if not wallItem then
Game.createItem(wall.id, 1, wall.position)
end
end
end
local tile = Tile(leverPosition)
if tile then
local item = tile:getItemById(config.levers.pulled)
if item then...
function onSay(player, words, param)
local text = ""
local spells = {}
for _, spell in ipairs(player:getInstantSpells()) do
if spell.level ~= 0 then
if spell.manapercent > 0 then
spell.mana = spell.manapercent .. "%"
end
spells[#spells + 1] = spell
end
end
table.sort(spells, function(a, b) return a.level < b.level end)
local prevLevel = -1
for i, spell in ipairs(spells) do
local line = ""
if prevLevel ~= spell.level then
if i ~= 1 then
line = "\n"
end
line = line .. "Spells for Level " .. spell.level .. "\n"
prevLevel = spell.level
end
text = text .. line .. " " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
end
player:showTextDialog(2175, text)
return true
end
<talkaction words="!spells" script="spells.lua" />
<action actionid="22666" script="wall_remove.lua"/>
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local storage = 22666
local time_n = os.time()
local wall_item_id = 2525
local walls = {
[1] = Position(1000,1000,7), -- x, y, z positions
[2] = Position(1000,500,7) -- Position of the another wall
}
if(math.random(1,10) <= 1) and time_n >= Game.getStorageValue(storage) then -- 10% chance
local lucky_wall = math.random(1,#walls)
local tile = Tile(walls[lucky_wall])
local wall_check = tile:getItemById(wall_item_id)
if wall_check then
wall_check:remove()
end
Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, 'Try again in 2 minutes.')
Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage
end
return true
end
local wallPosition = Position(1276, 995, 7) --wall position
local wall = 22573 --wall ID
local revertTime = 1 * 60 * 1000 --time: 1=1min
local function revertWall()
Game.createItem(wall, 1, wallPosition)
wallPosition:sendMagicEffect(CONST_ME_POFF)
end
local function revertLever(position)
local leverItem = Tile(position):getItemById(1946)
if leverItem then
leverItem:transform(1945)
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == 1945 then
local removeWall = Tile(wallPosition):getItemById(wall)
if removeWall then
removeWall:remove()
wallPosition:sendMagicEffect(CONST_ME_POFF)
addEvent(revertWall, revertTime)
end
item:transform(1946)
addEvent(revertLever, revertTime, toPosition)
end
return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local storage = 22666
local time_n = os.time()
local wall_item_id = 2525
local walls_remove_pos = Position(1000,1000,7)
local lucky_wall_pos = Position(1000,500,7)
if time_n >= Game.getStorageValue(storage) then
if (math.random(1,10) <= 1) then -- 10% chance
local lucky_wall = Tile(lucky_wall_pos)
local lucky_wall_check = lucky_wall:getItemById(wall_item_id)
if lucky_wall_check then
lucky_wall_check:remove()
end
end
local tile = Tile(walls_remove_pos)
local wall_check = tile:getItemById(wall_item_id)
if wall_check then
wall_check:remove()
end
Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, 'Try again in 2 minutes.')
Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage
end
return true
end
if you define constant values in scope of function they will get reinitialized every time someone use the action, move them out of function scope.Oh ... is really more simple of that script I maded for you! HAHAHAHAHA
@Inoxic
Lua:function onUse(player, item, fromPosition, target, toPosition, isHotkey) local storage = 22666 local time_n = os.time() local wall_item_id = 2525 local walls_remove_pos = Position(1000,1000,7) local lucky_wall_pos = Position(1000,500,7) if time_n >= Game.getStorageValue(storage) then if (math.random(1,10) <= 1) then -- 10% chance local lucky_wall = Tile(lucky_wall_pos) local lucky_wall_check = lucky_wall:getItemById(wall_item_id) if lucky_wall_check then lucky_wall_check:remove() end end local tile = Tile(walls_remove_pos) local wall_check = tile:getItemById(wall_item_id) if wall_check then wall_check:remove() end Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage else player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, 'Try again in 2 minutes.') Game.setStorageValue(storage,(time_n+120)) -- 120 seconds to current time in a Global Storage end return true end
This script no include transformation of the leverID ... or create another wall.. Just remove a wall in the position.
local config = {
walls = {
[1] = {position = Position(x, y, z), chance = 100, id = 1033},
[2] = {position = Position(x, y, z), chance = 20, id = 1033},
},
positions = {
Position(x, y, z),
Position(x, y, z),
},
levers = {notPulled = 1000, pulled = 1001}
}
local function revertThings(leverPosition)
for _, wall in ipairs(config.walls) do
local tile = Tile(wall.position)
if tile then
local wall = tile:getItemById(wall.id)
if not wall then
Game.createItem(wall.id, 1, wall.position)
end
end
end
local tile = Tile(leverPosition)
if tile then
local item = tile:getItemById(config.levers.pulled)
if item then
item:transform(config.levers.notPulled)
end
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getId() == config.levers.notPulled then
for _, wall in ipairs(config.walls) do
local tile = Tile(wall.position)
if tile then
local wall = tile:getItemById(wall.id)
if wall and math.random(1, 100) <= wall.chance then
wall:remove()
end
end
end
item:transform(config.levers.pulled)
addEvent(revertThings, 2 * 60 * 1000, item:getPosition())
end
return true
end