Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _stoneEvent = {}
- _stoneEvent.config =
- {
- monsterName = 'Stone Event',
- spawnPos = {x = 986, y = 1010, z = 7},
- waves = -- waves
- {
- [95] = -- health percent
- {
- {name = 'Dragon', qty = 1},
- {name = 'Rotworm', qty = 1},
- },
- [85] =
- {
- {name = 'Dragon Lord', qty = 1},
- },
- [50] =
- {
- {name = 'Demon', qty = 1},
- },
- [25] =
- {
- {name = 'Ap Javel', qty = 1},
- },
- [10] =
- {
- {name = 'Orshabaal', qty = 1}
- }
- },
- individualReward = -- given only to the player who dealt the most damage
- {
- {name = '10 Premium Points Emblem', qty = 1, chance = 100} -- you can add more rewards
- },
- globalReward = -- given to everyone who participated
- {
- {name = 'Crystal Coin', qty = 10, chance = 100},
- {name = 'Magic Plate Armor', qty = 1, chance = 50}
- },
- globalStatus = 33033,
- eventStatus = 33033
- }
- _stoneEvent.temp = {}
- _stoneEvent.monsters = {}
- function _stoneEvent.giveIndivualReward(player)
- for _, reward in ipairs(_stoneEvent.config.individualReward) do
- if math.random(1, 100) <= reward.chance then
- player:addItem(ItemType(reward.name):getId(), reward.qty)
- end
- end
- end
- function _stoneEvent.giveGlobalReward(player)
- for _, reward in ipairs(_stoneEvent.config.globalReward) do
- if math.random(1, 100) <= reward.chance then
- player:addItem(ItemType(reward.name):getId(), reward.qty)
- end
- end
- end
- function _stoneEvent.getHealthPercent(monster)
- return math.ceil(monster:getHealth() / monster:getMaxHealth() * 100)
- end
- function _stoneEvent.getBounds()
- local aux = {}
- for hp, _ in pairs(_stoneEvent.config.waves) do
- table.insert(aux, hp)
- end
- table.insert(aux, -1)
- table.sort(aux, function(a, b) return b < a end)
- return aux
- end
- function _stoneEvent.getClosestFreePosition(position)
- local usePosition = Position(position)
- local tiles = {Tile(usePosition)}
- local length = 2
- local tile
- for y = -length, length do
- for x = -length, length do
- if x ~= 0 or y ~= 0 then
- usePosition.x = position.x - x
- usePosition.y = position.y - y
- tile = Tile(usePosition)
- if tile then
- tiles[#tiles + 1] = tile
- end
- end
- end
- end
- for i = 1, #tiles do
- tile = tiles[i]
- if tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then
- return tile:getPosition()
- end
- end
- return Position()
- end
- function _stoneEvent.onEventDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
- if creature:getName() ~= _stoneEvent.config.monsterName then
- Game.setStorageValue(_stoneEvent.config.globalStatus, Game.getStorageValue(_stoneEvent.config.globalStatus) - 1)
- table.remove(_stoneEvent.monsters, creature:getId())
- if Game.getStorageValue(_stoneEvent.config.globalStatus) == 0 then
- Creature(_stoneEvent.config.monsterName):setHiddenHealth(false)
- end
- else
- for _, player in ipairs(Game.getPlayers()) do
- if player:getStorageValue(_stoneEvent.config.eventStatus) == 1 then
- _stoneEvent.giveGlobalReward(player)
- player:setStorageValue(_stoneEvent.config.eventStatus, 0)
- end
- end
- if not mostDamageKiller:isPlayer() then
- _stoneEvent.giveIndivualReward(mostDamageKiller:getMaster())
- else
- _stoneEvent.giveIndivualReward(mostDamageKiller)
- end
- _stoneEvent.broadcast('[Stone Event]: Event ended!! Congratulations to everyone who participated!!')
- end
- return true
- end
- function _stoneEvent.onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
- if not creature:isMonster() and creature:getName() ~= _stoneEvent.config.monsterName then
- return primaryDamage, primaryType, secondaryDamage, secondaryType
- end
- if not attacker:isPlayer() then
- return primaryDamage, primaryType, secondaryDamage, secondaryType
- end
- if attacker:getStorageValue(_stoneEvent.config.eventStatus) <= 0 then
- attacker:setStorageValue(_stoneEvent.config.eventStatus, 1)
- end
- local globalStatus = Game.getStorageValue(_stoneEvent.config.globalStatus)
- if tonumber(globalStatus) > 0 then
- return creature:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT) and true
- end
- local hp = _stoneEvent.temp[1]
- if _stoneEvent.getHealthPercent(creature) < hp then
- table.remove(_stoneEvent.temp, 1)
- for _, monsters in pairs(_stoneEvent.config.waves[hp]) do
- for i = 1, monsters.qty do
- local t = {x = _stoneEvent.config.spawnPos.x + math.random(-3, 3), y = _stoneEvent.config.spawnPos.y + math.random(-3, 3), z = _stoneEvent.config.spawnPos.z}
- local pos = _stoneEvent.getClosestFreePosition(t)
- local c = Game.createMonster(monsters.name, pos)
- if c then
- local globalStatus = Game.getStorageValue(_stoneEvent.config.globalStatus)
- Game.setStorageValue(_stoneEvent.config.globalStatus, math.max(0, tonumber(globalStatus)) + 1)
- c:registerEvent('stone_event_death')
- _stoneEvent.monsters[c:getId()] = c
- end
- end
- end
- local globalStatus = Game.getStorageValue(_stoneEvent.config.globalStatus)
- if tonumber(globalStatus) > 0 then
- creature:setHiddenHealth(true)
- end
- end
- return primaryDamage, primaryType, secondaryDamage, secondaryType
- end
- function _stoneEvent.check()
- local s = Creature(_stoneEvent.config.monsterName)
- if s:isRemoved() then return true end
- if #_stoneEvent.monsters > 0 or s:isMonster() then
- for _, monster in ipairs(_stoneEvent.monsters) do
- monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
- monster:remove()
- end
- s:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
- s:remove()
- Game.setStorageValue(_stoneEvent.config.globalStatus, 0)
- end
- _stoneEvent.broadcast('[Stone Event]: Exceed maximum play time!! Event ending!!')
- end
- function _stoneEvent.startEvent()
- _stoneEvent.broadcast('[Stone Event]: Stone Event just started ! You have 30 minutes to defeat the Stone !')
- local s = Game.createMonster(_stoneEvent.config.monsterName, _stoneEvent.config.spawnPos)
- if s then
- s:registerEvent('stone_event_stats')
- s:registerEvent('stone_event_death')
- _stoneEvent.temp = _stoneEvent.getBounds()
- else
- _stoneEvent.broadcast('[Stone Event]: Game couldn\'t start!! Contact the game manager!!')
- end
- addEvent(_stoneEvent.check, 30 * 60 * 1000)
- end
- function _stoneEvent.broadcast(message)
- for _, player in ipairs(Game.getPlayers()) do
- player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement