What's new

Mods [MOD] Randomly Event System

Status
Not open for further replies.

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
1. Autor - Oskar

2. Oryginalny temat -


3. Opis - W skrypcie chodzi o to, ?e od momentu uruchomienia silnika skrypt wylosowuje jeden event i go uruchamia. Co minut? wy?wietla si? wiadomo?? o tym jaki typ zosta? uruchomiony oraz ilu graczy przyst?pi?o i ilu jeszcze brakuje. Po rozpocz?ciu, a nast?pnie zako?czeniu eventu, losuje kolejny i tak w niesko?czono??. Nigdy event nie powt?rzy si? dwa razy pod rz?d, w sensie ten sam. Czyli nie b?dzie przypadku takiego, ?e wylosuje: Zombie, Zombie, Fire Zombie. Skrypt nie testowany! Nie posiadam pewno?ci czy zadzia?a wszystko tak jak opisa?em.

4. Klient - Bazowo pisa?em go pod 8.54, silnik 0.3.6pl1, ale powinien dzia?a? na innych.

5. Skrypt
[lua]<?xml version='1.0' encoding='ISO-8859-1'?>
<mod name='Randomly Event System' version='0.1.0' author='Oskar' contact='oskar1121@gmail.com' enabled='yes'>
<config name='newRandomlyEventsSystem'><![CDATA[
events = {
[1] = {name = 'Team Battle Island', enterPos = {x=1589,y=1549,z=7}, centerArenaPos = {x=1589,y=1549,z=7},
arenaSize = {26,24}, randomReward = false, reward = {2157,5,6119,1}, registers = {'TeamBattleIslandEventStatsChange'}},
[2] = {name = 'Fire Storm Event', enterPos = {x=1589,y=1549,z=7}, centerArenaPos = {x=1589,y=1549,z=7},
arenaSize = {5,5}, randomReward = false, reward = {2157,5,6119,1}},
[3] = {name = 'Last Man Standing', enterPos = {x=1589,y=1549,z=7}, centerArenaPos = {x=1589,y=1549,z=7},
arenaSize = {5,5}, randomReward = false, reward = {2157,5,6119,1}, registers = {'LMSEventStatsChange'}},
[4] = {name = 'Pandora Box', enterPos = {x=1589,y=1549,z=7}, centerArenaPos = {x=1589,y=1549,z=7},
arenaSize = {5,5}, randomReward = false},
[5] = {name = 'Zombie Event', enterPos = {x=1589,y=1549,z=7}, centerArenaPos = {x=1589,y=1549,z=7},
arenaSize = {5,5}, randomReward = false, reward = {2157,5,6119,1}, registers = {'zombieEventStatsChange'}}
}

maxEventPlayers = 1 --maksymalna ilosc graczy, ktora moze przystapic do eventu, po przekroczeniu tej liczby event od razu startuje (nie czeka pozostalego czasu, ktory pozostal na szukanie chetnych)
minEventPlayers = 1 --minimalna ilosc graczy, bez ktorej event sie nie rozpocznie
accesToIgnore = 22

kickPosition = {x=1594,y=1555,z=7} --pozycja, gdzie wyrzuci gracza po przegranej/rezygnacji z eventu
enterPosition = {x=1594,y=1555,z=7} --pozycja tzw. poczekalni, gdzie gracze beda czekac na rozpoczecie eventu

storageStatus = 31000 --bazowe storage, na ktorym oparte bedzie ukochamianie eventow, np fire storm przyjmuje wartosc 1, team battle island 4 itd. Uzywam tez tego storage do zapisywania osob, ktore uczestnicza w evencie
eventStorageStatus = 31001 --storage sprawdzajace czy jakikolwiek event jest w trakcie dzialania/szukania graczy/nieaktywny value 2/1/0


--Team Battle Island Config
wavesRiffle = {[95]=10,[90]=11,[85]=12,[80]=13,[75]=14,[70]=15,[65]=16,[60]=17,[55]=18,[50]=19,
[45]=20,[40]=21,[35]=22,[30]=23,[25]=24,[20]=25,[15]=26,[10]=27,[5]=28,[1]=30} --procentHpBossa1,ilo??StworzonychPotwor?w1,procentHpBossa2,ilo??StworzonychPotwor?w2, ...

arenasData = {
['red'] = {centerIslandPosition = {x=983,y=1218,z=6}, islandSize = {11,10}, storage = 13301,
monsterType = {'bog raider',8,'hydra',2,'defiler',5},
bossPosition = {x=993,y=1227,z=7}, bossName = 'nature guard',
outfit = 128, color = 94},
['green'] = {centerIslandPosition = {x=1004,y=1217,z=6}, islandSize = {12,10}, storage = 13302,
monsterType = {'bonelord',8,'plaguesmith',2,'earth elemental',5},
bossPosition = {x=995,y=1227,z=7}, bossName = 'crumb of nature',
outfit = 128, color = 82},
['yellow'] = {centerIslandPosition = {x=1004,y=1239,z=6}, islandSize = {12,10}, storage = 13303,
monsterType = {'massive earth elemental',8,'serpent spawn',2,'wyvern',5},
bossPosition = {x=995,y=1229,z=7}, bossName = 'wrath of nature',
outfit = 128, color = 79},
['blue'] = {centerIslandPosition = {x=983,y=1237,z=6}, islandSize = {12,10}, storage = 13304,
monsterType = {'necromancer',8,'giant spider',2,'medusa',5},
bossPosition = {x=993,y=1229,z=7}, bossName = 'natural warrior',
outfit = 128, color = 88},
}

--Fire Storm Config
fireStormShootInterval = 8
fireStormNewFireShoots = 15
fireStormBaseFireShoots = 40

--Last Man Standing Config
LMSCountSpawnNewMonsters = 3
LMSTimeBetweenSpawnNewMonsters = 20

LMSMonsters = {
--['nazwa potwora'] = szansa na stworzenie,
['hero'] = 25,
['black knight'] = 15
}

--Pandora Box Config
monstersPositions = {
leftTopCorner = {x=1579,y=1539,z=7},
rightBottomCorner = {x=1599,y=1559,z=7}
}
--box config
pandoraBoxId = 9661
pandoraBoxPosition = {x=1589,y=1549,z=7}

--monsters config
monstersName = {'slime',4,'dragon',25} --'name', chance, 'name1', chance1
monstersSpawnCount = {1,2} --{from, to}

--waves config
wavesCount = {2,4} --{from, to}
timeBetweenWaves = 20 --in seconds

timeOnKillAllMonsters = 2 --in minutes
timeOnGetRewards = 10 --in seconds
bossName = 'Pandora'
pandoraGuards = 'fallen island warlock'
pandoraGuardsCount = 4
expRateValue = 0.25

pandoraBoxRewards = {
--[vocationId] = {itemid, count, itemid1, count1, ...}
[1] = {2160, 25, 7898, 1, 7899, 1}, --sorc
[2] = {2160, 25, 7884, 1, 7897, 1}, --druid
[3] = {2160, 25, 8891, 1, 7368, 100}, --pall
[4] = {2160, 25, 8889, 1, 5741, 1}, --knight
[5] = {2160, 30, 8868, 1, 8867, 1}, --ms
[6] = {2160, 30, 8866, 1, 8869, 1}, --ed
[7] = {2160, 30, 8888, 1, 2537, 1}, --rp
[8] = {2160, 30, 8881, 1, 2522, 1}, --ek
}

--Zombie Event Config
countOfZombiesOnStart = 10
zombieStorageStatus = 31003
zombieEventConfig = {
--['nazwa potwora'] = {szansa na stworzenie, szansa na zainfekowanie}
['horned mutant'] = {20,1},
['vile centurion'] = {15,2},
['daidalost'] = {10,4},
['mongrel man'] = {5,8},
['propell zombie'] = {2,16},
['scrathclaw'] = {1,32}
}


doCreatureSetStorage = setPlayerStorageValue
getCreatureStorage = getPlayerStorageValue

CONST_PROP_BLOCKSOLID = 0
CONST_PROP_HASHEIGHT = 1
CONST_PROP_BLOCKPROJECTILE = 2
CONST_PROP_BLOCKPATHFIND = 3
CONST_PROP_ISVERTICAL = 4
CONST_PROP_ISHORIZONTAL = 5
CONST_PROP_MOVEABLE = 6
CONST_PROP_BLOCKINGANDNOTMOVEABLE = 7
CONST_PROP_SUPPORTHANGABLE = 8
CONST_PROP_IMMOVABLENOFIELDBLOCKPATH = 9
CONST_PROP_NOFIELDBLOCKPATH = 10
CONST_PROP_SUPPORTHANGABLE = 11

function choose(table)
return table[math.random(#table)]
end

function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).uid == 0 then return false end
if creature and isCreature(getTopCreature(pos).uid) then return false end
if pz and getTileInfo(pos).protection then return false end
local n = proj and CONST_PROP_BLOCKPROJECTILE or CONST_PROP_BLOCKPATHFIND
for i = 0, 255 do
pos.stackpos = i
local tile = getThingFromPos(pos)
if tile.uid > 0 and not isCreature(tile.uid) then
if hasProperty(tile.uid, n) or hasProperty(tile.uid, CONST_PROP_BLOCKINGANDNOTMOVEABLE) then
return false
end
end
end
return true
end

function getPercent(number, all)
return (number / all) * 100
end

local _f = doTeleportThing
function doTeleportThing(cid, newpos, ignoreBlocking)
return (ignoreBlocking or isWalkable(newpos, true, true, false) or false) and _f(cid, newpos, true, true)
end

function addPlayerToEventArea(cid, enterPosition)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
doSendMagicEffect(enterPosition, CONST_ME_TELEPORT)
doTeleportThing(cid, enterPosition, true)
return doCreatureSetStorage(cid, storageStatus, 1)
end

function kickPlayerFromEvent(cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
doSendMagicEffect(kickPosition, CONST_ME_TELEPORT)
doTeleportThing(cid, kickPosition, true)
return doCreatureSetStorage(cid, storageStatus, 0)
end

function getEventPlayers()
local players = {}
for _, cid in pairs(getPlayersOnline()) do
if getCreatureStorage(cid, storageStatus) == 1 and getPlayerAccess(cid) < accesToIgnore then
table.insert(players, cid)
end
end
return players
end

function doClearArena(eventNumber)
local spectatorsEventArena = getSpectators(events[eventNumber].centerArenaPos, events[eventNumber].arenaSize[1], events[eventNumber].arenaSize[2])
if spectatorsEventArena then
for _, v in ipairs(spectatorsEventArena) do
if isMonster(v) then
doRemoveThing(v)
elseif isPlayer(v) then
kickPlayerFromEvent(v)
end
end
end
return true
end

function doWaitingOnPlayers(timeToStart, eventNumber)
if getStorage(eventStorageStatus) ~= 1 then
return true
end
if timeToStart == 0 then
if #getEventPlayers() < minEventPlayers then
doBroadcastMessage(events[eventNumber].name .. ' is still active. We not found enough player. We\'re waiting 5 minutes for '..minEventPlayers - #getEventPlayers()..' players. If you want joined to event just use command "!join", but if you would leave '..events[eventNumber].name..' just say "!leave". Have fun!')
return doWaitingOnPlayers(5, events[eventNumber].name)
else
doSetStorage(eventStorageStatus, 2)
doClearArena(eventNumber)
local eventName = events[eventNumber].name:lower()
if eventName == 'team battle island' then
doSetStartNewEvent(eventNumber)
elseif eventName == 'fire storm event' then
addEvent(spawnNewFire, 5000, eventNumber)
elseif eventName == 'last man standing' then
for i = 1, LMSCountSpawnNewMonsters do
spawnNewLMSMonster(0, eventNumber)
end
elseif eventName == 'pandora box' then
setPandoraBox(eventNumber)
elseif eventName == 'zombie event' then
for i = 1, countOfZombiesOnStart do
spawnNewZombie(eventNumber)
end
else
return print('[ERROR] - Wrong event name is choose.')
end
for _, v in ipairs(getEventPlayers()) do
addPlayerToEventArea(v, events[eventNumber].enterPos)
end
return doBroadcastMessage(events[eventNumber].name .. ' is started. We have ' .. #getEventPlayers() .. ' players, which joined to event. Have fun!')
end
end
local onWhatWaiting = #getEventPlayers() >= minEventPlayers and ' to start an Event.' or ' for ' .. minEventPlayers - #getEventPlayers() .. ' players.'
doBroadcastMessage(events[eventNumber].name .. ' is active. We are waiting '..timeToStart..' minute'..(timeToStart > 1 and 's' or '').. onWhatWaiting .. ' If you want joined to event just use command "!join", but if you would leave fire storm arena just say "!leave". Have fun!')
return addEvent(doWaitingOnPlayers, 60 * 1000, timeToStart - 1, eventNumber)
end

function doRandomEvent(eventNumber)
local newEvent = math.random(#events)
if newEvent ~= eventNumber then
doSetStorage(storageStatus, newEvent)
doSetStorage(eventStorageStatus, 1)
doBroadcastMessage(events[newEvent].name..' is active. We are waiting 10 minutes for ' .. minEventPlayers - #getEventPlayers() .. ' players. If you want joined to event just use command "!join", but if you would leave fire storm arena just say "!leave". Have fun!')
return addEvent(doWaitingOnPlayers, 60 * 1000, 10, newEvent)
end
return doRandomEvent(eventNumber)
end

function loseFromEvent(cid)
local msg, eventNumber = '', getStorage(storageStatus)
kickPlayerFromEvent(cid)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You lose.')
if #getEventPlayers() <= 1 then
local winner = getEventPlayers()[1] or cid
if isPlayer(winner) then
if events[eventNumber].randomReward then
local i = math.random(#events[eventNumber].reward/2)
doPlayerAddItem(winner, events[eventNumber].reward[i*2-1], events[eventNumber].reward[i*2], true)
else
for i = 1, #events[eventNumber].reward/2 do
doPlayerAddItem(winner, events[eventNumber].reward[i*2-1], events[eventNumber].reward[i*2], true)
end
end
doPlayerSendTextMessage(winner, MESSAGE_INFO_DESCR, 'You won '..events[eventNumber].name..'.')
msg = getCreatureName(winner) .. ' won '..events[eventNumber].name..'.'
kickPlayerFromEvent(winner)
doClearArena(eventNumber)
else
msg = events[eventNumber].name..' finished! No one win!'
end
doSetStorage(storageStatus, 0)
doSetStorage(eventStorageStatus, 0)
addEvent(doRandomEvent, 5 * 60 * 1000, eventNumber)
return doBroadcastMessage(msg .. ' Next event running in 5 minutes.')
end
return true
end

function chooseZombieMonster()
local monster = false
for k, v in pairs(zombieEventConfig) do
monster = monster or (math.random(100) <= v[1] and k or false)
end
return monster or chooseZombieMonster()
end

function spawnNewZombie(eventNumber, fromPosition, n)
local n, pos = n or 0, {x = events[eventNumber].centerArenaPos.x + math.random(-events[eventNumber].arenaSize[1],events[eventNumber].arenaSize[1]), y = events[eventNumber].centerArenaPos.y + math.random(-events[eventNumber].arenaSize[2],events[eventNumber].arenaSize[2]), z = events[eventNumber].centerArenaPos.z}
if isWalkable(pos, true, true, true) then
local monster = chooseZombieMonster()
local cid = doCreateMonster((monster == '' and 'horned mutant' or monster), pos, false, false, false)
doSendMagicEffect(pos, CONST_ME_MORTAREA)
return (isMonster(cid) and registerCreatureEvent(cid, 'zombieEventDeath') and registerCreatureEvent(cid, 'zombieEventThink')) and (fromPosition and doSendDistanceShoot(fromPosition, pos, CONST_ANI_SUDDENDEATH) or true)
end
return (n < 100 and spawnNewZombie(eventNumber, fromPosition, n+1) or true)
end

function checkPositions(n)
local eventNumber, n = getStorage(storageStatus), n or 0
local pos = {x = events[eventNumber].centerArenaPos.x + math.random(-events[eventNumber].arenaSize[1],events[eventNumber].arenaSize[1]), y = events[eventNumber].centerArenaPos.y + math.random(-events[eventNumber].arenaSize[2],events[eventNumber].arenaSize[2]), z = events[eventNumber].centerArenaPos.z}
if type(pos) == 'table' and isWalkable(pos, true, true, true) then
return pos
end
return n < 100 and checkPositions(n+1) or false
end

function setMonster()
for i = 1, #monstersName/2 do
local pos = checkPositions()
if pos and math.random(100000) <= monstersName[i*2]*1000 then
local mon = doCreateMonster(monstersName[i*2-1], pos, false, false, false)
return isCreature(mon) and doCreatureSetStorage(mon, 1000, 1) or true
end
end
return setMonster()
end

function setPandoraBoxMonsters()
for j = 1, math.random(wavesCount[1], wavesCount[2]) do
addEvent(function()
for _, pid in ipairs(getEventPlayers()) do
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Next wave is raid on the island! Beware mortals, death come for you!')
end
for i = 1, math.random(monstersSpawnCount[1], monstersSpawnCount[2]) do
addEvent(setMonster, i * 50)
end return true end,
(j == 1 and 1000 or timeBetweenWaves * 1000 * (j-1)))
end
return true
end

function checkMonsters(n)
local eventNumber, n = getStorage(storageStatus), n or 0
local newSpectators = getSpectators(events[eventNumber].centerArenaPos, events[eventNumber].arenaSize[1], events[eventNumber].arenaSize[2])
if newSpectators then
for _, v in ipairs(newSpectators) do
if isMonster(v) and getCreatureStorage(v, 1000) == 1 then
for _, pid in ipairs(getEventPlayers()) do
if n == 0 then
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Experience rate is to decreased by '.. expRateValue * 100 ..' percent and not grow, until the evil from Pandora Box walk on the island.')
n = 60
end
doPlayerSetExperienceRate(pid, expRateValue)
end
return addEvent(checkMonsters, 5000, n - 1)
end
end
end
for _, pid in ipairs(getEventPlayers()) do
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Evil from Pandora Box is defeated! '..bossName..' in his own person be came to the island for revenage!')
end
local pand = doCreateMonster(bossName, pandoraBoxPosition, false, false, false)
local pos, guardPos = getThingPos(pand), getThingPos(pand)
for i = 1, pandoraGuardsCount do
guardPos.x = pos.x + math.random(-4,4)
guardPos.y = pos.y + math.random(-4,4)
doCreateMonster(pandoraGuards, guardPos, false, false, false)
end
return isMonster(pand) and registerCreatureEvent(pand, 'pandoraDeath') or false
end

function setPandoraBox()
for _, pid in ipairs(getEventPlayers()) do
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Pandora Box is appeared somewhere on the island! Find her and just use it!')
end
local item = doCreateItem(pandoraBoxId, pandoraBoxPosition)
doItemSetAttribute(item, 'uid', 2000)
return doItemSetAttribute(item, 'name', 'Pandora Box') and false
end

function chooseLMSMonster()
local monster = false
for k, v in pairs(LMSMonsters) do
monster = monster or (math.random(100) <= v and k or false)
end
return monster or chooseLMSMonster()
end

function spawnNewLMSMonster(n, eventNumber)
if getStorage(storageStatus) ~= eventNumber then
return doClearArena(eventNumber)
end
local pos = {x = events[eventNumber].centerArenaPos.x + math.random(-events[eventNumber].arenaSize[1],events[eventNumber].arenaSize[1]), y = events[eventNumber].centerArenaPos.y + math.random(-events[eventNumber].arenaSize[2],events[eventNumber].arenaSize[2]), z = events[eventNumber].centerArenaPos.z}
if isWalkable(pos, true, true, true) then
local cid = doCreateMonster(chooseLMSMonster(), pos, false, false, false)
if not isCreature(cid) then
return spawnNewLMSMonster(n+1, eventNumber)
end
for i = 1, LMSCountSpawnNewMonsters do
addEvent(spawnNewLMSMonster, LMSTimeBetweenSpawnNewMonsters * 1000, n + 1, eventNumber)
end
return doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
end
return (n < 100 and spawnNewLMSMonster(n+1, eventNumber) or true)
end

function spawnNewFire(eventNumber, count, reserved)
count, reserved = count or fireStormBaseFireShoots, reserved or fireStormBaseFireShoots
for i = 1, count do
if getStorage(storageStatus) ~= eventNumber then
return true
end
local pos = {x = events[eventNumber].centerArenaPos.x + math.random(-events[eventNumber].arenaSize[1],events[eventNumber].arenaSize[1]), y = events[eventNumber].centerArenaPos.y + math.random(-events[eventNumber].arenaSize[2],events[eventNumber].arenaSize[2]), z = events[eventNumber].centerArenaPos.z}
if i == count then
return addEvent(spawnNewFire, fireStormShootInterval*1000, eventNumber, fireStormNewFireShoots + reserved, fireStormNewFireShoots + reserved)
end
if isWalkable(pos, false, true, true) then
addEvent(function()
if #getEventPlayers() < 1 then
return true
end
local xx = math.abs(pos.x - events[eventNumber].centerArenaPos.x) + events[eventNumber].arenaSize[1]
local yy = math.abs(pos.y - events[eventNumber].centerArenaPos.y) + events[eventNumber].arenaSize[2]
doSendDistanceShoot({x=pos.x-xx,y=pos.y-yy,z=pos.z}, pos, CONST_ANI_FIRE)
addEvent(doSendMagicEffect, math.max(xx,yy)*15, pos, CONST_ME_HITBYFIRE)
local player = getTopCreature(pos).uid
if isPlayer(player) and getPlayerAccess(player) < accesToIgnore then
addEvent(loseFromEvent, 500, player)
end return true end,
math.random(500, fireStormShootInterval*1000),
pos)
else
return spawnNewFire(eventNumber, count-(i-1), math.max(reserved, count))
end
end
return true
end

teamTypes = {}
for k, v in pairs(arenasData) do
table.insert(teamTypes, k)
end

function chooseMonster(monsters, n)
local n = n or 0
for i = 1, #monsters / 2 do
if math.random(100000) <= monsters[i*2] * 1000 then
return monsters[i*2-1]
end
end
return n < 10 and chooseMonster(monsters, n + 1) or monsters[1]
end

function spawnNew(centerPosition, rangeRoom, monster, storage, n)
local n, pos = n or 0, {x=centerPosition.x+math.random(-(rangeRoom[1]-2),rangeRoom[1]-2), y=centerPosition.y+math.random(-(rangeRoom[2]-2),rangeRoom[2]-2), z=centerPosition.z+1}
if type(pos) == 'table' and isWalkable(pos, true, true, true) then
local cid = doCreateMonster(monster, pos, false, false, false)
doCreatureSetStorage(cid, storage, 1)
registerCreatureEvent(cid, 'TeamBattleIslandEventStatsChange')
return doSendMagicEffect(pos, CONST_ME_SMALLPLANTS)
end
return n < 20 and spawnNew(centerPosition, rangeRoom, monster, storage, n+1) or false
end

function getTeamColorType(teamTable, playerCount, t)
local randomType, t = choose(teamTypes), t or 0
if #teamTable[randomType] < math.ceil(playerCount / #arenasData) then
return randomType
end
return t <= 50 and getTeamColorType(teamTable, playerCount, t) or false
end

function getTeamType(cid, getColor)
for k, v in pairs(arenasData) do
if (isPlayer(cid) and getCreatureStorage(cid, v.storage) == 1) or
(isMonster(cid) and (v.bossName:lower() == getCreatureName(cid):lower() or isInArray(v.monsterType, getCreatureName(cid):lower()))) then
return getColor and k or v
end
end
return false
end

function getTableWithTeamColors()
local tableWithPlayers = {}
for k, v in pairs(arenasData) do
tableWithPlayers[k] = {}
end
for _, cid in ipairs(getEventPlayers()) do
table.insert(tableWithPlayers[getTeamType(cid, true)], cid)
end
return tableWithPlayers
end

function doSetStartNewEvent(eventNumber)
local spectators = getSpectators(events[eventNumber].centerArenaPos, events[eventNumber].arenaSize[1], events[eventNumber].arenaSize[2])
if spectators then
for _, cid in pairs(spectators) do
if isMonster(cid) then
doRemoveThing(cid)
elseif isPlayer(cid) then
kickPlayerFromEvent(cid)
end
end
end
local joinedPlayers, playerTeams = getEventPlayers(), {}
for k, v in pairs(arenasData) do
playerTeams[k] = {}
end
for _, pid in ipairs(joinedPlayers) do
setResetStorages(pid)
local teamColorType = getTeamColorType(playerTeams, #joinedPlayers)
if teamColorType then
table.insert(playerTeams[teamColorType], pid)
end
end
for k, v in pairs(playerTeams) do
if #v > 0 then
for i = 1, #v do
if isPlayer(v) then
doTeleportThing(v, arenasData[k].centerIslandPosition, true)
doSendMagicEffect(getThingPos(v), CONST_ME_SMALLPLANTS)
doCreatureSetStorage(v, arenasData[k].storage, 1)
doPlayerSendTextMessage(v, MESSAGE_EVENT_ADVANCE, 'Your team color are '..k..'. Your team have '..#v..' players.')
doCreatureChangeOutfit(v, {lookType=arenasData[k].outfit,lookBody=arenasData[k].color,lookHead=arenasData[k].color,lookLegs=arenasData[k].color,lookFeet=arenasData[k].color,lookAddons=3})
end
end
local cid = doCreateMonster(arenasData[k].bossName, arenasData[k].bossPosition, false, false, false)
if isCreature(cid) then
doCreatureSetStorage(cid, 1000, 100)
doCreatureSetStorage(cid, arenasData[k].storage, 1)
registerCreatureEvent(cid, 'TeamBattleIslandDeath')
registerCreatureEvent(cid, 'TeamBattleIslandEventStatsChange')
end
end
end
return true
end

function setResetStorages(cid)
for _, v in pairs(arenasData) do
doCreatureSetStorage(cid, v.storage, -1)
end
return true
end
]]></config>

--Join to event / other functions
<talkaction words="!join;!back;!leave" event="script"><![CDATA[
domodlib('newRandomlyEventsSystem')
function onSay(cid, words, param, channel)
local eventNumber = getStorage(storageStatus)
if eventNumber < 1 then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Any event is started.')
end
if words:lower() == '!join' then
if getCreatureCondition(cid, CONDITION_INFIGHT) and getPlayerAccess(cid) <= accesToIgnore then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have a PZ! You have to get rid of it. Somehow.')
end
if getPlayerAccess(cid) >= accesToIgnore then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have acces above than script is requied.')
return doTeleportThing(cid, enterPosition, true)
elseif #getEventPlayers() < maxEventPlayers then
if events[eventNumber].registers then
for _, v in pairs(events[eventNumber].registers) do
registerCreatureEvent(cid, v)
end
end
addPlayerToEventArea(cid, enterPosition)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You are player of number '..#getEventPlayers()..', which join to event.')
if #getEventPlayers() == maxEventPlayers then
doBroadcastMessage(getCreatureName(cid) .. ' has entered to a '..events[eventNumber].name..'.')
return doWaitingOnPlayers(0, eventNumber)
else
return doBroadcastMessage(getCreatureName(cid) .. ' has entered to a '..events[eventNumber].name..'. We still need ' .. (maxEventPlayers - #getEventPlayers()) .. ' players.')
end
else
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Arena is full.')
end
elseif isInArray({'!leave','!back'}, words:lower()) then
if getStorage(storageStatus) ~= -1 then
return kickPlayerFromEvent(cid, kickPosition)
end
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can\'t leave from arena if event is already running.')
end
return true
end
]]></talkaction>

<globalevent name='NES' type='startup' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onStartup()
doSetStorage(eventStorageStatus, -1)
return addEvent(doRandomEvent, 10000, 0)
end
]]></globalevent>

<event type='login' name='playerLogin' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onLogin(cid)
doCreatureSetStorage(cid, TeamBattleIslandStorageStatus, -1)
doCreatureSetStorage(cid, LMSStorageStatus, 0)
doCreatureSetStorage(cid, zombieStorageStatus, 0)
doCreatureSetStorage(cid, storageStatus, -1)
return setResetStorages(cid)
end
]]></event>

--Zombie Event
<event type='death' name='zombieEventDeath' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onDeath(cid)
for i = 1, math.random(2) do
spawnNewZombie(getStorage(storageStatus), getThingPos(cid))
end
doSendMagicEffect(getThingPos(cid), CONST_ME_MORTAREA)
return doCreatureSay(cid, 'I\'ll be back!', TALKTYPE_ORANGE_1)
end
]]></event>

<event type='think' name='zombieEventThink' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onThink(cid)
if not isMonster(cid) then
return true
end
local name, target = getCreatureName(cid):lower(), getCreatureTarget(cid)
if zombieEventConfig[name] and target and isPlayer(target) then
if getCreatureStorage(target, zombieStorageStatus+1) < os.time() and getDistanceBetween(getThingPos(target), getThingPos(cid)) <= 1 and math.random(100) <= zombieEventConfig[name][2] then
doSendAnimatedText(getThingPos(target), 'INFECTED!', COLOR_LIGHTGREEN)
doCreatureSetStorage(target, zombieStorageStatus+1, os.time() + 3)
doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_BLUE, 'You are infected. You can cure, just say "disable infection", but remember, you have only three seconds on it.')
return addEvent(function()
if isPlayer(target) then
if getCreatureStorage(target, zombieStorageStatus+1) ~= os.time() then
return false
end
doCreatureAddHealth(target, getCreatureMaxHealth(target))
return loseFromEvent(target)
end return true end,
3000,
target)
end
end
return true
end
]]></event>

<event type='statschange' name='zombieEventStatsChange' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onStatsChange(cid, attacker, type, combat, value)
if isMonster(attacker) and isPlayer(cid) and zombieEventConfig[getCreatureName(attacker):lower()] and type == STATSCHANGE_HEALTHLOSS and math.abs(value) >= getCreatureHealth(cid) then
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
return loseFromEvent(cid) and false
end
return true
end
]]></event>

