local function isInArea(pos, fromPos, toPos)
if pos.x >= fromPos.x and pos.x <= toPos.x then
if pos.y >= fromPos.y and pos.y <= toPos.y then
if pos.z >= fromPos.z and pos.z <= toPos.z then
return true
end
end
end
return false
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
function onStatsChange(cid, attacker, type, combat, value)
if getPlayerStorageValue(cid, 122691) >= 1 and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
local aEvent = getPlayerStorageValue(attacker, eventConfig.indicatorStorage)
local cEvent = getPlayerStorageValue(cid, eventConfig.indicatorStorage)
if eventAreas[cEvent].etype == 1 then -- event most kills
if type == 1 and getCreatureHealth(cid) <= value then
local frags = getPlayerStorageValue(attacker, eventConfig.mostKillsFragCounter)
if frags == -1 then
setPlayerStorageValue(attacker, eventConfig.mostKillsFragCounter, 1)
else
setPlayerStorageValue(attacker, eventConfig.mostKillsFragCounter, frags + 1)
end
doPlayerSendTextMessage(attacker, MESSAGE_STATUS_WARNING, "You killed " .. getPlayerName(cid) .. "!" .. " You have " .. getPlayerStorageValue(attacker, eventConfig.mostKillsFragCounter) .. " frags!")
doTeleportThing(cid, eventAreas[cEvent].left)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
return false
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
elseif eventAreas[aEvent].etype == 3 then -- event team battle
if type == 1 and getCreatureHealth(cid) <= value then
local playerTeam = getPlayerStorageValue(attacker, eventConfig.teamBattleTeamStorage)
local targetTeam = getPlayerStorageValue(cid, eventConfig.teamBattleTeamStorage)
if playerTeam ~= targetTeam then
local frags = 0
local msg = ""
if playerTeam == 1 then
doSetStorage(eventAreas[aEvent].blacksFragsStorage, getStorage(eventAreas[aEvent].blacksFragsStorage) + 1)
elseif playerTeam == 2 then
doSetStorage(eventAreas[aEvent].whitesFragsStorage, getStorage(eventAreas[aEvent].whitesFragsStorage) + 1)
end
if getStorage(eventAreas[aEvent].blacksFragsStorage) > getStorage(eventAreas[aEvent].whitesFragsStorage) then
frags = getStorage(eventAreas[aEvent].blacksFragsStorage)
msg = "The Black Team is winning!"
elseif getStorage(eventAreas[aEvent].blacksFragsStorage) < getStorage(eventAreas[aEvent].whitesFragsStorage) then
frags = getStorage(eventAreas[aEvent].whitesFragsStorage)
msg = "The White Team is winning!"
else
msg = "The teams are even!"
end
doPlayerSendTextMessage(attacker, MESSAGE_STATUS_WARNING, "You owned " .. getPlayerName(cid) .. "!" .. " Your team has " .. frags .. " frags!")
doBroadcastMessage("Black team " .. getStorage(eventAreas[aEvent].blacksFragsStorage) .. ":" .. getStorage(eventAreas[aEvent].whitesFragsStorage) .. " White team. " .. msg)
end
doTeleportThing(cid, eventAreas[aEvent].exit)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
return false
end
----------------------------------------------------------------------------------- LMS REWARD SYSTEM ----------------------------------------------------------------------------------
elseif eventAreas[aEvent].etype == 4 then -- last man standing event tier 1
if type == 1 and getCreatureHealth(cid) <= value then
doSetStorage(eventAreas[aEvent].killCounter, getStorage(eventAreas[aEvent].killCounter) + 1)
doTeleportThing(cid, eventAreas[aEvent].exit)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
setPlayerStorageValue(cid, eventConfig.indicatorStorage, 0)
if getStorage(eventAreas[aEvent].killCounter) - waitingAreas[aEvent].people == 0 then -- last man winning
doTeleportThing(attacker, eventAreas[aEvent].exit)
doBroadcastMessage("The winner of the Tier 1 Last Man Standing event is " .. getPlayerName(attacker) .. ". Congratulations! Reward: 1 Token, 2 Gold Ingots.", MESSAGE_EVENT_ADVANCE)
doPlayerAddItem(attacker, 8309, 1) -- reward is 1 token
doPlayerAddItem(attacker, 9971, 2) -- reward is 2 gold ingot
doSetStorage(eventConfig.indicatorStorage + aEvent, 0)
setPlayerStorageValue(attacker, eventConfig.indicatorStorage, 0)
doCreatureAddHealth(attacker, getCreatureMaxHealth(attacker))
doCreatureAddMana(attacker, getCreatureMaxMana(attacker))
end
return false
end
----------------------------------------------------------------------------------- ----------------- ----------------------------------------------------------------------------------
elseif eventAreas[aEvent].etype == 5 then -- event ctf
if type == 1 and getCreatureHealth(cid) <= value then
local cidTeam = getPlayerStorageValue(cid, eventConfig.ctfTeamStorage)
local attackerTeam = getPlayerStorageValue(attacker, eventConfig.ctfTeamStorage)
local msg = ""
if cidTeam == 1 then
msg = "Black"
else
msg = "White"
end
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
if getPlayerStorageValue(cid, eventConfig.ctfFlagStorage) == 1 then
doBroadcastMessage(getPlayerName(attacker) .. " recovered the " .. msg .. " Team's Flag!")
setPlayerStorageValue(cid, eventConfig.ctfFlagStorage, 0)
end
if cidTeam == 1 then
doTeleportThing(cid, eventAreas[aEvent].blacksStartPos)
doTransformItem(eventAreas[aEvent].whiteBasinUid, 1484)
else
doTeleportThing(cid, eventAreas[aEvent].whitesStartPos)
doTransformItem(eventAreas[aEvent].blackBasinUid, 1484)
end
elseif type == 1 then
local cidTeam = getPlayerStorageValue(cid, eventConfig.ctfTeamStorage)
local attackerTeam = getPlayerStorageValue(attacker, eventConfig.ctfTeamStorage)
if eventAreas[aEvent].friendlyFire == false and cidTeam == attackerTeam then
doCreatureAddHealth(cid, value)
return false
end
return true
end
return false
end
end
return true
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
function onLogin(cid)
setPlayerStorageValue(cid, eventConfig.indicatorStorage, 0) -- zero event indicator
setPlayerStorageValue(cid, eventConfig.mostKillsFragCounter, 0) -- zero frag counter
setPlayerStorageValue(cid, eventConfig.ctfFlagStorage, 0)
for i = 1, #eventAreas do
if eventAreas[i].etype == 2 then
for j = 1, #eventAreas[i] do
if isInArea(getPlayerPosition(cid), eventAreas[i][j].left, eventAreas[i][j].right) == true then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
end
else
if isInArea(getPlayerPosition(cid), eventAreas[i].left, eventAreas[i].right) == true then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
end
end
return true
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
function onLogout(cid)
if getPlayerStorageValue(cid, eventConfig.indicatorStorage) > 0 then
doPlayerSendCancel(cid, "You may not logout while you are participating in an event.")
return false
end
return true
end
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
function onThink(cid, interval)
if isCreature(cid) then
if getPlayerStorageValue(cid, eventConfig.ctfFlagStorage) > 0 then
doSendMagicEffect(getPlayerPosition(cid), eventConfig.ctfFlagEffect)
end
end
return true
end