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

TFS 1.2 Globalevent (spawn item) doesnt work

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
529
Reaction score
56
Hello so i making this code i though i made everything correctly but it doesnt spawn items around the map. Not sure what i did wrong (no errors in console tho)
Lua:
local areas = {
    positions = {
        Position(218, 113, 7),
        Position(312, 339, 7),
        Position(282, 200, 7)
    }
  
}

function onThink(interval)
    if not items or not next(items) then
        return true
    end

    local itemId = items[math.random(#items)]
    local position = areas.positions[math.random(#areas.positions)]

    local item = Game.createItem(itemId, 1, position)
    if not item then
        return true
    end

    broadcastMessage(string.format("Item was spawned somewhere", MESSAGE_STATUS_WARNING))
    return true
end
 
Solution
there's no table items, unless you didn't add it,
Code:
local items = {itemid1, itemid2, itemid3}
local areas = {
    positions = {
        Position(218, 113, 7),
        Position(312, 339, 7),
        Position(282, 200, 7)
    }
  
}

function onThink(interval)
    if not items or not next(items) then
        return true
    end

    local itemId = items[math.random(#items)]
    local position = areas.positions[math.random(#areas.positions)]

    local item = Game.createItem(itemId, 1, position)
    if not item then
        return true
    end

    broadcastMessage(string.format("Item was spawned somewhere", MESSAGE_STATUS_WARNING))
    return true
end
Does your items table exist somewhere?

Because if not..

The very first line will return nil, and make nothing happen.
 
there's no table items, unless you didn't add it,
Code:
local items = {itemid1, itemid2, itemid3}
local areas = {
    positions = {
        Position(218, 113, 7),
        Position(312, 339, 7),
        Position(282, 200, 7)
    }
  
}

function onThink(interval)
    if not items or not next(items) then
        return true
    end

    local itemId = items[math.random(#items)]
    local position = areas.positions[math.random(#areas.positions)]

    local item = Game.createItem(itemId, 1, position)
    if not item then
        return true
    end

    broadcastMessage(string.format("Item was spawned somewhere", MESSAGE_STATUS_WARNING))
    return true
end
 
Solution
I think some of the LUA questions in OTLand support could be handled by sharing some basic coding techniques

For example this kind of thing could be easily picked up by inserting temporary "write to stdout" instructions (I assume LUA can do this?).
Or maybe, since it's being tested in OT anyway, spawn and use a "codeCommentMonster" instead :)
 
there's no table items, unless you didn't add it,
Code:
local items = {itemid1, itemid2, itemid3}
local areas = {
    positions = {
        Position(218, 113, 7),
        Position(312, 339, 7),
        Position(282, 200, 7)
    }
 
}

function onThink(interval)
    if not items or not next(items) then
        return true
    end

    local itemId = items[math.random(#items)]
    local position = areas.positions[math.random(#areas.positions)]

    local item = Game.createItem(itemId, 1, position)
    if not item then
        return true
    end

    broadcastMessage(string.format("Item was spawned somewhere", MESSAGE_STATUS_WARNING))
    return true
end

Hello!

Is it possible to TFS 0.4 ?
 
what are you looking for? and i'll have to look

I got this:

Lua:
doCreateItem(25457, 1, table.random({{x = 3347, y = 810, z = 6}}))

But i need "random frompos topos", somethink like:

Lua:
doCreateItem(25457, 1, table.random({frompos{x = 3347, y = 810, z = 6}, topos{x = 3347, y = 810, z = 6}}))

But i dont know how to use frompos topos



--------------

Done!

I used:

Lua:
local fromPos = {x=3345, y=808, z=6}
local toPos = {x=3350, y=812, z=6}
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
doCreateItem(25457, 1, pos)
 
Last edited:
Back
Top