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

Spawn if the item have actionid = 15160 doesn’t spawn the item

Jean Dark

Member
Joined
Jan 6, 2019
Messages
38
Reaction score
14
Location
Unknow
TFS 0.4

I want to add checker in this script to check ( if the item have actionid = 15160 returns false and the script doesn’t spawn the item)

local t = {
items = {{9562,1,1},{9562,1,1}}, -- goes item, max item count, rarity (5-1. 5 being always, 1 being rare)
positions = {
{x = 2444, y = 961, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2436, y = 948, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2455, y = 946, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2459, y = 970, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2451, y = 974, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2438, y = 974, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2460, y = 984, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2433, y = 953, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2436, y = 934, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2432, y = 928, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2440, y = 919, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2458, y = 926, z = 6}, -- positions items can spawn, add more positions if needed
{x = 2412, y = 942, z = 6}, -- positions items can spawn, add more positions if needed
}
}


function onThink(interval)
local item = math.random(#t.items)
for a = 1, #t.positions do
if getTileItemById(t.positions[a], t.items[item][1]) ~= TRUE then
local amount = math.random(t.items[item][2])
if (math.random(99) <= t.items[item][3]) then
local itemZZ = doCreateItem(t.items[item][1], amount, t.positions[a])
doItemSetAttribute(itemZZ, "aid", 15160)
doBroadcastMessage("Demon tile has spawned somewhere on the bridge map! Be the first one to become a Demon! (+30% more HP!)", MESSAGE_STATUS_WARNING)
end
end
end
return true
end
 

Attachments

Last edited:
Solution
Try this
Lua:
local INDEX_ITEMID   = 1
local INDEX_MAXCOUNT = 2
local INDEX_CHANCE   = 3

local config = {
    message  = "Demon tile has spawned somewhere on the bridge map! Be the first one to become a Demon! (+30% more HP!)",
    actionId = 15160,

    items = {
        -- { itemId, max, %chance }
        {9562, 1, 100},
        {9562, 1, 100}
    },

    positions = {
        {x = 2444, y = 961, z = 6},
        {x = 2436, y = 948, z = 6},
        {x = 2455, y = 946, z = 6},
        {x = 2459, y = 970, z = 6},
        {x = 2451, y = 974, z = 6},
        {x = 2438, y = 974, z = 6},
        {x = 2460, y = 984, z = 6},
        {x = 2433, y = 953, z = 6},
        {x = 2436, y = 934, z = 6},
        {x = 2432, y = 928, z = 6},
        {x =...
Try this
Lua:
local INDEX_ITEMID   = 1
local INDEX_MAXCOUNT = 2
local INDEX_CHANCE   = 3

local config = {
    message  = "Demon tile has spawned somewhere on the bridge map! Be the first one to become a Demon! (+30% more HP!)",
    actionId = 15160,

    items = {
        -- { itemId, max, %chance }
        {9562, 1, 100},
        {9562, 1, 100}
    },

    positions = {
        {x = 2444, y = 961, z = 6},
        {x = 2436, y = 948, z = 6},
        {x = 2455, y = 946, z = 6},
        {x = 2459, y = 970, z = 6},
        {x = 2451, y = 974, z = 6},
        {x = 2438, y = 974, z = 6},
        {x = 2460, y = 984, z = 6},
        {x = 2433, y = 953, z = 6},
        {x = 2436, y = 934, z = 6},
        {x = 2432, y = 928, z = 6},
        {x = 2440, y = 919, z = 6},
        {x = 2458, y = 926, z = 6},
        {x = 2412, y = 942, z = 6},
    }
}

function onThink(interval)
    local randomItem = math.random(#config.items)
    for _, position in pairs(config.positions) do
        local tileItem = getTileItemById(position, config.items[randomItem][INDEX_ITEMID])
        if not tileItem or (not (tileItem.uid > 0)) then
            if math.random(1, 100) <= config.items[randomItem][INDEX_CHANCE] then
                local amount = math.random(config.items[randomItem][INDEX_MAXCOUNT])
                local itemX  = doCreateItem(config.items[randomItem][INDEX_ITEMID], amount, position)
                doItemSetAttribute(itemX, "aid", config.actionId)
                doBroadcastMessage(config.message, MESSAGE_STATUS_WARNING)
            end
        else
            doSendMagicEffect(position, CONST_ME_POFF)
        end
    end
    return true
end
 
Solution
Back
Top