• 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 0.X] Anihilator issue

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
What could be wrong with this anihilator script? Trying to change to this one to clear room after quest (when a new team goes) and prevent to enter if has a team doing, but gotting error:

2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:37 -
2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:37 -
2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:37 -
2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:37 -
2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:37 -
2022-11-10 08:47:37 - [Error - Action Interface]
2022-11-10 08:47:37 - data/actions/scripts/annihilator.lua:eek:nUse
2022-11-10 08:47:37 - Description:
2022-11-10 08:47:37 - (luaDoCreateMonster) Cannot create monster: Demon
2022-11-10 08:47:48 -
2022-11-10 08:47:48 - [Error - Action Interface]
2022-11-10 08:47:48 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:47:48 - Description:
2022-11-10 08:47:48 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:47:48 - stack traceback:
2022-11-10 08:47:48 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 08:47:49 -
2022-11-10 08:47:49 - [Error - Action Interface]
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:47:49 - Description:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:47:49 - stack traceback:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 08:47:49 -
2022-11-10 08:47:49 - [Error - Action Interface]
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:47:49 - Description:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:47:49 - stack traceback:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 08:47:49 -
2022-11-10 08:47:49 - [Error - Action Interface]
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:47:49 - Description:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:47:49 - stack traceback:
2022-11-10 08:47:49 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 08:48:10 -
2022-11-10 08:48:10 - [Error - Action Interface]
2022-11-10 08:48:10 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:48:10 - Description:
2022-11-10 08:48:10 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:48:10 - stack traceback:
2022-11-10 08:48:10 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 08:48:12 -
2022-11-10 08:48:12 - [Error - Action Interface]
2022-11-10 08:48:12 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 08:48:12 - Description:
2022-11-10 08:48:12 - data/actions/scripts/quests/quests.lua:13: attempt to compare boolean with number
2022-11-10 08:48:12 - stack traceback:
2022-11-10 08:48:12 - data/actions/scripts/quests/quests.lua:13: in function <data/actions/scripts/quests/quests.lua:1>
Lua:
-- Annihilator by Shawak v2.1

        -- CONFIG --

        local room = {     -- room with demons
        fromX = 188,
        fromY = 115,
        fromZ = 10,
        --------------
        toX = 197,
        toY = 121,
        toZ = 10
        }

        local monster_pos = {
        [1] = {pos = {195, 118, 10}, monster = "Demon"},
        [2] = {pos = {196, 118, 10}, monster = "Demon"},
        [3] = {pos = {194, 120, 10}, monster = "Demon"},
        [4] = {pos = {192, 120, 10}, monster = "Demon"},
        [5] = {pos = {193, 116, 10}, monster = "Demon"},
        [6] = {pos = {191, 116, 10}, monster = "Demon"}
        }

        local players_pos = {
        {x = 191, y =118, z = 9, stackpos = 253},
        {x = 192, y =118, z = 9, stackpos = 253},
        {x = 193, y =118, z = 9, stackpos = 253},
        {x = 194, y =118, z = 9, stackpos = 253}
        }

        local new_player_pos = {
        {x = 191, y = 118, z = 10},
        {x = 192, y = 118, z = 10},
        {x = 193, y = 118, z = 10},
        {x = 194, y = 118, z = 10}
        }

        local playersOnly = "yes"
        local questLevel = 100

        ------------------------------------------------------
        --- CONFIG END ---------------------------------------
        ------------------------------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local all_ready, monsters, player, level = 0, 0, {}, 0
        if item.uid == 9006 then
                for i = 1, #players_pos do
                        table.insert(player, 0)
                end
                for i = 1, #players_pos do
                        player[i] = getThingfromPos(players_pos[i])
                        if player[i].itemid > 0 then
                                if string.lower(playersOnly) == "yes" then
                                        if isPlayer(player[i].uid) == TRUE then
                                                all_ready = all_ready+1
                                        else
                                                monsters = monsters+1
                                        end
                                else
                                        all_ready = all_ready+1
                                end
                        end
                end
                if all_ready == #players_pos then
                        for i = 1, #players_pos do
                                player[i] = getThingfromPos(players_pos[i])
                                if isPlayer(player[i].uid) == TRUE then
                                        if getPlayerLevel(player[i].uid) >= questLevel then
                                                level = level+1
                                        end
                                else
                                        level = level+1
                                end
                        end
                        if level == #players_pos then
                                if string.lower(playersOnly) == "yes" and monsters == 0 or string.lower(playersOnly) == "no" then
                                        for _, area in pairs(monster_pos) do
                                                        doCreateMonster(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]})
                                        end
                                        for i = 1, #players_pos do
                                                doSendMagicEffect(players_pos[i], CONST_ME_POFF)
                                                doTeleportThing(player[i].uid, new_player_pos[i], FALSE)
                                                doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                                doTransformItem(item.uid,1946)
                                        end
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can do this quest.")
                                end
                        else
                                doPlayerSendTextMessage(cid,19,"All Players have to be level "..questLevel.." to do this quest.")
                        end
                else
                        doPlayerSendTextMessage(cid,19,"You need "..table.getn(players_pos).." players to do this quest.")
                end
        elseif item.itemid == 1946 then
                local player_room = 0
                for x = room.fromX, room.toX do
                        for y = room.fromY, room.toY do
                                for z = room.fromZ, room.toZ do
                                        local pos = {x=x, y=y, z=z,stackpos = 253}
                                        local thing = getThingfromPos(pos)
                                        if thing.itemid > 0 then
                                                if isPlayer(thing.uid) == TRUE then
                                                        player_room = player_room+1
                                                end
                                        end
                                end
                        end
                end
    elseif item.uid == 9007 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a demon armor.")
            doPlayerAddItem(cid,2494,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9008 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a magic sword.")
            doPlayerAddItem(cid,2400,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9009 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a stonecutter axe.")
            doPlayerAddItem(cid,2431,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9010 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found thunder hammer.")
            doPlayerAddItem(cid,2421,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
                if player_room >= 1 then
                        doPlayerSendTextMessage(cid,19,"There is already a team in the quest room.")        
                elseif player_room == 0 then
                        for x = room.fromX, room.toX do
                                for y = room.fromY, room.toY do
                                        for z = room.fromZ, room.toZ do
                                                local pos = {x=x, y=y, z=z,stackpos = 253}
                                                local thing = getThingfromPos(pos)
                                                if thing.itemid > 0 then
                                                        doRemoveCreature(thing.uid)
                                                end
                                        end
                                end
                        end
    local itemId = item.itemid
    if itemId == 1945 or itemId == 1946 then
        doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
                end
        end
        return TRUE
end

My quests.lua

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getBooleanFromString(getConfigValue('enableProtectionQuestForGM'))) then
        if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF, cid)
            return true
        end
    end

    if item.uid > 1000 and item.uid < 11395 then
        local itemWeight = getItemWeightById(item.uid, 1)
        local playerCap = getPlayerFreeCap(cid)
        if getPlayerStorageValue(cid, item.uid) == -1 then
            if playerCap >= itemWeight then
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemNameById(item.uid) .. '.')
                doPlayerAddItem(cid, item.uid , 1)
                setPlayerStorageValue(cid, item.uid, 1)
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have found a ' .. getItemNameById(item.uid) .. ' weighing ' .. itemWeight .. ' oz it\'s too heavy.')
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
        end
    else
        return false
    end

    return true
