Lua script edit help

jackl90

Member
Joined
Jul 25, 2017
Messages
186
Best answers
0
Reaction score
6
Hello someone can help me with this script?

Lua:
local effectDuration = 3*60
local effectInterval = 2
if not alreadyExecuted then
    alreadyExecuted = 0
end

local function repeatEffect(pos, effect, repeats)
    Game.sendMagicEffect(pos, effect)
    if repeats > 0 then
        addEvent(repeatEffect, effectInterval*1000, pos, effect, repeats-1)
    end
end

function onAddItem(item, tileitem, position)
    if alreadyExecuted == 0 and Game.isItemThere({x = 32511, y = 31585, z = 15},3034) then
        repeatEffect({x = 32509, y = 31589, z = 15}, 13, effectDuration/effectInterval)
        Game.sendMagicEffect({x = 32511, y = 31585, z = 15}, 16)
        Game.removeItemOnMap({x = 32511, y = 31585, z = 15},3034)
        alreadyExecuted = 1
        end
    end

If i put this same script number in other tiles, example tile 1, tile 2, tile 3 how can i add more positions in this part ?
Lua:
 if alreadyExecuted == 0 and Game.isItemThere({x = 32511, y = 31585, z = 15},3034) then
because i have 3 tiles that i need this script work
tile1 {x = 32511, y = 31585, z = 15}
tile 2 {x = 32511, y = 31586, z = 15}
tile 3 {x = 32511, y = 31587, z = 15}

What i need?
if player addeditem in tile 1 for example and after try additem in tile 2

only will work this part of script

Lua:
Game.sendMagicEffect({x = 32511, y = 31586, z = 15}, 16)

        Game.removeItemOnMap({x = 32511, y = 31585, z = 15},3034)
no work more repeatEffect in this case.
 

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
6,571
Best answers
179
Reaction score
1,289
Location
Norway, Oslo
The magic effect is always in position {x = 32509, y = 31589, z = 15}, but the items can be in any of the 3 tiles you mentioned?

Lua:
local effectDuration = 3*60
local effectInterval = 2
local positionList = {
    {
        item = {x = 32511, y = 31585, z = 15},
        effect = {x = 32509, y = 31589, z = 15}
    },
    {
        item = {x = 32511, y = 31586, z = 15},
        effect = {x = 32509, y = 31589, z = 15}
    },
    {
        item = {x = 32511, y = 31587, z = 15},
        effect = {x = 32509, y = 31589, z = 15}
    }
}
if not alreadyExecuted then
    alreadyExecuted = 0
end

local function repeatEffect(pos, effect, repeats)
    Game.sendMagicEffect(pos, effect)
    if repeats > 0 then
        addEvent(repeatEffect, effectInterval*1000, pos, effect, repeats-1)
    end
end

function onAddItem(item, tileitem, position)
    for i,pos in positionList do
        if alreadyExecuted == 0 and Game.isItemThere(pos.item, 3034) then
            repeatEffect(pos.effect, 13, effectDuration/effectInterval)
            Game.sendMagicEffect(pos.item, 16)
            Game.removeItemOnMap(pos.item, 3034)
            alreadyExecuted = 1
        end
    end
end
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
744
Best answers
110
Reaction score
485
Location
United States
Hello Znote, thanks so much for u reply... but unfortunately it did not work, i will try explain better using a imagem.

You can try this, idk how it'll work cause I can't test since idk what distro you are using.
I made this assuming you set an action id for each lava tile and register the onAddItem to the action id not the item id.

Lua:
local event_duration = 3 * 60
local event_interval = 2
local switch_pos = {x = 33199, y = 31648, z = 15}
local pos_needed = {x = 33201, y = 31646, z = 15}

if not already_executed then
    already_executed = false
end

local function repeatEffect(position, effect, interval, end_time)
    if os.time() >= end_time then
        return
    end

    Game.sendMagicEffect(position, effect)
    addEvent(repeatEffect, interval * 1000, position, effect, interval, end_time)
end

function onAddItem(item, tileitem, position)
    if item.itemid == 3034 then
        Game.sendMagicEffect(position, 16)
        Game.removeItemOnMap(position, 3034)
        if not already_executed and (position.x == pos_needed.x and position.y == pos_needed.y and position.z == pos_needed.z) then
            repeatEffect(switch_pos, 13, event_interval, os.time() + event_duration)
            already_executed = true
        end
    end
    return true
end
 
OP
J

jackl90

Member
Joined
Jul 25, 2017
Messages
186
Best answers
0
Reaction score
6
You can try this, idk how it'll work cause I can't test since idk what distro you are using.
I made this assuming you set an action id for each lava tile and register the onAddItem to the action id not the item id.

Lua:
local event_duration = 3 * 60
local event_interval = 2
local switch_pos = {x = 33199, y = 31648, z = 15}
local pos_needed = {x = 33201, y = 31646, z = 15}

if not already_executed then
    already_executed = false
end

local function repeatEffect(position, effect, interval, end_time)
    if os.time() >= end_time then
        return
    end

    Game.sendMagicEffect(position, effect)
    addEvent(repeatEffect, interval * 1000, position, effect, interval, end_time)
end

function onAddItem(item, tileitem, position)
    if item.itemid == 3034 then
        Game.sendMagicEffect(position, 16)
        Game.removeItemOnMap(position, 3034)
        if not already_executed and (position.x == pos_needed.x and position.y == pos_needed.y and position.z == pos_needed.z) then
            repeatEffect(switch_pos, 13, event_interval, os.time() + event_duration)
            already_executed = true
        end
    end
    return true
end

works, i think just need add more position in local pos_needed =
how can i do it ?
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
744
Best answers
110
Reaction score
485
Location
United States
works, i think just need add more position in local pos_needed =
how can i do it ?
You would turn pos_needed into an array and use a for loop to check each of those positions. I would write it but I don't see why you need more positions needed when you stated in your directions that positions 2 and 3 will only remove item and send magic effect. Only pos 1 was the positions that could activate the repeatEffect function.
 
OP
J

jackl90

Member
Joined
Jul 25, 2017
Messages
186
Best answers
0
Reaction score
6
You would turn pos_needed into an array and use a for loop to check each of those positions. I would write it but I don't see why you need more positions needed when you stated in your directions that positions 2 and 3 will only remove item and send magic effect. Only pos 1 was the positions that could activate the repeatEffect function.
i understand, but is because if i put the item on position 2 now for example then position 1 and 3 will only remove item and send magic effect.
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
744
Best answers
110
Reaction score
485
Location
United States
i understand, but is because if i put the item on position 2 now for example then position 1 and 3 will only remove item and send magic effect.
Your descriptions are very hard to understand. If this is what you want great, but otherwise idk how to help, sorry man.
Lua:
local event_duration = 3 * 60
local event_interval = 2
local switch_pos = {x = 33199, y = 31648, z = 15}

local positions = {
    {x = 33201, y = 31646, z = 15},
    {x = 33202, y = 31646, z = 15},
    {x = 33203, y = 31646, z = 15},
}

if not already_executed then
    already_executed = false
end

local function repeatEffect(position, effect, interval, end_time)
    if os.time() >= end_time then
        return
    end

    Game.sendMagicEffect(position, effect)
    addEvent(repeatEffect, interval * 1000, position, effect, interval, end_time)
end

function onAddItem(item, tileitem, position)
    if item.itemid == 3034 then
        Game.sendMagicEffect(position, 16)
        Game.removeItemOnMap(position, 3034)
        if not already_executed then
            for key, pos in pairs(positions) do
                if pos.x == position.x and pos.y == position.y then
                    repeatEffect(switch_pos, 13, event_interval, os.time() + event_duration)
                    already_executed = true
                    break
                end
            end
        end
    end
    return true
end
 
Top