• 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 TFS 1.1 Game.createMonster spawns duplicated creatures

Gaddhuve

Member
Joined
May 6, 2011
Messages
76
Solutions
1
Reaction score
19
Hi folks,

Im playing around in this script and when using Game.createMonster it spawns two of the same monster instead of just one. Ideas to what might cause this?
Code:
       local t = {
        effectposswitch = Position(1658, 1100, 11),
        effectposwall = Position(1645, 1099, 10),
        effectposcreature = Position(1662, 1099, 11)

      }
      local wallPos = {
            [1] = {x= 1645, y= 1099, z= 10, stackpos=1},
            [2] = {x= 1662, y= 1099, z= 11, stackpos=1}

        }

        local time_ = 40

        function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            local function reset()
            item:transform(1354)
                    Game.createItem(1497, 1, wallPos[1])
                    Game.createItem(4474, 1, wallPos[2])                   
                    Position(t.effectposswitch):sendMagicEffect(CONST_ME_ENERGYHIT)
                    Position(t.effectposwall):sendMagicEffect(CONST_ME_ICETORNADO)
                    Position(t.effectposcreature):sendMagicEffect(CONST_ME_STONES)
           
                end

            if item.itemid == 1304 then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "The stone has lost its power.")
                return false
            end
            item:transform(1304)
            addEvent(reset, time_ * 1000)
            for i = 1, #wallPos do
                doRemoveItem(getThingfromPos(wallPos[i]).uid)
                Position(t.effectposwall):sendMagicEffect(CONST_ME_TELEPORT)
                Position(t.effectposswitch):sendMagicEffect(CONST_ME_ENERGYHIT)
                Position(t.effectposcreature):sendMagicEffect(CONST_ME_STONES)
                Game.createMonster('Stone Golem', Position(1662, 1099, 11))               
            end
         
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "The mountain awakes to defend the stone!")
            return true
        end

Thanks in advance!
 
This will create only one monster:
PHP:
local t = {
effectposswitch = Position(1658, 1100, 11),
effectposwall = Position(1645, 1099, 10),
effectposcreature = Position(1662, 1099, 11)

}
local wallPos = {
    [1] = {x= 1645, y= 1099, z= 10, stackpos=1},
    [2] = {x= 1662, y= 1099, z= 11, stackpos=1}

}

local time_ = 40

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local function reset()
    item:transform(1354)
            Game.createItem(1497, 1, wallPos[1])
            Game.createItem(4474, 1, wallPos[2])                 
            Position(t.effectposswitch):sendMagicEffect(CONST_ME_ENERGYHIT)
            Position(t.effectposwall):sendMagicEffect(CONST_ME_ICETORNADO)
            Position(t.effectposcreature):sendMagicEffect(CONST_ME_STONES)
 
        end

    if item.itemid == 1304 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "The stone has lost its power.")
        return false
    end
    item:transform(1304)
    addEvent(reset, time_ * 1000)
    for i = 1, #wallPos do
        doRemoveItem(getThingfromPos(wallPos[i]).uid)
        Position(t.effectposwall):sendMagicEffect(CONST_ME_TELEPORT)
        Position(t.effectposswitch):sendMagicEffect(CONST_ME_ENERGYHIT)
        Position(t.effectposcreature):sendMagicEffect(CONST_ME_STONES)        
    end
    Game.createMonster('Stone Golem', Position(1662, 1099, 11))
    player:sendTextMessage(MESSAGE_STATUS_WARNING, "The mountain awakes to defend the stone!")
    return true
end

You spawned several because the Game.createMonster was located within the "for" stuffs, which made it create one monster for every thing the "for" was loading.
 
Back
Top