Advertisement
Guest User

Regicide Event

a guest
Oct 7th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.53 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <mod name="Regicide Event" version="1.0" author="LuckOake" contact="none" enabled="yes">
  3. ------------------------------------------------------------------------------------
  4. <config name="king_func"><![CDATA[
  5. kingdom = {
  6.     ["Protectors"] = {
  7.         pos = {x = 168, y = 84, z = 7},
  8.         storage = 51322,
  9.     },
  10.     ["Killers"] = {
  11.         pos = {x = 168, y = 84, z = 7},
  12.         storage = 51323,
  13.     }
  14. }
  15.  
  16. area1 = {x = 152, y = 77, z = 7} -- Ponta de cima na esquerda da área
  17. area2 = {x = 172, y = 93, z = 7} -- Ponta de baixo na direita da área
  18. stor = 51320
  19. tp_pos = {x = 155, y = 84, z = 7, stackpos = 1} -- Posição do teleport (Não altere o stackpos)
  20. maxplayers = 20 -- Máximo de players (De preferência, coloque um número par)
  21. wall = { -- Positions das paredes de bloqueio (Não altere o stackpos)
  22.     [1] = {x = 167, y = 85, z = 7, stackpos = 1},
  23.     [2] = {x = 167, y = 86, z = 7, stackpos = 1},
  24.     }
  25. wallid = 1111 -- Id das walls
  26. king = "King" -- Nome do monstro que será o King
  27. kpos = {x = 170, y = 82, z = 7} -- Position que o King será criado
  28. prizes = {
  29. [1] = {id = 2149, count = 13},
  30. [2] = {id = 2149, count = 12},
  31. [3] = {id = 2149, count = 11}
  32. }
  33. prand = math.random(1, #prizes)
  34.  
  35. function doCreatureFollow(cid, target, playerpos, targetpos, times)
  36.     followstor = 51325
  37.     if playerdir ~= getCreatureLookDirection(cid) then
  38.         doCreatureSetLookDirection(target, getCreatureLookDirection(cid))
  39.     end
  40.  
  41.     if playerpos ~= getCreaturePosition(cid) then
  42.         if playerpos.z == getCreaturePosition(cid).z then
  43.         ntpos = getCreaturePosition(cid)
  44.         local x,y,z = ntpos.x-playerpos.x,ntpos.y-playerpos.y,ntpos.z-playerpos.z
  45.         ntpos = getCreaturePosition(target)
  46.         ntpos.x, ntpos.y, ntpos.z = ntpos.x+x,ntpos.y+y,ntpos.z+z
  47.             if queryTileAddThing(target, ntpos) == RETURNVALUE_NOERROR and getCreaturePosition(cid).z == getCreaturePosition(target).z then
  48.                 doMoveCreature(target, getCreatureLookDirection(cid))
  49.             end
  50.         end
  51.     end
  52.     local playerpos, targetpos = getCreaturePosition(cid), getCreaturePosition(target)
  53.     local mf = 1
  54.     local times = mf+1
  55.     if times > 0 and getPlayerStorageValue(cid, followstor) == 1 then
  56.         addEvent(doCreatureFollow, 1, cid, target, playerpos, targetpos, times)
  57.     else
  58.     local times = 0
  59.         doCreatureSetNoMove(target, false)
  60.     end
  61. end
  62.  
  63. function doCleanMonstersFromArea(toPositionX, fromPositionX, toPositionY, fromPositionY, toPositionZ, fromPositionZ)
  64. local monsters = {}
  65. for x = fromPositionX, toPositionX do
  66.     for y = fromPositionY, toPositionY do
  67.         for z = fromPositionZ, toPositionZ do
  68.             local pos = {x=x,y=y,z=z, stackpos=253}
  69.             if(isMonster(getThingfromPos(pos).uid)) then
  70.                 table.insert(isMonster(getThingfromPos(pos).uid) and monsters, getThingfromPos(pos).uid)
  71.             end
  72.         end
  73.     end
  74. end
  75. for i = 1, #monsters do
  76.     doRemoveCreature(monsters[i])
  77. end
  78. return true
  79. end
  80.  
  81. function isMale(cid)
  82. return getPlayerSex(cid) == 1 and true or false
  83. end
  84.  
  85. function isFemale(cid)
  86. return getPlayerSex(cid) == 0 and true or false
  87. end
  88.  
  89. function getNumberType(n)
  90. return n % 2 == 0 and "par" or "impar"
  91. end
  92.  
  93. function selectPlayerTeam(cid)
  94.     if getNumberType(getGlobalStorageValue(stor)) == "par" then
  95.         doTeleportThing(cid, kingdom["Protectors"].pos)
  96.         setPlayerStorageValue(cid, 51321, 1)
  97.         registerCreatureEvent(cid, "KingProtect")
  98.         registerCreatureEvent(cid, "KingCast")
  99.         setGlobalStorageValue(kingdom["Protectors"].storage, getGlobalStorageValue(kingdom["Protectors"].storage)+1)
  100.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must PROTECT the King. Kill his enemies!")
  101.     if isMale(cid) then
  102.         doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
  103.     elseif isFemale(cid) then
  104.         doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
  105.     end
  106.     elseif getNumberType(getGlobalStorageValue(stor)) == "impar" then
  107.         doTeleportThing(cid, kingdom["Killers"].pos)
  108.         setPlayerStorageValue(cid, 51321, 2)
  109.         registerCreatureEvent(cid, "KingKill")
  110.         setGlobalStorageValue(kingdom["Killers"].storage, getGlobalStorageValue(kingdom["Killers"].storage)+1)
  111.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must KILL the King. Crush him!")
  112.     if isMale(cid) then
  113.         doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
  114.     elseif isFemale(cid) then
  115.         doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
  116.     end
  117.     end
  118.         setGlobalStorageValue(stor, getGlobalStorageValue(stor)+1)
  119.         registerCreatureEvent(cid, "KingdomLogout")
  120.         registerCreatureEvent(cid, "KingdomDeath")
  121. end
  122.  
  123. function removeWalls()
  124.     for _, walls in ipairs(wall) do
  125.         doRemoveItem(getThingFromPos(walls).uid, 1)
  126.     end
  127. end
  128.  
  129. function createWalls()
  130.     for _, walls in ipairs(wall) do
  131.         doCreateItem(wallid, 1, walls)
  132.     end
  133. end
  134.  
  135. function startEvent()
  136.     doRemoveItem(getThingFromPos(tp_pos).uid, 1)
  137.     doSendMagicEffect(tp_pos, 2)
  138.     doCreateMonster(king, kpos)
  139.     broadcastMessage("Regicide Event started.")
  140.     removeWalls()
  141. end
  142.    
  143. function resetEvent()
  144.     for _, pid in ipairs(getPlayersOnline()) do
  145.         if isInArea(getCreaturePosition(pid), area1, area2) then
  146.             if getPlayerStorageValue(pid, 51325) == 1 then
  147.                 setPlayerStorageValue(pid, 51325, -1)
  148.             end
  149.             setPlayerStorageValue(pid, 51321, -1)
  150.             doRemoveCondition(pid, CONDITION_OUTFIT)
  151.             doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
  152.             setGlobalStorageValue(stor, -1)
  153.             setGlobalStorageValue(51324, -1)
  154.             setGlobalStorageValue(51326, -1)
  155.             setGlobalStorageValue(kingdom["Protectors"].storage, -1)
  156.             setGlobalStorageValue(kingdom["Killers"].storage, -1)
  157.             doCleanMonstersFromArea(area2.x, area1.x, area2.y, area1.y, area2.z, area1.z)
  158.             addEvent(doRemoveCreature, 3000, pid)
  159.         end
  160.     end
  161.             createWalls()
  162. end
  163.  
  164. function isProtector(cid)
  165. return getPlayerStorageValue(cid, 51321) == 1 and true or false
  166. end
  167.  
  168. function isKiller(cid)
  169. return getPlayerStorageValue(cid, 51321) == 2 and true or false
  170. end
  171.  
  172. function openTeleport()
  173.     local tp = 1387
  174.     local tele = doCreateItem(tp, 1, tp_pos)
  175.         setGlobalStorageValue(kingdom["Protectors"].storage, 0)
  176.         setGlobalStorageValue(kingdom["Killers"].storage, 0)
  177.         doItemSetAttribute(tele, "aid", 15781)
  178.         doSendMagicEffect(tp_pos, 10)
  179.         setGlobalStorageValue(51320, 0)
  180.         broadcastMessage("Regicide Event is now open!")
  181. end
  182. ]]></config>
  183. ------------------------------------------------------------------------------------
  184. <talkaction words="/regicide" access="5" event="buffer"><![CDATA[
  185. domodlib('king_func')
  186.     if not param then
  187.         doPlayerSendCancel(cid, "Incorrect params. Choose if the event will "open", "force" or "reset".") return true
  188.     elseif param == "open" then
  189.         if getGlobalStorageValue(stor) ~= -1 or getGlobalStorageValue(stor) > 0 then
  190.             doPlayerSendCancel(cid, "You can't start the event now.") return true
  191.         end
  192.             openTeleport()
  193.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've opened the Regicide event.") return true
  194.     elseif param == "force" then
  195.         if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(51324) >= 1 then
  196.             doPlayerSendCancel(cid, "You can't force the event now.") return true
  197.         end
  198.             setGlobalStorageValue(51324, 1)
  199.             startEvent()
  200.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've closed the Regicide event.") return true
  201.     elseif param == "reset" then
  202.         if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(51324) == -1 then
  203.             doPlayerSendCancel(cid, "You can't end the event now.") return true
  204.         end
  205.             resetEvent()
  206.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've reseted the Regicide event.") return true
  207.     end
  208. return true
  209. ]]></talkaction>
  210. ------------------------------------------------------------------------------------
  211. <movevent type="StepIn" actionid="15781" event="script"><![CDATA[
  212. domodlib('king_func')
  213. function onStepIn(cid, position, fromPosition)
  214.     if getGlobalStorageValue(51320) == (maxplayers-1) then
  215.         setGlobalStorageValue(51324, 1)
  216.         startEvent()
  217.     else
  218.         broadcastMessage(""..getCreatureName(cid).." entered in the Regicide Event. There is "..(maxplayers-(getGlobalStorageValue(stor)+1)).." slots remaining.")
  219.     end
  220.         selectPlayerTeam(cid)
  221. return true
  222. end
  223. ]]></movevent>
  224. ------------------------------------------------------------------------------------
  225. <event type="logout" name="KingdomLogout" event="script"><![CDATA[  
  226. domodlib('king_func')
  227. function onLogout(cid)
  228.     if getPlayerStorageValue(cid, 51321) >= 1 then
  229.         doPlayerSendCancel(cid, "You can't logout when you are in this event!") return false
  230.     end
  231. return true
  232. end
  233. ]]></event>
  234. ------------------------------------------------------------------------------------
  235. <event type="preparedeath" name="KingdomDeath" event="script"><![CDATA[  
  236. domodlib('king_func')
  237. function onPrepareDeath(cid)
  238.     if isKiller(cid) and getGlobalStorageValue(kingdom["Killers"].storage) > 1 then
  239.         setGlobalStorageValue(kingdom["Killers"].storage, getGlobalStorageValue(kingdom["Killers"].storage)-1)
  240.         broadcastMessage(""..getCreatureName(cid).." [KILLER] died. "..getGlobalStorageValue(kingdom["Protectors"].storage).." Protectors and "..getGlobalStorageValue(kingdom["Killers"].storage).." Killers left.")
  241.     elseif isKiller(cid) and getGlobalStorageValue(kingdom["Killers"].storage) == 1 then
  242.         for _, wid in ipairs(getPlayersOnline()) do
  243.             if isProtector(wid) then
  244.                 if not doPlayerAddItem(wid, prizes[prand].id, prizes[prand].count) then
  245.                 local parcel = doCreateItemEx(ITEM_PARCEL)
  246.                     doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
  247.                     doPlayerSendMailByName(getCreatureName(wid), parcel, getPlayerTown(wid))
  248.                     doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
  249.                 end
  250.                     doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
  251.             end
  252.         end
  253.         broadcastMessage("All the Killers are dead. Protectors won the Regicide Event!")
  254.         resetEvent()
  255.     elseif isProtector(cid) then
  256.         setGlobalStorageValue(kingdom["Protectors"].storage, getGlobalStorageValue(kingdom["Protectors"].storage)-1)
  257.         broadcastMessage(""..getCreatureName(cid).." [PROTECTOR] died. "..getGlobalStorageValue(kingdom["Protectors"].storage).." Protectors and "..getGlobalStorageValue(kingdom["Killers"].storage).." Killers left.")
  258.     end
  259.         setPlayerStorageValue(cid, 51321, -1)
  260.         doCreatureSetDropLoot(cid, false)
  261.         doPlayerSetLossSkill(cid, 0)
  262.         doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, 0)
  263. return true
  264. end
  265. ]]></event>
  266. ------------------------------------------------------------------------------------
  267. <event type="target" name="KingProtect" event="script"><![CDATA[  
  268. domodlib('king_func')
  269. function onTarget(cid, target)
  270.     if isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) ~= 1 and getGlobalStorageValue(51326) == -1 then
  271.     local times = 1
  272.     local playerpos,playerdir,targetpos = getCreaturePosition(cid), getPlayerLookDir(cid), getCreaturePosition(target)
  273.         setPlayerStorageValue(cid, followstor, 1)
  274.         addEvent(doCreatureFollow, 1000, cid, target, playerpos, targetpos, times)
  275.         doCreatureSetNoMove(target, true)
  276.         setGlobalStorageValue(51326, 1)
  277.         doCreatureSay(cid, "King, follow me!") return false
  278.     elseif isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) == 1 then
  279.         doCreatureSetNoMove(target, false)
  280.         setPlayerStorageValue(cid, followstor, -1)
  281.         setGlobalStorageValue(51326, -1)
  282.         doCreatureSay(cid, "King, stop following me!") return false
  283.     elseif isProtector(cid) and isMonster(target) and getPlayerStorageValue(cid, followstor) ~= 1 and getGlobalStorageValue(51326) == 1 then
  284.         doPlayerSendCancel(cid, "Sorry, but the king is already following someone.") return false
  285.     end
  286. return true
  287. end
  288. ]]></event>
  289. ------------------------------------------------------------------------------------
  290. <event type="combat" name="KingCast" event="script"><![CDATA[  
  291. domodlib('king_func')
  292. function onCombat(cid, target)
  293.     if isPlayer(cid) and isMonster(target) then
  294.         if isProtector(cid) and string.lower(getCreatureName(target)) == string.lower(king) then
  295.             doPlayerSendCancel(cid, "You may not attack the King.") return false
  296.         end
  297.     end
  298.     if isPlayer(cid) and isPlayer(target) then
  299.         if isProtector(cid) and isProtector(target) or isKiller(cid) and isKiller(target) then
  300.             doPlayerSendCancel(cid, "You may not attack your team mates.") return false
  301.         end
  302.     end
  303. return true
  304. end
  305. ]]></event>
  306. ------------------------------------------------------------------------------------
  307. <event type="kill" name="KingKill" event="script"><![CDATA[
  308. domodlib('king_func')
  309. function onKill(cid, target)
  310.     if isKiller(cid) and isMonster(target) then
  311.         for _, tid in ipairs(getPlayersOnline()) do
  312.             if isKiller(tid) then
  313.                 if not doPlayerAddItem(tid, prizes[prand].id, prizes[prand].count) then
  314.                 local parcel = doCreateItemEx(ITEM_PARCEL)
  315.                     doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
  316.                     doPlayerSendMailByName(getCreatureName(tid), parcel, getPlayerTown(tid))
  317.                     doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
  318.                 end
  319.                     doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
  320.             end
  321.         end
  322.             broadcastMessage(""..getCreatureName(cid).." killed the King and won the battle for the Killers!")
  323.             resetEvent()
  324.     end
  325. return true
  326. end]]></event>
  327. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement