• 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 Firestorm event rewards

Phemus

Member
Joined
Jun 16, 2012
Messages
149
Solutions
2
Reaction score
12
I am trying to modify the firestrom event mod with my basic level of coding experience. What I am trying to do is to modify it to the point where it gives you a random item with different amounts. For example, the winner will receive either 25 crystal coins or 1 demon armor. I got frustrated with it. I hope one can help me. Thank you.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Fire_Storm_Event" version="3.0" author="CollocorpuseK" contact="otland.net" enabled="yes">

    <config name="config_fire_storm_event">
        <![CDATA[
            configFireStormEvent = {
                storages = {
                    main = '13335', -- set free storage
                    player = '13336', -- set free storage
                    joining = '13337', -- set free storage
                    exhaust = '13338', -- set free storage
                    countEvent = '13339' -- set free storage
                },
              
                position = {x = 31526, y = 31576, z = 7}, -- position which player is teleported to
                room = {
                    from = {x = 31505, y = 31565, z = 7}, -- left top corner of event room
                    to = {x = 31548, y = 31589, z = 7} -- right bottom corner of event room
                },

                rewards = {{2160, 10}, {9020, 5}}, -- reward id which player can win (reward is random)
                players = {
                    max = 50,
                    min = 2,
                    minLevel = 80
                },

                days = {
                    ['Monday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'},
                    ['Tuesday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'},
                    ['Wednesday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'},
                    ['Thursday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'},
                    ['Friday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:11:00'},
                    ['Saturday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'},
                    ['Sunday'] = {'12:00:00','14:00:00','17:00:00','21:00:00','23:00:00'}
                },

                fireStormDelay = 1000, -- milisecond
              

                delayTime = 5.0, -- time in which players who joined to event are teleporting to teleport position
                startEvent = 30, -- time from teleport to start event
                text = 'To win and get a reward, stay long as possible in the arena.'
            }

            fight = createConditionObject(CONDITION_INFIGHT)
            setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
          
            y, x = 1, 1 -- don't change it
        ]]>
    </config>
  
    <lib name="lib_fire_storm_event">
        <![CDATA[
            function doStartFireStormEvent()
                doSetStorage(configFireStormEvent.storages.joining, -1)
              
                if configFireStormEvent.players.min <= doCountPlayersFireStormEvent() then     
                    for _, cid in ipairs(getPlayersOnline()) do
                        if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
                            doCreatureSetNoMove(cid, false)
                            doRemoveCondition(cid, CONDITION_INFIGHT)
                            doTeleportThing(cid, configFireStormEvent.position)
                            doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
                          
                            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Get ready. Fire Storm starts in '..configFireStormEvent.startEvent..' seconds.')
                        end
                    end
                  
                    addEvent(doSetStorage, configFireStormEvent.startEvent * 1000, configFireStormEvent.storages.main, 1)
                    addEvent(doRepeatCheckFireStorm, configFireStormEvent.startEvent * 1000 + 2000)
                  
                    doBroadcastMessage('Fire Storm has started. Good luck!')
                else
                    for _, cid in ipairs(getPlayersOnline()) do
                        if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
                            doCreatureSetNoMove(cid, false)
                            doRemoveCondition(cid, CONDITION_INFIGHT)
                        end
                    end
                  
                    doBroadcastMessage('Fire Storm was not able to start beacuse there were not enough players.')
                end
            end
          
            function doRepeatCheckFireStorm()
                if getStorage(configFireStormEvent.storages.main) > 0 then
                    local xTable, yTable, playerTable = {}, {}, {}

                    for x = configFireStormEvent.room.from.x, configFireStormEvent.room.to.x do
                        for y = configFireStormEvent.room.from.y, configFireStormEvent.room.to.y do
                            table.insert(xTable, x)
                            table.insert(yTable, y)

                            local n, i = getTileInfo({x=x, y=y, z=configFireStormEvent.room.to.z}).creatures, 1
                            if n ~= 0 then
                                local v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
                                while v ~= 0 do
                                    if isPlayer(v) then
                                        table.insert(playerTable, v)
                                        if n == #playerTable then
                                            break
                                        end
                                    end
                                    i = i + 1
                                    v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
                                end
                            end
                        end
                    end

                    if #playerTable == 1 then
                        local prize = math.random(#configFireStormEvent.rewards)
                        doCreatureAddHealth(playerTable[1], getCreatureMaxHealth(playerTable[1]) - getCreatureHealth(playerTable[1]))
                        doCreatureAddMana(playerTable[1], getCreatureMaxMana(playerTable[1]) - getCreatureMana(playerTable[1]))
                        doTeleportThing(playerTable[1], getTownTemplePosition(getPlayerTown(playerTable[1])), true)
                        doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize], configFireStormEvent.rewards[2])
                        doPlayerSendTextMessage(playerTable[1], MESSAGE_EVENT_ADVANCE, 'You win! You have received ' .. getItemNameById(configFireStormEvent.rewards[prize]) .. ' as reward.')
                        doBroadcastMessage('Fire Storm has finished. The winner is ' .. getCreatureName(playerTable[1]) .. '. Congratulations!')
                        doSetStorage(configFireStormEvent.storages.main, -1)
                      
                        db.executeQuery("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Fire\", \"" .. getCreatureName(playerTable[1]) .. "\", \"" .. getItemNameById(configFireStormEvent.rewards[prize]) .. "\", " .. getStorage(configFireStormEvent.storages.countEvent) ..");")
                        doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
                      
                        x, y = 1, 1
                    elseif #playerTable > 1 then
                        for a = 1, y do
                            addEvent(
                                function()
                                    local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}

                                    for _, player in ipairs(playerTable) do
                                        local pPos = getThingPos(player)
                                        if pPos.x == pos.x and pPos.y == pos.y and pPos.z == pos.z then
                                            doCreatureAddHealth(player, - getCreatureMaxHealth(player))
                                        end
                                    end
                                    doSendDistanceShoot({x = pos.x - math.random(4, 6), y = pos.y - 5, z = pos.z}, pos, CONST_ANI_FIRE)

                                    addEvent(doSendMagicEffect, 150, pos, CONST_ME_HITBYFIRE)
                                    addEvent(doSendMagicEffect, 150, pos, CONST_ME_FIREAREA)
                                end,
                                math.random(100,1000)
                            )
                        end
                        if x == 5 * y then
                            y = y + 1
                        end
                      
                        x = x + 1
                    else
                        doBroadcastMessage('No one survived the Fire Storm.')
                        doSetStorage(configFireStormEvent.storages.main, -1)                     
                        doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
                        x, y = 1, 1
                    end
                  
                    addEvent(doRepeatCheckFireStorm, configFireStormEvent.fireStormDelay)
                end
            end
          
            function doCountPlayersFireStormEvent()
                local x = 0
                for _, cid in ipairs(getPlayersOnline()) do
                    if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
                        x = x + 1
                    end
                end
                return x
            end
          
            function doStartCountingFireStormEvent(x)
                if configFireStormEvent.delayTime-x > 0 then
                    doBroadcastMessage('Fire Storm will start in '..configFireStormEvent.delayTime-x..' minutes. You can join to the event by saying "!fire join".')
                    addEvent(doStartCountingFireStormEvent, 60*1000, x+1)
                end
            end
        ]]>
    </lib>
    <talkaction words="!fire" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")

            function onSay(cid, words, param)
                if getStorage(configFireStormEvent.storages.joining) ~= 1 then
                    return doPlayerSendCancel(cid, 'Fire Storm hasn\'t started yet.')
                elseif param == '' then
                    return doPlayerSendCancel(cid, 'Command param required (say: "!fire join" or "!fire leave.").')
                elseif getPlayerLevel(cid) < configFireStormEvent.players.minLevel then
                    return doPlayerSendCancel(cid, 'You can\'t join to the event if you don\'t have a require '..configFireStormEvent.players.minLevel..' level.')
                elseif getTileInfo(getThingPos(cid)).protection ~= true then
                    return doPlayerSendCancel(cid, 'You can\'t join to the event if you aren\'t in protection zone.')
                elseif exhaustion.check(cid, configFireStormEvent.storages.exhaust) ~= false then
                    return doPlayerSendCancel(cid, 'You must wait '..exhaustion.get(cid, configFireStormEvent.storages.exhaust)..' seconds to use this command again.')
                end

                if param == 'join' then
                    if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
                        return doPlayerSendCancel(cid, 'You have arleady joined to event. Wait patiently for start.')
                    elseif doCountPlayersFireStormEvent() == configFireStormEvent.players.max then
                        return doPlayerSendCancel(cid, 'Max players in the event have been reached.')
                    end
                
                    doCreatureSetNoMove(cid, true)
                    doPlayerPopupFYI(cid, configFireStormEvent.text)
                    doCreatureSetStorage(cid, configFireStormEvent.storages.player, 1)
                    doAddCondition(cid, fight)
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You have joined to Fire Storm Event. You can\'t move until event start. Wait patiently for the event start.')
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have joined to Fire Storm Event.')
                elseif param == 'leave' then
                    if getCreatureStorage(cid, configFireStormEvent.storages.player) <= 0 then
                        return doPlayerSendCancel(cid, 'You can\'t leave from the event if you don\'t join.')
                    end
                
                    doCreatureSetNoMove(cid, false)
                    doRemoveCondition(cid, CONDITION_INFIGHT)
                    doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You left the Fire Storm Event.')
                end
            
                exhaustion.set(cid, configFireStormEvent.storages.exhaust, 5)
            
                return true
            end
        ]]>
    </talkaction>

    <talkaction words="/firestart" access="5" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")
            domodlib("lib_fire_storm_event")

            function onSay(cid, words, param)
                if getStorage(configFireStormEvent.storages.main) > 0 then
                    return doPlayerSendCancel(cid, 'Fire Storm Event is already running.')
                end
        
                doStartCountingFireStormEvent(0)
            
                for _, pid in ipairs(getPlayersOnline()) do
                    if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
                        doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
                        doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
                    end
                end
            
                doSetStorage(configFireStormEvent.storages.joining, 1)
                addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
                return true
            end
        ]]>
    </talkaction>

    <globalevent name="Fire_Storm_Event_Days" interval="1000" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")
            domodlib("lib_fire_storm_event")

            local daysOpen = {}         
            for k, v in pairs(configFireStormEvent.days) do
                table.insert(daysOpen, k)
            end
        
            function onThink(interval)
                if isInArray(daysOpen, os.date('%A')) then
                    if isInArray(configFireStormEvent.days[os.date('%A')], os.date('%X', os.time())) then
                        if getStorage(configFireStormEvent.storages.joining) ~= 1 then
                            doStartCountingFireStormEvent(0)
                        
                            for _, pid in ipairs(getPlayersOnline()) do
                                if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
                                    doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
                                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
                                end
                            end
                        
                            doSetStorage(configFireStormEvent.storages.joining, 1)
                            addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
                        end
                    end
                end
                return true
            end
        ]]>
    </globalevent>

    <event type="statschange" name="Fire_Storm_Event_Dead" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")

            function onStatsChange(cid, attacker, type, combat, value)
                if type == 1 and getCreatureHealth(cid) <= value then
                    if isInRange(getThingPos(cid), configFireStormEvent.room.from, configFireStormEvent.room.to) then
                        doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
                        doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
                        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
                        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You loss.')
                        return false
                    end
                end
                return true
            end
        ]]>
    </event>

    <event type="login" name="Fire_Storm_Event_Login" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")
    
            function onLogin(cid)
                if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
                    doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
                    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
                    doCreatureSetNoMove(cid, false)
                    doRemoveCondition(cid, CONDITION_INFIGHT)
                end

                registerCreatureEvent(cid, 'Fire_Storm_Event_Dead')
                return true
            end
        ]]>
    </event>

    <globalevent name="Fire_Storm_Event_Start" type="startup" event="script">
        <![CDATA[
            domodlib("config_fire_storm_event")

            function onStartup()
                doSetStorage(configFireStormEvent.storages.main, -1)
                doSetStorage(configFireStormEvent.storages.joining, -1)
                return true
            end
        ]]>
    </globalevent>
</mod>

This is the error on the console
Code:
[13:58:10.946] [Error - TalkAction Interface]
[13:58:10.961] In a timer event called from:
[13:58:10.961] domodlib("config_fire_storm_event")
[13:58:10.961]             domodlib("lib_fire_storm_event")
[13:58:10.961]
[13:58:10.961]             function onSay(cid, words, param)
[13:58:10.961]                 if getStorage(configFireStormEvent.storages.main) > 0 then
[13:58:10.981]                     return doPlayerSendCancel(cid, 'Fire Storm Event is already running.')
[13:58:10.981]                 end
[13:58:10.981]
[13:58:10.981]                 doStartCountingFireStormEvent(0)
[13:58:10.999]
[13:58:10.999]                 for _, pid in ipairs(getPlayersOnline()) do
[13:58:10.999]                     if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
[13:58:10.999]                         doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
[13:58:11.015]                         doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
[13:58:11.015]                     end
[13:58:11.015]                 end
[13:58:11.015]
[13:58:11.015]                 doSetStorage(configFireStormEvent.storages.joining, 1)
[13:58:11.030]                 addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
[13:58:11.030]                 return true
[13:58:11.030]             end
[13:58:11.030] :onSay
[13:58:11.030] Description:
[13:58:11.046] (LuaInterface::luaDoPlayerAddItem) Item not found

[13:58:11.046] [Error - TalkAction Interface]
[13:58:11.046] In a timer event called from:
[13:58:11.046] domodlib("config_fire_storm_event")
[13:58:11.061]             domodlib("lib_fire_storm_event")
[13:58:11.061]
[13:58:11.061]             function onSay(cid, words, param)
[13:58:11.061]                 if getStorage(configFireStormEvent.storages.main) > 0 then
[13:58:11.061]                     return doPlayerSendCancel(cid, 'Fire Storm Event is already running.')
[13:58:11.077]                 end
[13:58:11.077]
[13:58:11.077]                 doStartCountingFireStormEvent(0)
[13:58:11.077]
[13:58:11.077]                 for _, pid in ipairs(getPlayersOnline()) do
[13:58:11.093]                     if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
[13:58:11.093]                         doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
[13:58:11.099]                         doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
[13:58:11.099]                     end
[13:58:11.099]                 end
[13:58:11.099]
[13:58:11.099]                 doSetStorage(configFireStormEvent.storages.joining, 1)
[13:58:11.115]                 addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
[13:58:11.115]                 return true
[13:58:11.115]             end
[13:58:11.130] :onSay
[13:58:11.130] Description:
[13:58:11.130] data/lib/050-function.lua:241: attempt to index a boolean value
[13:58:11.130] stack traceback:
[13:58:11.130]  data/lib/050-function.lua:241: in function 'getItemNameById'
[13:58:11.146]  [string "function doStartFireStormEvent()..."]:64: in function <[string "function doStartFireStormEvent()..."]:32>
 