--Team Battle Island
<event type='statschange' name='TeamBattleIslandEventStatsChange' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onStatsChange(cid, attacker, type, combat, value)
if combat == COMBAT_HEALING then
return true
end
local teamType = getTeamType(cid)
if isPlayer(cid) and teamType then
if getCreatureHealth(cid) <= value then
if getCreatureStorage(cid, TeamBattleIslandStorageStatus) == 1 then
setResetStorages(cid)
return loseFromEvent(cid) and false
end
return false
end
if isCreature(attacker) then
local attackerTeamType = getTeamType(attacker)
if attackerTeamType and teamType.storage ~= attackerTeamType.storage then
return doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
end
end
elseif isMonster(cid) and teamType then
local x, monsterPercentHealth = 0, math.ceil(getPercent(getCreatureHealth(cid), getCreatureMaxHealth(cid)))
if isPlayer(attacker) then
if isInArray(teamType.monsterType, getCreatureName(cid):lower()) then
return getCreatureStorage(attacker, teamType.storage) == 1
elseif getCreatureStorage(attacker, teamType.storage) == -1 then
return doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
end
end
local TeamBattleIslandSpectators = getSpectators({x=teamType.centerIslandPosition.x,y=teamType.centerIslandPosition.y,z=teamType.centerIslandPosition.z+1}, teamType.islandSize[1], teamType.islandSize[2])
if TeamBattleIslandSpectators then
for _, pid in ipairs(TeamBattleIslandSpectators) do
x = x + (isMonster(pid) and getCreatureStorage(pid, teamType.storage) == 1 and 1 or 0)
end
end
if x > 2 then
return doSendMagicEffect(getThingPos(cid), CONST_ME_POFF) and false
end
local monsterCount = wavesRiffle[monsterPercentHealth]
if not monsterCount then
return true
end
if getCreatureStorage(cid, 1000) == -1 then
doCreatureSetStorage(cid, 1000, 100)
end
if getCreatureStorage(cid, 1000) > monsterPercentHealth then
for i = 1, monsterCount do
addEvent(spawnNew, i * 100, teamType.centerIslandPosition, teamType.islandSize, chooseMonster(teamType.monsterType), teamType.storage, 0)
end
return doCreatureSetStorage(cid, 1000, monsterPercentHealth)
end
end
return true
end
]]></event>

<event type='death' name='TeamBattleIslandDeath' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onDeath(cid, corpse, deathList)
local teamType, eventNumber = getTeamType(cid, true), getStorage(storageStatus)
if teamType then
for _, pid in pairs(getTableWithTeamColors()[teamType]) do
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Your team win and you get some gifts.')
doBroadcastMessage(teamType:upper()..' team win Team Battle Island Event! Congratulations!')
if events[eventNumber].randomReward then
local i = math.random(#events[eventNumber].reward/2)
doPlayerAddItem(pid, events[eventNumber].reward[i*2-1], events[eventNumber].reward[i*2], true)
else
for i = 1, #events[eventNumber].reward/2 do
doPlayerAddItem(pid, events[eventNumber].reward[i*2-1], events[eventNumber].reward[i*2], true)
end
end
end
local TeamBattleIslandSpectators = getSpectators(events[eventNumber].centerArenaPos, events[eventNumber].arenaSize[1], events[eventNumber].arenaSize[2])
if TeamBattleIslandSpectators then
for _, v in ipairs(TeamBattleIslandSpectators) do
if isMonster(v) then
doRemoveThing(v)
elseif isPlayer(v) then
setResetStorages(v)
kickPlayerFromEvent(v)
end
end
end
addEvent(doRandomEvent, 5 * 60 * 1000, eventNumber)
doSetStorage(eventStorageStatus, 0)
return doSetStorage(storageStatus, 0)
end
return
end
]]></event>

--Pandora Box
<event type='death' name='pandoraDeath' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onDeath(cid)
if getTileItemById(pandoraBoxPosition, pandoraBoxId).uid == 2000 then
item = getTileItemById(pandoraBoxPosition, pandoraBoxId)
end
addEvent(function()
doClearArena(getStorage(storageStatus))
doSetStorage(storageStatus, 0)
doSetStorage(eventStorageStatus, 0)
doBroadcastMessage('Pandora Box is disappeared from the world!')
if getTileItemById(pandoraBoxPosition, pandoraBoxId).uid == 2000 then
return doRemoveItem(getTileItemById(pandoraBoxPosition, pandoraBoxId).uid)
end
return true end,
timeOnGetRewards * 1000)
return item and doItemSetAttribute(item.uid, 'pandoraBox', 1000) and doBroadcastMessage('The ancient evil has been defeated! The Pandora\'s Box are the reward for each, but only for '..timeOnGetRewards..' seconds!') or true
end
]]></event>

--Last Man Standing
<event type='statschange' name='LMSEventStatsChange' event='script'><![CDATA[
domodlib('newRandomlyEventsSystem')
function onStatsChange(cid, attacker, type, combat, value)
if isMonster(attacker) and isPlayer(cid) and LMSMonsters[getCreatureName(attacker):lower()] and type == STATSCHANGE_HEALTHLOSS and math.abs(value) >= getCreatureHealth(cid) then
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
return loseFromEvent(cid) and false
end
return true
end
]]></event>

