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

Lua What am I doing wrong?

manuloku

New Member
Joined
Nov 12, 2008
Messages
31
Reaction score
4
I'm trying to do an AMBUSH system, but calling from a Global LIB (AMBUSH_TABLE). It calls the name of monsters to be summoned for each UID tile you StepOut (in different locations, of course...) BTW the game don't create the monster and don't even appear anything in console to help me out how to fix... so I know the code is not well done, since i'm not good at scripts... btw I'm trying!

Also i'm trying to input an ADDEVENT() for create the monsters after 3 seconds.

Lua:
function onStepOut(cid, item, position, fromPosition)

    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local pos = player:getPosition()
    local uniqueid = tile:getUniqueId()
        if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then
            local creatures_pool = {}
            for i, monsters in pairs(AMBUSH_TABLE) do
                    table.insert(creatures_pool, AMBUSH_TABLE[i].monsters) 
            end         
                for k = 1, #creatures_pool do
                    local pos = player:getPosition()
                    local radius = 2
                    Game.createMonster(creatures_pool[k], position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
                    -- player:setStorageValue(uniqueid, 1)
                end     
        end
end

and HERE is the LIB file:

Lua:
AMBUSH_TABLE = {    [60005] = {monsters = {'skeleton', 'poison spider'}
                                                                                   },
                                                                               
                    [60006] = {monsters = {}
                                                                                   },
                                                                                   
                }
 
Solution
I won't comment on the code itself, just answering the question of what you're doing incorrectly. xP
You're not using the AMBUSH_TABLE key, which you setup as the uniqueid of the tile in your loop.
This is leaving the creatures_pool empty, which makes the second loop do nothing, hence no errors.

change this
Lua:
for i, monsters in pairs(AMBUSH_TABLE) do
    table.insert(creatures_pool, AMBUSH_TABLE[i].monsters) 
end
to this
Lua:
for i = 1, #AMBUSH_TABLE[uniqueid].monsters do
    table.insert(creatures_pool, AMBUSH_TABLE[uniqueid].monsters[i]) 
end
I won't comment on the code itself, just answering the question of what you're doing incorrectly. xP
You're not using the AMBUSH_TABLE key, which you setup as the uniqueid of the tile in your loop.
This is leaving the creatures_pool empty, which makes the second loop do nothing, hence no errors.

change this
Lua:
for i, monsters in pairs(AMBUSH_TABLE) do
    table.insert(creatures_pool, AMBUSH_TABLE[i].monsters) 
end
to this
Lua:
for i = 1, #AMBUSH_TABLE[uniqueid].monsters do
    table.insert(creatures_pool, AMBUSH_TABLE[uniqueid].monsters[i]) 
end
 
Solution
I won't comment on the code itself, just answering the question of what you're doing incorrectly. xP
You're not using the AMBUSH_TABLE key, which you setup as the uniqueid of the tile in your loop.
This is leaving the creatures_pool empty, which makes the second loop do nothing, hence no errors.

change this
Lua:
for i, monsters in pairs(AMBUSH_TABLE) do
    table.insert(creatures_pool, AMBUSH_TABLE[i].monsters)
end
to this
Lua:
for i = 1, #AMBUSH_TABLE[uniqueid].monsters do
    table.insert(creatures_pool, AMBUSH_TABLE[uniqueid].monsters[i])
end
Isn't realy necessary loop the table, just copy the monsters value to creature_pool or just refear to monsters itself.
Lua:
local creatures_pool = AMBUSH_TABLE[uniqueid].monsters
or
Lua:
for k = 1, #AMBUSH_TABLE[uniqueid].monsters do
    local radius = 2
    Game.createMonster(AMBUSH_TABLE[uniqueid].monsters[k], position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!") --dois caras numa moto?!
    -- player:setStorageValue(uniqueid, 1)
end
What im trying to say is: Why loop over a table just to copy the values to another table? The tables don't looks be changed later...
This point isn't for you Xikini
 
Thanks, @zxmatzx! Btw, with @Xikini configuration i couldn't take all the monsters in the AMBUSH.lua pool, so i had to make this:

AMBUSH.lua (lib file):
Lua:
AMBUSH_TABLE = {    [60005] = {monsters = { [1] = {'skeleton'},
                                            [2] = {'poison spider'}
                                            }
                                                                                   },
                                                                               
                    [60006] = {monsters = {}
                                                                                   },
                                                                                   
                }

and in the main script (movement script):
Code:
function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local uniqueid = tile:getUniqueId()
        if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then  
        local creatures_pool = {}
        for var = 1, #AMBUSH_TABLE[uniqueid].monsters do
            local ambush = AMBUSH_TABLE[uniqueid].monsters[var]
            for i = 1, #ambush do
                table.insert(creatures_pool, ambush[i])    
            end  
        end      
        for k = 1, #creatures_pool do
            local pos = player:getPosition()
            local radius = 2
            Game.createMonster(creatures_pool[k], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")  
        -- player:setStorageValue(uniqueid, 1)
        end
end

And yeah... It looks to work perfectly... BUT now i'm trying to make an AddEvent() to launch the function after 3 seconds...

I did this: (not working)

Code:
local function emboscada(cid, position)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local creatures_pool = {}
    local creatures_pool = {}
    for var = 1, #AMBUSH_TABLE[uniqueid].monsters do
        local ambush = AMBUSH_TABLE[uniqueid].monsters[var]
        for i = 1, #ambush do
            table.insert(creatures_pool, ambush[i])    
        end  
    end      
    for k = 1, #creatures_pool do
        local pos = player:getPosition()
        local radius = 2
        Game.createMonster(creatures_pool[k], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")  
end

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local uniqueid = tile:getUniqueId()
        if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then  
            addEvent(emboscada, 3000, cid.uid, position)  
        -- player:setStorageValue(uniqueid, 1)
        end
end

The problem I SEE is that as TILE ( local tile = Item(item.uid)) is an onStepOut declared, it WON'T work at the local function...

Can you guys help me?

@zxmatzx I did a lot of FOR inside the function, how can i optimize that, thinking in what you helped me in you post?
 
Last edited:
Thanks, @zxmatzx! Btw, with @Xikini configuration i couldn't take all the monsters in the AMBUSH.lua pool, so i had to make this:

AMBUSH.lua (lib file):
Lua:
AMBUSH_TABLE = {    [60005] = {monsters = { [1] = {'skeleton'},
                                            [2] = {'poison spider'}
                                            }
                                                                                   },
                                                                             
                    [60006] = {monsters = {}
                                                                                   },
                                                                                 
                }

and in the main script (movement script):
Code:
function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local uniqueid = tile:getUniqueId()
        if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then
        local creatures_pool = {}
        for var = 1, #AMBUSH_TABLE[uniqueid].monsters do
            local ambush = AMBUSH_TABLE[uniqueid].monsters[var]
            for i = 1, #ambush do
                table.insert(creatures_pool, ambush[i])  
            end
        end    
        for k = 1, #creatures_pool do
            local pos = player:getPosition()
            local radius = 2
            Game.createMonster(creatures_pool[k], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        -- player:setStorageValue(uniqueid, 1)
        end
end

And yeah... It looks to work perfectly... BUT now i'm trying to make an AddEvent() to launch the function after 3 seconds...

I did this: (not working)

Code:
local function emboscada(cid, position)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local creatures_pool = {}
    local creatures_pool = {}
    for var = 1, #AMBUSH_TABLE[uniqueid].monsters do
        local ambush = AMBUSH_TABLE[uniqueid].monsters[var]
        for i = 1, #ambush do
            table.insert(creatures_pool, ambush[i])  
        end
    end    
    for k = 1, #creatures_pool do
        local pos = player:getPosition()
        local radius = 2
        Game.createMonster(creatures_pool[k], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
end

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local uniqueid = tile:getUniqueId()
        if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then
            addEvent(emboscada, 3000, cid.uid, position)
        -- player:setStorageValue(uniqueid, 1)
        end
end

The problem I SEE is that as TILE ( local tile = Item(item.uid)) is an onStepOut declared, it WON'T work at the local function...

Can you guys help me?

@zxmatzx I did a lot of FOR inside the function, how can i optimize that, thinking in what you helped me in you post?
Lua:
AMBUSH_TABLE = {
    [60005] = {monsters = {"skeleton", "poison spider"} },
    [60006] = {monsters = {"rat", "cave rat"} }
}

local function emboscada(cid, position, uniqueid)
    local player = Player(cid)
    if not player then
        return true
    end
    if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then   
        for i = 1, #AMBUSH_TABLE[uniqueid].monsters do
            local pos = player:getPosition()
            local radius = 2
            print("Attempting to create monster: " .. AMBUSH_TABLE[uniqueid].monsters[i])
            Game.createMonster(AMBUSH_TABLE[uniqueid].monsters[i], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        player:setStorageValue(uniqueid, 1)
    end
end

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local uniqueid = tile:getUniqueId()
    if player:getStorageValue(uniqueid) == -1 or player:getStorageValue(uniqueid) == 0 then   
        addEvent(emboscada, 3000, cid.uid, position, uniqueid)   
    end
    return true
end
 
Thanks a lot @Xikini and @zxmatzx it works like a glove!

Now the last thing, just to full complete my system, and of course, i don't have any idea how to do...

How can i make posible to activate this system for the same 60005 if a corridor is larger? (example: 3x3 tiles), like if a player pass x-1 or x+1 from the original tile, it triggers the same thing?

That way i can make the ambushes less predictable...
 
Thanks a lot @Xikini and @zxmatzx it works like a glove!

Now the last thing, just to full complete my system, and of course, i don't have any idea how to do...

How can i make posible to activate this system for the same 60005 if a corridor is larger? (example: 3x3 tiles), like if a player pass x-1 or x+1 from the original tile, it triggers the same thing?

That way i can make the ambushes less predictable...
Hi,
You can configure your onStepOut function with a actionid, and set this actionid to all tiles that you want to run your script.
This in movements.xml
XML:
 <movevent event="StepOut" actionid="5000" script="myScript.lua" />
 
@zxmatzx Thanks mate!

Now trying to reproduce what you said, I could not find an answer... since my stepout already determined as actionid="60000" and inside script there is the uniqueids, like "60005"...

Well, not a problem I think, so what i made is: create an custom item, with 0 transparency and put over the tiles that i want to see the "magic".

So my event inside movements.xml is:
XML:
    <movevent event="StepOut" itemid="29965" script="explorations/map_ambushes.lua"/>

and for map_ambushes.lua i did this: (not working, of course)

Lua:
AMBUSH_TABLE = {
    [29965] = {
                [60005] = {monsters = {"rotworm", "rotworm"},
                    ambush_reset = 1, -- minutos
                    ambush_time = 3000,
                },       
                
                [60006] = {monsters = {"rat", "cave rat"},
                    ambush_reset = x, -- minutos
                    ambush_time = xxxx,
                }
    }
}

local function emboscada(cid, position, item, actionid)
    local player = Player(cid)
    if not player then
        return true
    end
    local check = AMBUSH_TABLE[item.itemid]
    if player:getStorageValue(Storage.AMBUSH) <= os.time() then   
        for i = 1, #check[actionid].monsters do
            local pos = player:getPosition()
            local radius = 2
            print("Attempting to create monster: " .. check[actionid].monsters[i])
            Game.createMonster(check[actionid].monsters[i], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        player:setStorageValue(Storage.AMBUSH, check[actionid].ambush_reset*60+os.time())
    end
end

local function removeRubbish(pillarPos)
    local myTile = Tile(pillarPos)
    local itemsTile = myTile:getItems()
  
    for k, v in pairs(itemsTile) do
        v:remove()
    end
  
    return true
end

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(AMBUSH_TABLE[item.itemid])
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local actionid = tile:getActionId()
    local check = AMBUSH_TABLE[item.itemid]
    if player:getStorageValue(Storage.AMBUSH) <= os.time() then   
        local time = check[actionid].ambush_time
        addEvent(emboscada, time, cid.uid, position, actionid)
    end
    return true
end

And now I need to ask again: What am I doing wrong?
 
Okay main thing was line 54, where you weren't including the additional parameter for the function on line 15. (item)

I reworked a bit of your code to accomodate that information and smooth over some of the locals you were using.

Now let's go over something a bit more important.. the actionID's and uniqueID's.

Unique id's are great, but they are unique. Can only ever be used once, or you run into issues, which I beleive you've found out. (I personally think they are rubbish and rarely use them. :D)

Action id's are more useful, since you can use multiple of them on the map with the same number, but if you double-dip on a number you've used previously, all sorts of weird shit can happen. (basically human error = bad, like normal.)

So for your specific use-case, I'd suggest using actionID's on the tiles, and position parameters in your table.

make an imaginary square around your actionid tiles, and if your actionid tiles are in that area, then you know what monsters to use.

so, actionid on all tiles you want to trigger the ambush, top left corner, bottom right corner in script. (and no invisible item.)

You can put 1 actionid on every tile you want to trigger the ambush, and the ambush monsters will be decided inside table with invisible square.

Untitled.png


Which with these changes.. ironically undoes all the changes you made.. xD
Sorry.

But yeah, try this.
Lua:
AMBUSH_TABLE = {

    {   monsters = {"rotworm", "rotworm"},
        ambush_reset = 1, -- minutos
        ambush_time = 3000,
        top_left_corner = {x = 990, y = 990},
        bot_right_corner = {x = 1010, y = 1010}
    },     
  
    {   monsters = {"rat", "cave rat"},
        ambush_reset = x, -- minutos
        ambush_time = xxxx,
        top_left_corner = {x = 990, y = 990, z = 7},
        bot_right_corner = {x = 1010, y = 1010, z = 7}
    }
  
}

local function emboscada(cid, index)
    local player = Player(cid)
    if not player then
        return true
    end
    local check = AMBUSH_TABLE[index]
    local cur_time = os.time()
    if player:getStorageValue(Storage.AMBUSH) <= cur_time then 
        for i = 1, #check.monsters do
            local pos = player:getPosition()
            local radius = 2
            print("Attempting to create monster: " .. check.monsters[i])
            Game.createMonster(check.monsters[i], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        player:setStorageValue(Storage.AMBUSH, check.ambush_reset * 60 + cur_time)
    end
end

--[[
local function removeRubbish(pillarPos)
    local myTile = Tile(pillarPos)
    local itemsTile = myTile:getItems()
  
    for k, v in pairs(itemsTile) do
        v:remove()
    end
  
    return true
end
]]--

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.uid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local actionid = tile:getActionId()
    if player:getStorageValue(Storage.AMBUSH) <= os.time() then
        local index = 0
        for i = 1, #AMBUSH_TABLE do
            if position.z == AMBUSH_TABLE[i].top_left_corner.z then
                if position.y >= AMBUSH_TABLE[i].top_left_corner.y and position.y <= AMBUSH_TABLE[i].bot_right_corner.y then
                    if position.x >= AMBUSH_TABLE[i].top_left_corner.x and position.x <= AMBUSH_TABLE[i].bot_right_corner.x then
                        index = i
                        break
                    end
                end
            end
        end
        if index > 0 then
            local timer = AMBUSH_TABLE[item_id][actionid].ambush_time
            addEvent(emboscada, timer, cid.uid, index)
        else
            print("LUA ERROR: Ambush location not found in AMBUSH_TABLE .. Position("..position.x..", "..position.y..", "..position.z..")")
        end
    end
    return true
end
 
First of all, thanks so much @Xikini, and don't have problem to change it, I know you are changing it not only for work, but for better too!

BTW i don't know what i'm doing wrong... after edit the positions it become this:

Lua:
AMBUSH_TABLE = {

    {   monsters = {"skeleton", "rotworm"},
        ambush_reset = 1, -- minutos
        ambush_time = 3000,
        top_left_corner = {x = 32371, y = 32251, z = 9},
        bot_right_corner = {x = 32379, y = 32252, z = 9}
    },    

    {   monsters = {"rat", "cave rat"},
        ambush_reset = x, -- minutos
        ambush_time = xxxx,
        top_left_corner = {x = 990, y = 990, z = 7},
        bot_right_corner = {x = 1010, y = 1010, z = 7}
    }

}

local function emboscada(cid, index)
    local player = Player(cid)
    if not player then
        return true
    end
    local check = AMBUSH_TABLE[index]
    local cur_time = os.time()
    if player:getStorageValue(Storage.AMBUSH) <= cur_time then
        for i = 1, #check.monsters do
            local pos = player:getPosition()
            local radius = 2
            print("Attempting to create monster: " .. check.monsters[i])
            Game.createMonster(check.monsters[i], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        player:setStorageValue(Storage.AMBUSH, check.ambush_reset * 60 + cur_time)
    end
end

--[[
local function removeRubbish(pillarPos)
    local myTile = Tile(pillarPos)
    local itemsTile = myTile:getItems()

    for k, v in pairs(itemsTile) do
        v:remove()
    end

    return true
end
]]--

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.aid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local actionid = tile:getActionId()
    if player:getStorageValue(Storage.AMBUSH) <= os.time() then
        local index = 0
        for i = 1, #AMBUSH_TABLE do
            if position.z == AMBUSH_TABLE[i].top_left_corner.z then
                if position.y >= AMBUSH_TABLE[i].top_left_corner.y and position.y <= AMBUSH_TABLE[i].bot_right_corner.y then
                    if position.x >= AMBUSH_TABLE[i].top_left_corner.x and position.x <= AMBUSH_TABLE[i].bot_right_corner.x then
                        index = i
                        break
                    end
                end
            end
        end
        if index > 0 then
            local timer = AMBUSH_TABLE[item_id][actionid].ambush_time
            addEvent(emboscada, timer, cid.uid, index)
        else
            print("LUA ERROR: Ambush location not found in AMBUSH_TABLE .. Position("..position.x..", "..position.y..", "..position.z..")")
        end
    end
    return true
end

I changed local tile = Item(item.uid) to local tile = Item(item.aid). Since it's giving index nil value...

But nothing happens inside the game and nothing happens in console too... what am I doing wrong?

Look, this is my script inside movements.xml: <movevent event="StepOut" actionid="60005" script="explorations/map_ambushes.lua"/>

Also I put the AIDs randomly inside that position table.. (Maybe here is the problem? I don't think i really understood that part.. even with pics XD)

Thanks for helping me
 
First of all, thanks so much @Xikini, and don't have problem to change it, I know you are changing it not only for work, but for better too!

BTW i don't know what i'm doing wrong... after edit the positions it become this:

Lua:
AMBUSH_TABLE = {

    {   monsters = {"skeleton", "rotworm"},
        ambush_reset = 1, -- minutos
        ambush_time = 3000,
        top_left_corner = {x = 32371, y = 32251, z = 9},
        bot_right_corner = {x = 32379, y = 32252, z = 9}
    },   

    {   monsters = {"rat", "cave rat"},
        ambush_reset = x, -- minutos
        ambush_time = xxxx,
        top_left_corner = {x = 990, y = 990, z = 7},
        bot_right_corner = {x = 1010, y = 1010, z = 7}
    }

}

local function emboscada(cid, index)
    local player = Player(cid)
    if not player then
        return true
    end
    local check = AMBUSH_TABLE[index]
    local cur_time = os.time()
    if player:getStorageValue(Storage.AMBUSH) <= cur_time then
        for i = 1, #check.monsters do
            local pos = player:getPosition()
            local radius = 2
            print("Attempting to create monster: " .. check.monsters[i])
            Game.createMonster(check.monsters[i], Position(math.random(pos.x-radius, pos.x+radius), math.random(pos.y-radius, pos.y+radius), pos.z))
        end
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Você sofreu uma emboscada!")
        player:setStorageValue(Storage.AMBUSH, check.ambush_reset * 60 + cur_time)
    end
end

--[[
local function removeRubbish(pillarPos)
    local myTile = Tile(pillarPos)
    local itemsTile = myTile:getItems()

    for k, v in pairs(itemsTile) do
        v:remove()
    end

    return true
end
]]--

function onStepOut(cid, item, position, fromPosition)
    local tile = Item(item.aid)
    local player = Player(cid)
    if not tile or not player then
        return true
    end
    local actionid = tile:getActionId()
    if player:getStorageValue(Storage.AMBUSH) <= os.time() then
        local index = 0
        for i = 1, #AMBUSH_TABLE do
            if position.z == AMBUSH_TABLE[i].top_left_corner.z then
                if position.y >= AMBUSH_TABLE[i].top_left_corner.y and position.y <= AMBUSH_TABLE[i].bot_right_corner.y then
                    if position.x >= AMBUSH_TABLE[i].top_left_corner.x and position.x <= AMBUSH_TABLE[i].bot_right_corner.x then
                        index = i
                        break
                    end
                end
            end
        end
        if index > 0 then
            local timer = AMBUSH_TABLE[item_id][actionid].ambush_time
            addEvent(emboscada, timer, cid.uid, index)
        else
            print("LUA ERROR: Ambush location not found in AMBUSH_TABLE .. Position("..position.x..", "..position.y..", "..position.z..")")
        end
    end
    return true
end

I changed local tile = Item(item.uid) to local tile = Item(item.aid). Since it's giving index nil value...

But nothing happens inside the game and nothing happens in console too... what am I doing wrong?

Look, this is my script inside movements.xml: <movevent event="StepOut" actionid="60005" script="explorations/map_ambushes.lua"/>

Also I put the AIDs randomly inside that position table.. (Maybe here is the problem? I don't think i really understood that part.. even with pics XD)

Thanks for helping me
I think this is getting to the point where I need to actually test stuff on a server..
I don't know TFS 1.0+ at all, so a lot of things in the script I'm basically just guessing how they work and interact with each other.

Later today or tomorrow I'll figure out how to install tfs 1.3, cuz there's another thing I wanted to work on anyway.
Check your pm's as well.
Post automatically merged:

Found the problem over a discord call.

changed item.aid back to item.uid

and changed
Lua:
local timer = AMBUSH_TABLE[item_id][actionid].ambush_time
to
Lua:
local timer = AMBUSH_TABLE[index].ambush_time
 
Last edited:
Back
Top