Change the two instances of:
Lua:
getItemNameById(configFireStormEvent.rewards[prize])
To:
Lua:
getItemNameById(configFireStormEvent.rewards[prize][1])
 
Now I get this error
Code:
[20:5:19.932] [Error - TalkAction Interface]
[20:5:19.937] In a timer event called from:
[20:5:19.940] domodlib("config_fire_storm_event")
[20:5:19.944]             domodlib("lib_fire_storm_event")
[20:5:19.948]
[20:5:19.960]             function onSay(cid, words, param)
[20:5:19.964]                 if getStorage(configFireStormEvent.storages.main) > 0 then
[20:5:19.972]                     return doPlayerSendCancel(cid, 'Fire Storm Event is already running.')
[20:5:19.980]                 end
[20:5:19.992]
[20:5:19.996]                 doStartCountingFireStormEvent(0)
[20:5:20.004]
[20:5:20.004]                 for _, pid in ipairs(getPlayersOnline()) do
[20:5:20.012]                     if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
[20:5:20.028]                         doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
[20:5:20.036]                         doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
[20:5:20.040]                     end
[20:5:20.049]                 end
[20:5:20.061]
[20:5:20.065]                 doSetStorage(configFireStormEvent.storages.joining, 1)
[20:5:20.073]                 addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
[20:5:20.089]                 return true
[20:5:20.093]             end
[20:5:20.097] :onSay
[20:5:20.105] Description:
[20:5:20.105] (LuaInterface::luaDoPlayerAddItem) Item not found
 
You mean to change:
Code:
 doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize], configFireStormEvent.rewards[2])
To:
Code:
 doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize][1])
 
@Phemus

Yup good job! Except, now we also need the item count for the function doPlayerAddItem(cid, itemID, itemCount), which is in our second index in from our rewards table:

Code:
configFireStormEvent.rewards = {{2160, 10}, {9020, 5}}

configFireStormEvent.rewards[1] = {2160, 10}
--> configFireStormEvent.rewards[1][1] = 2160
--> configFireStormEvent.rewards[1][2] = 10

configFireStormEvent.rewards[2] = {9020, 5}
--> configFireStormEvent.rewards[2][1] = 9020
--> configFireStormEvent.rewards[2][2] = 5

Lua:
doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize][1], configFireStormEvent.rewards[prize][2])
 
Back
Top