--Pandora Box
<action uniqueid="2000" event="script"><![CDATA[
domodlib('newRandomlyEventsSystem')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == pandoraBoxId and not getItemAttribute(item.uid, 'pandoraBox') then
doItemSetAttribute(item.uid, 'pandoraBox', 500)
addEvent(checkMonsters, timeOnKillAllMonsters * 1000 * 60, 0)
return setPandoraBoxMonsters()
elseif item.itemid == pandoraBoxId and getItemAttribute(item.uid, 'pandoraBox') == 1000 then
if getCreatureStorage(cid, 150) ~= -1 then
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It\'s empty.')
end
if pandoraBoxRewards[getPlayerVocation(cid)] then
doCreatureSetStorage(cid, 150, 0)
msg = 'You have found '
for i = 1, #pandoraBoxRewards[getPlayerVocation(cid)]/2 do
msg = msg .. getItemNameById(pandoraBoxRewards[getPlayerVocation(cid)][i*2-1]) .. (i < #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ', ' or i == #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ' and ' or '.')
doPlayerAddItem(cid, pandoraBoxRewards[getPlayerVocation(cid)][i*2-1], pandoraBoxRewards[getPlayerVocation(cid)][i*2])
end
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
end
end
return false
end
]]></action>
</mod>[/lua]

6. Zdj?cia dzia?ania:

u4N8aDO.png

JOErlX7.png
 
Status
Not open for further replies.
Top