Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <mod name="Regicide Event" version="1.0" author="LuckOake" contact="none" enabled="yes">
- ------------------------------------------------------------------------------------
- <config name="king_func"><![CDATA[
- kingdom = {
- ["Protectors"] = {
- pos = {x = 168, y = 84, z = 7},
- storage = 51322,
- },
- ["Killers"] = {
- pos = {x = 168, y = 84, z = 7},
- storage = 51323,
- }
- }
- area1 = {x = 152, y = 77, z = 7} -- Ponta de cima na esquerda da área
- area2 = {x = 172, y = 93, z = 7} -- Ponta de baixo na direita da área
- stor = 51320
- tp_pos = {x = 155, y = 84, z = 7, stackpos = 1} -- Posição do teleport (Não altere o stackpos)
- maxplayers = 20 -- Máximo de players (De preferência, coloque um número par)
- wall = { -- Positions das paredes de bloqueio (Não altere o stackpos)
- [1] = {x = 167, y = 85, z = 7, stackpos = 1},
- [2] = {x = 167, y = 86, z = 7, stackpos = 1},
- }
- wallid = 1111 -- Id das walls
- king = "King" -- Nome do monstro que será o King
- kpos = {x = 170, y = 82, z = 7} -- Position que o King será criado
- prizes = {
- [1] = {id = 2149, count = 13},
- [2] = {id = 2149, count = 12},
- [3] = {id = 2149, count = 11}
- }
- prand = math.random(1, #prizes)
- function doCreatureFollow(cid, target, playerpos, targetpos, times)
- followstor = 51325
- if playerdir ~= getCreatureLookDirection(cid) then
- doCreatureSetLookDirection(target, getCreatureLookDirection(cid))
- end
- if playerpos ~= getCreaturePosition(cid) then
- if playerpos.z == getCreaturePosition(cid).z then
- ntpos = getCreaturePosition(cid)
- local x,y,z = ntpos.x-playerpos.x,ntpos.y-playerpos.y,ntpos.z-playerpos.z
- ntpos = getCreaturePosition(target)
- ntpos.x, ntpos.y, ntpos.z = ntpos.x+x,ntpos.y+y,ntpos.z+z
- if queryTileAddThing(target, ntpos) == RETURNVALUE_NOERROR and getCreaturePosition(cid).z == getCreaturePosition(target).z then
- doMoveCreature(target, getCreatureLookDirection(cid))
- end
- end
- end
- local playerpos, targetpos = getCreaturePosition(cid), getCreaturePosition(target)
- local mf = 1
- local times = mf+1
- if times > 0 and getPlayerStorageValue(cid, followstor) == 1 then
- addEvent(doCreatureFollow, 1, cid, target, playerpos, targetpos, times)
- else
- local times = 0
- doCreatureSetNoMove(target, false)
- end
- end
- function doCleanMonstersFromArea(toPositionX, fromPositionX, toPositionY, fromPositionY, toPositionZ, fromPositionZ)
- local monsters = {}
- for x = fromPositionX, toPositionX do
- for y = fromPositionY, toPositionY do
- for z = fromPositionZ, toPositionZ do
- local pos = {x=x,y=y,z=z, stackpos=253}
- if(isMonster(getThingfromPos(pos).uid)) then
- table.insert(isMonster(getThingfromPos(pos).uid) and monsters, getThingfromPos(pos).uid)
- end
- end
- end
- end
- for i = 1, #monsters do
- doRemoveCreature(monsters[i])
- end
- return true
- end
- function isMale(cid)
- return getPlayerSex(cid) == 1 and true or false
- end
- function isFemale(cid)
- return getPlayerSex(cid) == 0 and true or false
- end
- function getNumberType(n)
- return n % 2 == 0 and "par" or "impar"
- end
- function selectPlayerTeam(cid)
- if getNumberType(getGlobalStorageValue(stor)) == "par" then
- doTeleportThing(cid, kingdom["Protectors"].pos)
- setPlayerStorageValue(cid, 51321, 1)
- registerCreatureEvent(cid, "KingProtect")
- registerCreatureEvent(cid, "KingCast")
- setGlobalStorageValue(kingdom["Protectors"].storage, getGlobalStorageValue(kingdom["Protectors"].storage)+1)
- doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must PROTECT the King. Kill his enemies!")
- if isMale(cid) then
- doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
- elseif isFemale(cid) then
- doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
- end
- elseif getNumberType(getGlobalStorageValue(stor)) == "impar" then
- doTeleportThing(cid, kingdom["Killers"].pos)
- setPlayerStorageValue(cid, 51321, 2)
- registerCreatureEvent(cid, "KingKill")
- setGlobalStorageValue(kingdom["Killers"].storage, getGlobalStorageValue(kingdom["Killers"].storage)+1)
- doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must KILL the King. Crush him!")
- if isMale(cid) then
- doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
- elseif isFemale(cid) then
- doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
- end
- end
- setGlobalStorageValue(stor, getGlobalStorageValue(stor)+1)
- registerCreatureEvent(cid, "KingdomLogout")
- registerCreatureEvent(cid, "KingdomDeath")
- end
- function removeWalls()
- for _, walls in ipairs(wall) do
- doRemoveItem(getThingFromPos(walls).uid, 1)
- end
- end
- function createWalls()
- for _, walls in ipairs(wall) do
- doCreateItem(wallid, 1, walls)
- end
- end
- function startEvent()
- doRemoveItem(getThingFromPos(tp_pos).uid, 1)
- doSendMagicEffect(tp_pos, 2)
- doCreateMonster(king, kpos)
- broadcastMessage("Regicide Event started.")
- removeWalls()
- end
- function resetEvent()
- for _, pid in ipairs(getPlayersOnline()) do
- if isInArea(getCreaturePosition(pid), area1, area2) then
- if getPlayerStorageValue(pid, 51325) == 1 then
- setPlayerStorageValue(pid, 51325, -1)
- end
- setPlayerStorageValue(pid, 51321, -1)
- doRemoveCondition(pid, CONDITION_OUTFIT)
- doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
- setGlobalStorageValue(stor, -1)
- setGlobalStorageValue(51324, -1)
- setGlobalStorageValue(51326, -1)
- setGlobalStorageValue(kingdom["Protectors"].storage, -1)
- setGlobalStorageValue(kingdom["Killers"].storage, -1)
- doCleanMonstersFromArea(area2.x, area1.x, area2.y, area1.y, area2.z, area1.z)
- addEvent(doRemoveCreature, 3000, pid)
- end
- end
- createWalls()
- end
- function isProtector(cid)
- return getPlayerStorageValue(cid, 51321) == 1 and true or false
- end
- function isKiller(cid)
- return getPlayerStorageValue(cid, 51321) == 2 and true or false
- end
- function openTeleport()
- local tp = 1387
- local tele = doCreateItem(tp, 1, tp_pos)
- setGlobalStorageValue(kingdom["Protectors"].storage, 0)
- setGlobalStorageValue(kingdom["Killers"].storage, 0)
- doItemSetAttribute(tele, "aid", 15781)
- doSendMagicEffect(tp_pos, 10)
- setGlobalStorageValue(51320, 0)
- broadcastMessage("Regicide Event is now open!")
- end
- ]]></config>
- ------------------------------------------------------------------------------------
- <talkaction words="/regicide" access="5" event="buffer"><![CDATA[
- domodlib('king_func')
- if not param then
- doPlayerSendCancel(cid, "Incorrect params. Choose if the event will "open", "force" or "reset".") return true
- elseif param == "open" then
- if getGlobalStorageValue(stor) ~= -1 or getGlobalStorageValue(stor) > 0 then
- doPlayerSendCancel(cid, "You can't start the event now.") return true
- end
- openTeleport()
- doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've opened the Regicide event.") return true
- elseif param == "force" then
- if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(51324) >= 1 then
- doPlayerSendCancel(cid, "You can't force the event now.") return true
- end
- setGlobalStorageValue(51324, 1)
- startEvent()
- doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've closed the Regicide event.") return true
- elseif param == "reset" then
- if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(51324) == -1 then
- doPlayerSendCancel(cid, "You can't end the event now.") return true
- end
- resetEvent()
- doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've reseted the Regicide event.") return true
- end
- return true
- ]]></talkaction>
- ------------------------------------------------------------------------------------
- <movevent type="StepIn" actionid="15781" event="script"><![CDATA[
- domodlib('king_func')
- function onStepIn(cid, position, fromPosition)
- if getGlobalStorageValue(51320) == (maxplayers-1) then
- setGlobalStorageValue(51324, 1)
- startEvent()
- else
- broadcastMessage(""..getCreatureName(cid).." entered in the Regicide Event. There is "..(maxplayers-(getGlobalStorageValue(stor)+1)).." slots remaining.")
- end
- selectPlayerTeam(cid)
- return true
- end
- ]]></movevent>
- ------------------------------------------------------------------------------------
- <event type="logout" name="KingdomLogout" event="script"><![CDATA[
- domodlib('king_func')
- function onLogout(cid)
- if getPlayerStorageValue(cid, 51321) >= 1 then
- doPlayerSendCancel(cid, "You can't logout when you are in this event!") return false
- end
- return true
- end
- ]]></event>
- ------------------------------------------------------------------------------------
- <event type="preparedeath" name="KingdomDeath" event="script"><![CDATA[
- domodlib('king_func')
- function onPrepareDeath(cid)
- if isKiller(cid) and getGlobalStorageValue(kingdom["Killers"].storage) > 1 then
- setGlobalStorageValue(kingdom["Killers"].storage, getGlobalStorageValue(kingdom["Killers"].storage)-1)
- broadcastMessage(""..getCreatureName(cid).." [KILLER] died. "..getGlobalStorageValue(kingdom["Protectors"].storage).." Protectors and "..getGlobalStorageValue(kingdom["Killers"].storage).." Killers left.")
- elseif isKiller(cid) and getGlobalStorageValue(kingdom["Killers"].storage) == 1 then
- for _, wid in ipairs(getPlayersOnline()) do
- if isProtector(wid) then
- if not doPlayerAddItem(wid, prizes[prand].id, prizes[prand].count) then
- local parcel = doCreateItemEx(ITEM_PARCEL)
- doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
- doPlayerSendMailByName(getCreatureName(wid), parcel, getPlayerTown(wid))
- doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
- end
- doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
- end
- end
- broadcastMessage("All the Killers are dead. Protectors won the Regicide Event!")
- resetEvent()
- elseif isProtector(cid) then
- setGlobalStorageValue(kingdom["Protectors"].storage, getGlobalStorageValue(kingdom["Protectors"].storage)-1)
- broadcastMessage(""..getCreatureName(cid).." [PROTECTOR] died. "..getGlobalStorageValue(kingdom["Protectors"].storage).." Protectors and "..getGlobalStorageValue(kingdom["Killers"].storage).." Killers left.")
- end
- setPlayerStorageValue(cid, 51321, -1)
- doCreatureSetDropLoot(cid, false)
- doPlayerSetLossSkill(cid, 0)
- doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, 0)
- return true
- end
- ]]></event>
- ------------------------------------------------------------------------------------
- <event type="target" name="KingProtect" event="script"><![CDATA[
- domodlib('king_func')
- function onTarget(cid, target)
- if isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) ~= 1 and getGlobalStorageValue(51326) == -1 then
- local times = 1
- local playerpos,playerdir,targetpos = getCreaturePosition(cid), getPlayerLookDir(cid), getCreaturePosition(target)
- setPlayerStorageValue(cid, followstor, 1)
- addEvent(doCreatureFollow, 1000, cid, target, playerpos, targetpos, times)
- doCreatureSetNoMove(target, true)
- setGlobalStorageValue(51326, 1)
- doCreatureSay(cid, "King, follow me!") return false
- elseif isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) == 1 then
- doCreatureSetNoMove(target, false)
- setPlayerStorageValue(cid, followstor, -1)
- setGlobalStorageValue(51326, -1)
- doCreatureSay(cid, "King, stop following me!") return false
- elseif isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) ~= 1 and getGlobalStorageValue(51326) == 1 then
- doPlayerSendCancel(cid, "Sorry, but the king is already following someone.") return false
- end
- return true
- end
- ]]></event>
- ------------------------------------------------------------------------------------
- <event type="combat" name="KingCast" event="script"><![CDATA[
- domodlib('king_func')
- function onCombat(cid, target)
- if isPlayer(cid) and isMonster(target) then
- if isProtector(cid) and string.lower(getCreatureName(target)) == string.lower(king) then
- doPlayerSendCancel(cid, "You may not attack the King.") return false
- end
- end
- if isPlayer(cid) and isPlayer(target) then
- if isProtector(cid) and isProtector(target) or isKiller(cid) and isKiller(target) then
- doPlayerSendCancel(cid, "You may not attack your team mates.") return false
- end
- end
- return true
- end
- ]]></event>
- ------------------------------------------------------------------------------------
- <event type="kill" name="KingKill" event="script"><![CDATA[
- domodlib('king_func')
- function onKill(cid, target)
- if isKiller(cid) and isMonster(target) then
- for _, tid in ipairs(getPlayersOnline()) do
- if isKiller(tid) then
- if not doPlayerAddItem(tid, prizes[prand].id, prizes[prand].count) then
- local parcel = doCreateItemEx(ITEM_PARCEL)
- doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
- doPlayerSendMailByName(getCreatureName(tid), parcel, getPlayerTown(tid))
- doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
- end
- doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
- end
- end
- broadcastMessage(""..getCreatureName(cid).." killed the King and won the battle for the Killers!")
- resetEvent()
- end
- return true
- end]]></event>
- </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement