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

Error on warzone1 script final part

wafuboe

Member
Joined
Dec 24, 2010
Messages
882
Solutions
2
Reaction score
23
got this error when i clic on the crystal.
nmavlx.png

So this happen when i clic on the crystal the teleport instantly appears but it leads to nowhere. Also no monsterwaves are spawned.


Script:
Code:
local creatureNames, crystalPosition = { 'humongous fungus', 'hideous fungus' }, Position(810, 611, 15)

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

local function chargingText(cid, text, position)
    local player = Player(cid)
    player:say(text, TALKTYPE_MONSTER_SAY, false, player, position)
end

local function revertTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:transform(17999)
    end
end

local function clearArea(fromPosition, toPosition, bossName, exitPosition)
    for x = fromPosition.x, toPosition.x do
        for y = fromPosition.y, toPosition.y do
            for z = fromPosition.z, toPosition.z do
                local creature = Tile(Position(x, y, z)):getTopCreature()
                if creature then
                    if creature:isPlayer() then
                        creature:teleportTo(exitPosition)
                        exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                        creature:say('You were teleported out by the gnomish emergency device.', TALKTYPE_MONSTER_SAY)
                    end

                    if creature:isMonster() and creature:getName():lower() == bossName:lower() then
                        creature:remove()
                    end
                end
            end
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if Game.getStorageValue(GlobalStorage.Warzones) == 1 then
        return false
    end

    Game.setStorageValue(GlobalStorage.Warzones, 1)
    addEvent(Game.setStorageValue, 32 * 60 * 1000, GlobalStorage.Warzones, 0)
    local pos
    for i = 1, 6 do
        for k = 1, 10 do
            pos = Position(math.random(799, 604), math.random(802, 614), 15)
            addEvent(summonMonster, (i - 1) * 20000, creatureNames[math.random(#creatureNames)], pos)
        end
        addEvent(chargingText, (i - 1) * 20000, player.uid, 'The crystals are charging.', toPosition)
    end

    local crystalItem = Tile(crystalPosition):getItemById(17999)
    if crystalItem then
        crystalItem:transform(1387)
        addEvent(revertTeleport, 6 * 20 * 1000, crystalPosition)
    end

    addEvent(summonMonster, 6 * 20 * 1000, 'deathstrike', Position(814, 671, 15))
    addEvent(clearArea, 32 * 60 * 1000, Position(795, 649, 15), Position(833, 685, 15), 'deathstrike', Position(708, 621, 15))
    return true
end

Also i have a doubt..
Here in the positions, what actually it is? it is the area where fungus appears on warzone 1?
Code:
Game.setStorageValue(GlobalStorage.Warzones, 1)
    addEvent(Game.setStorageValue, 32 * 60 * 1000, GlobalStorage.Warzones, 0)
    local pos
    for i = 1, 6 do
        for k = 1, 10 do
            pos = Position(math.random(799, 604), math.random(802, 614), 15)
            addEvent(summonMonster, (i - 1) * 20000, creatureNames[math.random(#creatureNames)], pos)
        end
        addEvent(chargingText, (i - 1) * 20000, player.uid, 'The crystals are charging.', toPosition)
    end
 
Solution
I have to compile?
I put that just after local player =
only this error shows when clicking on crystal
i6gmqg.png

heres the script
Code:
local creatureNames, crystalPosition = { 'humongous fungus', 'hideous fungus' }, Position(810, 611, 15)

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

local function chargingText(cid, text, position)
    local player = Player(cid)
    if not player then
     return false
end
    player:say(text, TALKTYPE_MONSTER_SAY, false, player, position)
end

local function revertTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then...
In this line (54) change "player.uid" to "player"
Lua:
addEvent(chargingText, (i - 1) * 20000, player.uid, 'The crystals are charging.', toPosition)
 
You can't push a userdata value to scheduled events, so the fix is to use player:getId() and make sure that you either recompile the Player userdata in the function or use legacy functions that dosn't use the userdata value, best is to use option no 1.
But in your case chargingText already recompiles the Player userdata, but .... it dosn't check if it's valid or not, add an if statment after local player = ..
Lua:
if not player then
     return false
end
 
You can't push a userdata value to scheduled events, so the fix is to use player:getId() and make sure that you either recompile the Player userdata in the function or use legacy functions that dosn't use the userdata value, best is to use option no 1.
But in your case chargingText already recompiles the Player userdata, but .... it dosn't check if it's valid or not, add an if statment after local player = ..
Lua:
if not player then
     return false
end

I have to compile?
I put that just after local player =
only this error shows when clicking on crystal
i6gmqg.png

heres the script
Code:
local creatureNames, crystalPosition = { 'humongous fungus', 'hideous fungus' }, Position(810, 611, 15)

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

local function chargingText(cid, text, position)
    local player = Player(cid)
    if not player then
     return false
end
    player:say(text, TALKTYPE_MONSTER_SAY, false, player, position)
end

local function revertTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:transform(17999)
    end
end

local function clearArea(fromPosition, toPosition, bossName, exitPosition)
    for x = fromPosition.x, toPosition.x do
        for y = fromPosition.y, toPosition.y do
            for z = fromPosition.z, toPosition.z do
                local creature = Tile(Position(x, y, z)):getTopCreature()
                if creature then
                    if creature:isPlayer() then
                        creature:teleportTo(exitPosition)
                        exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                        creature:say('You were teleported out by the gnomish emergency device.', TALKTYPE_MONSTER_SAY)
                    end

                    if creature:isMonster() and creature:getName():lower() == bossName:lower() then
                        creature:remove()
                    end
                end
            end
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if Game.getStorageValue(GlobalStorage.Warzones) == 1 then
        return false
    end

    Game.setStorageValue(GlobalStorage.Warzones, 1)
    addEvent(Game.setStorageValue, 32 * 60 * 1000, GlobalStorage.Warzones, 0)
    local pos
    for i = 1, 6 do
        for k = 1, 10 do
            pos = Position(math.random(799, 604), math.random(802, 614), 15)
            addEvent(summonMonster, (i - 1) * 20000, creatureNames[math.random(#creatureNames)], pos)
        end
        addEvent(chargingText, (i - 1) * 20000, player, 'The crystals are charging.', toPosition)
    end

    local crystalItem = Tile(crystalPosition):getItemById(17999)
    if crystalItem then
        crystalItem:transform(1387)
        addEvent(revertTeleport, 6 * 20 * 1000, crystalPosition)
    end

    addEvent(summonMonster, 6 * 20 * 1000, 'deathstrike', Position(814, 671, 15))
    addEvent(clearArea, 32 * 60 * 1000, Position(795, 649, 15), Position(833, 685, 15), 'deathstrike', Position(708, 621, 15))
    return true
end
 
I have to compile?
I put that just after local player =
only this error shows when clicking on crystal
i6gmqg.png

heres the script
Code:
local creatureNames, crystalPosition = { 'humongous fungus', 'hideous fungus' }, Position(810, 611, 15)

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

local function chargingText(cid, text, position)
    local player = Player(cid)
    if not player then
     return false
end
    player:say(text, TALKTYPE_MONSTER_SAY, false, player, position)
end

local function revertTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:transform(17999)
    end
end

local function clearArea(fromPosition, toPosition, bossName, exitPosition)
    for x = fromPosition.x, toPosition.x do
        for y = fromPosition.y, toPosition.y do
            for z = fromPosition.z, toPosition.z do
                local creature = Tile(Position(x, y, z)):getTopCreature()
                if creature then
                    if creature:isPlayer() then
                        creature:teleportTo(exitPosition)
                        exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                        creature:say('You were teleported out by the gnomish emergency device.', TALKTYPE_MONSTER_SAY)
                    end

                    if creature:isMonster() and creature:getName():lower() == bossName:lower() then
                        creature:remove()
                    end
                end
            end
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if Game.getStorageValue(GlobalStorage.Warzones) == 1 then
        return false
    end

    Game.setStorageValue(GlobalStorage.Warzones, 1)
    addEvent(Game.setStorageValue, 32 * 60 * 1000, GlobalStorage.Warzones, 0)
    local pos
    for i = 1, 6 do
        for k = 1, 10 do
            pos = Position(math.random(799, 604), math.random(802, 614), 15)
            addEvent(summonMonster, (i - 1) * 20000, creatureNames[math.random(#creatureNames)], pos)
        end
        addEvent(chargingText, (i - 1) * 20000, player, 'The crystals are charging.', toPosition)
    end

    local crystalItem = Tile(crystalPosition):getItemById(17999)
    if crystalItem then
        crystalItem:transform(1387)
        addEvent(revertTeleport, 6 * 20 * 1000, crystalPosition)
    end

    addEvent(summonMonster, 6 * 20 * 1000, 'deathstrike', Position(814, 671, 15))
    addEvent(clearArea, 32 * 60 * 1000, Position(795, 649, 15), Position(833, 685, 15), 'deathstrike', Position(708, 621, 15))
    return true
end

Please read the rules; Rules for the Support board
#2

Lua:
local creatureNames, crystalPosition = { 'humongous fungus', 'hideous fungus' }, Position(810, 611, 15)

local function summonMonster(name, position)
    Game.createMonster(name, position)
    position:sendMagicEffect(CONST_ME_TELEPORT)
end

local function chargingText(cid, text, position)
    local player = Player(cid)
    if not player then
        return false
    end

    player:say(text, TALKTYPE_MONSTER_SAY, false, player, position)
end

local function revertTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:transform(17999)
    end
end

local function clearArea(fromPosition, toPosition, bossName, exitPosition)
    for x = fromPosition.x, toPosition.x do
        for y = fromPosition.y, toPosition.y do
            for z = fromPosition.z, toPosition.z do
                local creature = Tile(Position(x, y, z)):getTopCreature()
                if creature then
                    if creature:isPlayer() then
                        creature:teleportTo(exitPosition)
                        exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
                        creature:say('You were teleported out by the gnomish emergency device.', TALKTYPE_MONSTER_SAY)
                    end

                    if creature:isMonster() and creature:getName():lower() == bossName:lower() then
                        creature:remove()
                    end
                end
            end
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if Game.getStorageValue(GlobalStorage.Warzones) == 1 then
        return false
    end

    Game.setStorageValue(GlobalStorage.Warzones, 1)
    addEvent(Game.setStorageValue, 32 * 60 * 1000, GlobalStorage.Warzones, 0)
    local pos
    for i = 1, 6 do
        for k = 1, 10 do
            pos = Position(math.random(799, 604), math.random(802, 614), 15)
            addEvent(summonMonster, (i - 1) * 20000, creatureNames[math.random(#creatureNames)], pos)
        end
        addEvent(chargingText, (i - 1) * 20000, player:getId(), 'The crystals are charging.', toPosition)
    end

    local crystalItem = Tile(crystalPosition):getItemById(17999)
    if crystalItem then
        crystalItem:transform(1387)
        addEvent(revertTeleport, 6 * 20 * 1000, crystalPosition)
    end

    addEvent(summonMonster, 6 * 20 * 1000, 'deathstrike', Position(814, 671, 15))
    addEvent(clearArea, 32 * 60 * 1000, Position(795, 649, 15), Position(833, 685, 15), 'deathstrike', Position(708, 621, 15))
    return true
end

On line 58 you kept pushing a userdata value (player)
Lua:
addEvent(chargingText, (i - 1) * 20000, player, 'The crystals are charging.', toPosition)

The problem is as the error says, it's unsafe, so you need to use the getId() function.
Lua:
addEvent(chargingText, (i - 1) * 20000, player:getId(), 'The crystals are charging.', toPosition)
 
Solution
Back
Top Bottom