end
 
Solution
Your former script
Lua:
local config = {

    leverId = 9006, -- actionId
    rewards = {
        -- actionId, rewards
        [9007] = {2494, 1},
        [9008] = {2400, 1},
        [9009] = {2431, 1},
        [9010] = {2421, 1},

        storage = 5000
    },

    questLevel = 100,
    roomPosition = {from = {x=0,y=0,z=0}, to = {x=0,y=0,z=0}},

    playerPositions = {
        {start = {x=191, y=118, z=9}, destination = {x=191, y=118, z=10}},
        {start = {x=192, y=118, z=9}, destination = {x=192, y=118, z=10}},
        {start = {x=193, y=118, z=9}, destination = {x=193, y=118, z=10}},
        {start = {x=194, y=118, z=9}, destination = {x=194, y=118, z=10}}
    },

    spawnMonsters = {
        {position = {x=195, y=118, z=10}, monster =...
your positions are wrong

Lua:
 local monster_pos = {
        [1] = {pos = {195, 118, 10}, monster = "Demon"},
        [2] = {pos = {196, 118, 10}, monster = "Demon"},
        [3] = {pos = {194, 120, 10}, monster = "Demon"},
        [4] = {pos = {192, 120, 10}, monster = "Demon"},
        [5] = {pos = {193, 116, 10}, monster = "Demon"},
        [6] = {pos = {191, 116, 10}, monster = "Demon"}
to
Code:
     local monster_pos = {
        [1] = {pos = {33219, 31657, 13}, monster = "Demon"},
        [2] = {pos = {33221, 31657, 13}, monster = "Demon"},
        [3] = {pos = {33220, 31661, 13}, monster = "Demon"},
        [4] = {pos = {33222, 31661, 13}, monster = "Demon"},
        [5] = {pos = {33223, 31659, 13}, monster = "Demon"},
        [6] = {pos = {33224, 31659, 13}, monster = "Demon"}
        }
 
your positions are wrong

Lua:
 local monster_pos = {
        [1] = {pos = {195, 118, 10}, monster = "Demon"},
        [2] = {pos = {196, 118, 10}, monster = "Demon"},
        [3] = {pos = {194, 120, 10}, monster = "Demon"},
        [4] = {pos = {192, 120, 10}, monster = "Demon"},
        [5] = {pos = {193, 116, 10}, monster = "Demon"},
        [6] = {pos = {191, 116, 10}, monster = "Demon"}
to
Code:
     local monster_pos = {
        [1] = {pos = {33219, 31657, 13}, monster = "Demon"},
        [2] = {pos = {33221, 31657, 13}, monster = "Demon"},
        [3] = {pos = {33220, 31661, 13}, monster = "Demon"},
        [4] = {pos = {33222, 31661, 13}, monster = "Demon"},
        [5] = {pos = {33223, 31659, 13}, monster = "Demon"},
        [6] = {pos = {33224, 31659, 13}, monster = "Demon"}
        }
its not a global server, my positions are correct, im using a custom map ^^
 
Quests.lua
Line: local itemWeight = getItemWeightById(item.uid, 1)
Change item.uid to item.itemid

Annihilator.lua
Seems like positions are wrong or maybe tiles has protection zone or idk

You can see the source of the error here:
C++:
    if(!g_game.placeCreature(monster, pos, extend, force))
    {
        delete monster;
        errorEx("Cannot create monster: " + name);

        lua_pushboolean(L, false);
        return 1;
    }

Try by forcing the monster to spawn and verify the tile positions and conditions
Lua:
doCreateMonster(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]}, false, true)
 
Quests.lua
Line: local itemWeight = getItemWeightById(item.uid, 1)
Change item.uid to item.itemid

Annihilator.lua
Seems like positions are wrong or maybe tiles has protection zone or idk

You can see the source of the error here:
C++:
    if(!g_game.placeCreature(monster, pos, extend, force))
    {
        delete monster;
        errorEx("Cannot create monster: " + name);

        lua_pushboolean(L, false);
        return 1;
    }

Try by forcing the monster to spawn and verify the tile positions and conditions
Lua:
doCreateMonster(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]}, false, true)
Get better, but when i click on reward chest:

2022-11-10 19:21:14 - [Error - Action Interface]
2022-11-10 19:21:14 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 19:21:14 - Description:
2022-11-10 19:21:14 - data/lib/100-shortcut.lua:260: attempt to index a boolean value
2022-11-10 19:21:14 - stack traceback:
2022-11-10 19:21:14 - data/lib/100-shortcut.lua:260: in function 'getItemNameById'
2022-11-10 19:21:14 - data/actions/scripts/quests/quests.lua:14: in function <data/actions/scripts/quests/quests.lua:1>
2022-11-10 19:21:15 -
2022-11-10 19:21:15 - [Error - Action Interface]
2022-11-10 19:21:15 - data/actions/scripts/quests/quests.lua:eek:nUse
2022-11-10 19:21:15 - Description:
2022-11-10 19:21:15 - data/lib/100-shortcut.lua:260: attempt to index a boolean value
2022-11-10 19:21:15 - stack traceback:
2022-11-10 19:21:15 - data/lib/100-shortcut.lua:260: in function 'getItemNameById'
2022-11-10 19:21:15 - data/actions/scripts/quests/quests.lua:14: in function <data/actions/scripts/quests/quests.lua:1>
 
Oops I didnt read the script, just focused on the line error

Revert this change
Code:
Quests.lua
Line: local itemWeight = getItemWeightById(item.uid, 1)
Change item.uid to item.itemid

Quests.lua should work fine just make sure the uniqueId on the chest actually matchs an existing item id
If you are completely sure you are setting an existing item id then post your getItemWeightById function
 
Oops I didnt read the script, just focused on the line error

Revert this change
Code:
Quests.lua
Line: local itemWeight = getItemWeightById(item.uid, 1)
Change item.uid to item.itemid

Quests.lua should work fine just make sure the uniqueId on the chest actually matchs an existing item id
If you are completely sure you are setting an existing item id then post your getItemWeightById function
Sure, i have tried to merge my old anihi script with new one, i guess i mess up codes in incorrect position of codes.
Clean room its not working (when a new team try to do), its just stacking more demons.

This is the clean room code
Lua:
             if player_room >= 1 then
                        doPlayerSendTextMessage(cid,19,"There is already a team in the quest room.")      
                elseif player_room == 0 then
                        for x = room.fromX, room.toX do
                                for y = room.fromY, room.toY do
                                        for z = room.fromZ, room.toZ do
                                                local pos = {x=x, y=y, z=z,stackpos = 253}
                                                local thing = getThingfromPos(pos)
                                                if thing.itemid > 0 then
                                                        doRemoveCreature(thing.uid)
                                                end


My entire script:

Lua:
-- Annihilator by Shawak v2.1

        -- CONFIG --

        local room = {     -- room with demons
        fromX = 188,
        fromY = 115,
        fromZ = 10,
        --------------
        toX = 197,
        toY = 121,
        toZ = 10
        }

        local monster_pos = {
        [1] = {pos = {195, 118, 10}, monster = "Demon"},
        [2] = {pos = {196, 118, 10}, monster = "Demon"},
        [3] = {pos = {194, 120, 10}, monster = "Demon"},
        [4] = {pos = {192, 120, 10}, monster = "Demon"},
        [5] = {pos = {193, 116, 10}, monster = "Demon"},
        [6] = {pos = {191, 116, 10}, monster = "Demon"}
        }

        local players_pos = {
        {x = 191, y =118, z = 9, stackpos = 253},
        {x = 192, y =118, z = 9, stackpos = 253},
        {x = 193, y =118, z = 9, stackpos = 253},
        {x = 194, y =118, z = 9, stackpos = 253}
        }

        local new_player_pos = {
        {x = 191, y = 118, z = 10},
        {x = 192, y = 118, z = 10},
        {x = 193, y = 118, z = 10},
        {x = 194, y = 118, z = 10}
        }

        local playersOnly = "yes"
        local questLevel = 100

        ------------------------------------------------------
        --- CONFIG END ---------------------------------------
        ------------------------------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local all_ready, monsters, player, level = 0, 0, {}, 0
        if item.uid == 9006 then
                for i = 1, #players_pos do
                        table.insert(player, 0)
                end
                for i = 1, #players_pos do
                        player[i] = getThingfromPos(players_pos[i])
                        if player[i].itemid > 0 then
                                if string.lower(playersOnly) == "yes" then
                                        if isPlayer(player[i].uid) == TRUE then
                                                all_ready = all_ready+1
                                        else
                                                monsters = monsters+1
                                        end
                                else
                                        all_ready = all_ready+1
                                end
                        end
                end
                if all_ready == #players_pos then
                        for i = 1, #players_pos do
                                player[i] = getThingfromPos(players_pos[i])
                                if isPlayer(player[i].uid) == TRUE then
                                        if getPlayerLevel(player[i].uid) >= questLevel then
                                                level = level+1
                                        end
                                else
                                        level = level+1
                                end
                        end
                        if level == #players_pos then
                                if string.lower(playersOnly) == "yes" and monsters == 0 or string.lower(playersOnly) == "no" then
                                        for _, area in pairs(monster_pos) do
                                                        doCreateMonster(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]}, false, true)
                                        end
                                        for i = 1, #players_pos do
                                                doSendMagicEffect(players_pos[i], CONST_ME_POFF)
                                                doTeleportThing(player[i].uid, new_player_pos[i], FALSE)
                                                doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                                doTransformItem(item.uid,1946)
                                        end
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can do this quest.")
                                end
                        else
                                doPlayerSendTextMessage(cid,19,"All Players have to be level "..questLevel.." to do this quest.")
                        end
                else
                        doPlayerSendTextMessage(cid,19,"You need "..table.getn(players_pos).." players to do this quest.")
                end
        elseif item.itemid == 1946 then
                local player_room = 0
                for x = room.fromX, room.toX do
                        for y = room.fromY, room.toY do
                                for z = room.fromZ, room.toZ do
                                        local pos = {x=x, y=y, z=z,stackpos = 253}
                                        local thing = getThingfromPos(pos)
                                        if thing.itemid > 0 then
                                                if isPlayer(thing.uid) == TRUE then
                                                        player_room = player_room+1
                                                end
                                        end
                                end
                        end
                end
    elseif item.uid == 9007 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a demon armor.")
            doPlayerAddItem(cid,2494,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9008 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a magic sword.")
            doPlayerAddItem(cid,2400,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9009 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a stonecutter axe.")
            doPlayerAddItem(cid,2431,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9010 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found thunder hammer.")
            doPlayerAddItem(cid,2421,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
                if player_room >= 1 then
                        doPlayerSendTextMessage(cid,19,"There is already a team in the quest room.")      
                elseif player_room == 0 then
                        for x = room.fromX, room.toX do
                                for y = room.fromY, room.toY do
                                        for z = room.fromZ, room.toZ do
                                                local pos = {x=x, y=y, z=z,stackpos = 253}
                                                local thing = getThingfromPos(pos)
                                                if thing.itemid > 0 then
                                                        doRemoveCreature(thing.uid)
                                                end
                                        end
                                end
                        end
    local itemId = item.itemid
    if itemId == 1945 or itemId == 1946 then
        doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
                end
        end
        return TRUE
end
end
Post automatically merged:

My former script

Lua:
function onUse(cid, item, frompos, item2, topos)
    if item.uid == 9006 then
        local count = 0
        local config = {
            questLevel = 100,
            playerPositions = {
                {start = {x=191, y=118, z=9}, destination = {x=191, y=118, z=10}},
                {start = {x=192, y=118, z=9}, destination = {x=192, y=118, z=10}},
                {start = {x=193, y=118, z=9}, destination = {x=193, y=118, z=10}},
                {start = {x=194, y=118, z=9}, destination = {x=194, y=118, z=10}}
            },
            spawnMonsters = {
                {position = {x=195, y=118, z=10}, monster = "Demon"},
                {position = {x=196, y=118, z=10}, monster = "Demon"},
                {position = {x=194, y=120, z=10}, monster = "Demon"},
                {position = {x=192, y=120, z=10}, monster = "Demon"},
                {position = {x=189, y=118, z=10}, monster = "Demon"},
                {position = {x=191, y=116, z=10}, monster = "Demon"},
                {position = {x=193, y=116, z=10}, monster = "Demon"}
            }
        }
        local players = {}
        for i = 1, #config.playerPositions do
            local pid = getTopCreature(config.playerPositions[i].start)
            if pid.uid > 0 then
                if isPlayer(pid.uid) then
                    if getPlayerLevel(pid.uid) >= config.questLevel then
                        table.insert(players, pid.uid)
                    end
                end
            end
        end
        if #players == #config.playerPositions then
            for i = 1, #players do
                doTeleportThing(players[i], config.playerPositions[i].destination)
                doSendMagicEffect(config.playerPositions[i].destination, CONST_ME_TELEPORT)
            end
            for v = 1, #config.spawnMonsters do
                doCreateMonster(config.spawnMonsters[v].monster, config.spawnMonsters[v].position)
                doSendMagicEffect(config.spawnMonsters[v].position, CONST_ME_TELEPORT)
            end
        else
            doPlayerSendCancel(cid, "Sorry, not possible.")
        end
    elseif item.uid == 9007 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a demon armor.")
            doPlayerAddItem(cid,2494,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9008 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a magic sword.")
            doPlayerAddItem(cid,2400,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9009 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a stonecutter axe.")
            doPlayerAddItem(cid,2431,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    elseif item.uid == 9010 then
        queststatus = getPlayerStorageValue(cid,5000)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found thunder hammer.")
            doPlayerAddItem(cid,2421,1)
            setPlayerStorageValue(cid,5000,1)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.")
        end
    end
    local itemId = item.itemid
    if itemId == 1945 or itemId == 1946 then
        doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    end
    return true
end
 
Your former script
Lua:
local config = {

    leverId = 9006, -- actionId
    rewards = {
        -- actionId, rewards
        [9007] = {2494, 1},
        [9008] = {2400, 1},
        [9009] = {2431, 1},
        [9010] = {2421, 1},

        storage = 5000
    },

    questLevel = 100,
    roomPosition = {from = {x=0,y=0,z=0}, to = {x=0,y=0,z=0}},

    playerPositions = {
        {start = {x=191, y=118, z=9}, destination = {x=191, y=118, z=10}},
        {start = {x=192, y=118, z=9}, destination = {x=192, y=118, z=10}},
        {start = {x=193, y=118, z=9}, destination = {x=193, y=118, z=10}},
        {start = {x=194, y=118, z=9}, destination = {x=194, y=118, z=10}}
    },

    spawnMonsters = {
        {position = {x=195, y=118, z=10}, monster = "Demon"},
        {position = {x=196, y=118, z=10}, monster = "Demon"},
        {position = {x=194, y=120, z=10}, monster = "Demon"},
        {position = {x=192, y=120, z=10}, monster = "Demon"},
        {position = {x=189, y=118, z=10}, monster = "Demon"},
        {position = {x=191, y=116, z=10}, monster = "Demon"},
        {position = {x=193, y=116, z=10}, monster = "Demon"}
    },

    kickTime = 5 * 60, -- 0 to disable kick
    kickPosition = {x=0, y=0, z=0},

    lastEventId = 0
}

function getCreaturesOnRoom()

    local creatures = {}
    creatures.monsters = {}
    creatures.players = {}

    for x = config.roomPosition.from.x, config.roomPosition.to.x do
        for y = config.roomPosition.from.y, config.roomPosition.to.y do
            local thing = getTopCreature({x = x, y = y, z = config.roomPosition.to.z})
            if thing.uid > 0 then
                local type = isPlayer(thing.uid) and "players" or "monsters"
                creatures[type][#creatures[type] + 1] = thing.uid
            end
        end
    end

    return creatures
end

function resetRoom(creatures)

    creatures = creatures or getCreaturesOnRoom()
    if #creatures.monsters > 0 then
        for i = 1, #creatures.monsters do
            local monster = creatures.monsters[i]
            if isCreature(monster) then
                doRemoveCreature(monster)
            end
        end
    end

    if #creatures.players > 0 then
        for i = 1, #creatures.players do
            local pid = creatures.players[i]
            if isPlayer(pid) then
                doTeleportThing(pid, config.kickPosition)
                doSendMagicEffect(getThingPos(pid), CONST_ME_TELEPORT)
            end
        end
    end
end

function onUse(cid, item, frompos, item2, topos)

    -- rewards
    local reward = config.rewards[item.aid]
    if reward then

        if getPlayerStorageValue(cid, config.rewards.storage) == 1 then
            return doPlayerSendTextMessage(cid, 22, "It is empty.")
        end

        local rewardId = reward[1]
        local itemType = getItemInfo(rewardId)
        doPlayerAddItem(cid, rewardId, 1)

        setPlayerStorageValue(cid, config.rewards.storage, 1)
        return doPlayerSendTextMessage(cid,22, "You have found " .. (itemType.article ~= "" and itemType.article.. " " or "") .. itemType.name:lower() .. ".")
    end

    -- lever item
    local players = {}
    for i = 1, #config.playerPositions do
        local pid = getTopCreature(config.playerPositions[i].start)
        if pid.uid <= 0 then
            break
        end

        if isPlayer(pid.uid) then
            if getPlayerLevel(pid.uid) >= config.questLevel then
                table.insert(players, pid.uid)
            end
        end
    end

    if #players ~= #config.playerPositions then
        return doPlayerSendCancel(cid, "Sorry, not possible.")
    end

    local creatures = getCreaturesOnRoom()
    if #creatures.players > 0 then
        return doPlayerSendCancel(cid, "There are players inside.")
    end

    if #creatures.monsters > 0 then
        resetRoom(creatures)
    end

    for i = 1, #players do
        doTeleportThing(players[i], config.playerPositions[i].destination)
        doSendMagicEffect(config.playerPositions[i].destination, CONST_ME_TELEPORT)
    end

    for v = 1, #config.spawnMonsters do
        doCreateMonster(config.spawnMonsters[v].monster, config.spawnMonsters[v].position)
        doSendMagicEffect(config.spawnMonsters[v].position, CONST_ME_TELEPORT)
    end

    if config.kickTime > 0 then
        stopEvent(config.lastEventId)
        config.lastEventId = addEvent(resetRoom, config.kickTime * 1000)
    end

    return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
Last edited:
Solution
Your former script
Lua:
local config = {

    questLevel = 100,
    roomPosition = {from = {x=0,y=0,z=0}, to = {x=0,y=0,z=0}},

    playerPositions = {
        {start = {x=191, y=118, z=9}, destination = {x=191, y=118, z=10}},
        {start = {x=192, y=118, z=9}, destination = {x=192, y=118, z=10}},
        {start = {x=193, y=118, z=9}, destination = {x=193, y=118, z=10}},
        {start = {x=194, y=118, z=9}, destination = {x=194, y=118, z=10}}
    },

    spawnMonsters = {
        {position = {x=195, y=118, z=10}, monster = "Demon"},
        {position = {x=196, y=118, z=10}, monster = "Demon"},
        {position = {x=194, y=120, z=10}, monster = "Demon"},
        {position = {x=192, y=120, z=10}, monster = "Demon"},
        {position = {x=189, y=118, z=10}, monster = "Demon"},
        {position = {x=191, y=116, z=10}, monster = "Demon"},
        {position = {x=193, y=116, z=10}, monster = "Demon"}
    },

    kickTime = 5 * 60, -- 0 to disable kick
    kickPosition = {x=0, y=0, z=0},

    lastEventId = 0
}

function getCreaturesOnRoom()

    local creatures = {}
    creatures.monsters = {}
    creatures.players = {}

    for x = config.roomPosition.from.x, config.roomPosition.to.x do
        for y = config.roomPosition.from.y, config.roomPosition.to.y do
            local thing = getTopCreature({x = x, y = y, z = config.roomPosition.to.z,})
            if thing.uid > 0 then
                local type = isPlayer(thing.uid) and "players" or "monsters"
                creatures[type][#creatures[type] + 1] = thing.uid
            end
        end
    end

    return creatures
end

function resetRoom(creatures)

    creatures = creatures or getCreaturesOnRoom()
    if #creatures.monsters > 0 then
        for i = 1, #creatures.monsters do
            local monster = creatures.monsters[i]
            if isCreature(monster) then
                doRemoveCreature(monster)
            end
        end
    end

    if #creatures.players > 0 then
        for i = 1, #creatures.players do
            local pid = creatures.players[i]
            if isPlayer(pid) then
                doTeleportThing(pid, config.kickPosition)
                doSendMagicEffect(getThingPos(pid), CONST_ME_TELEPORT)
            end
        end
    end
end

function onUse(cid, item, frompos, item2, topos)

    local players = {}
    for i = 1, #config.playerPositions do
        local pid = getTopCreature(config.playerPositions[i].start)
        if pid.uid <= 0 then
            break
        end
      
        if isPlayer(pid.uid) then
            if getPlayerLevel(pid.uid) >= config.questLevel then
                table.insert(players, pid.uid)
            end
        end
    end

    if #players ~= #config.playerPositions then
        return doPlayerSendCancel(cid, "Sorry, not possible.")
    end

    local creatures = getCreaturesOnRoom()
    if #creatures.players > 0 then
        return doPlayerSendCancel(cid, "There are players inside.")
    end

    if #creatures.monsters > 0 then
        resetRoom(creatures)
    end

    for i = 1, #players do
        doTeleportThing(players[i], config.playerPositions[i].destination)
        doSendMagicEffect(config.playerPositions[i].destination, CONST_ME_TELEPORT)
    end

    for v = 1, #config.spawnMonsters do
        doCreateMonster(config.spawnMonsters[v].monster, config.spawnMonsters[v].position)
        doSendMagicEffect(config.spawnMonsters[v].position, CONST_ME_TELEPORT)
    end

    if config.kickTime > 0 then
        stopEvent(config.lastEventId)
        config.lastEventId = addEvent(resetRoom, config.kickTime * 1000)
    end

    return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
Room seems to work fine. Where in the code i can put chest reward configuration?
 
Last edited:
Back
Top