Advertisement
LuckOake

Defend The Generator

Dec 16th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.25 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <mod name="Defend The Generator" version="1.0" author="LuckOake" contact="none" enabled="yes">
  3. -----------------------------------------------------------------------
  4. <config name="generator"><![CDATA[
  5. teams = {
  6.     ["Defenders"] = {
  7.         pos = {x = 314, y = 127, z = 7},
  8.         storage = 43110,
  9.     },
  10.     ["Invaders"] = {
  11.         pos = {x = 317, y = 127, z = 7},
  12.         storage = 43111,
  13.     }
  14. }
  15.  
  16. defpos,defstor = teams["Defenders"].pos,teams["Defenders"].storage
  17. invpos,invstor = teams["Invaders"].pos,teams["Invaders"].storage
  18. stor = 43112
  19. tstor = 43113
  20. sstor = 43114
  21. gstor = 43115
  22.  
  23. area1 = {x = 311, y = 126, z = 7} -- Ponta de cima na esquerda da área
  24. area2 = {x = 320, y = 131, z = 7} -- Ponta de baixo na direita da área
  25. tp_pos = {x = 316, y = 132, z = 7, stackpos = 1} -- Posição do teleport (Não altere o stackpos)
  26. sparkpos = {x = 316, y = 127, z = 7} -- Posição dos sparks do Gerador
  27. maxplayers = 20 -- Máximo de players (De preferência, coloque um número par)
  28. gtime = 10 -- Quantos segundos o gerador deverá ficar desligado para que os Invaders vençam
  29. wall = { -- Positions das paredes de bloqueio (Não altere o stackpos)
  30.     [1] = {x = 316, y = 126, z = 7, stackpos = 1},
  31.     [2] = {x = 316, y = 127, z = 7, stackpos = 1},
  32.     }
  33. wallid = 1111 -- Id das walls
  34. prizes = {
  35. [1] = {id = 2149, count = 13},
  36. [2] = {id = 2149, count = 12},
  37. [3] = {id = 2149, count = 11}
  38. }
  39. prand = math.random(1, #prizes)
  40.  
  41. function isMale(cid)
  42.     return getPlayerSex(cid) == 1 and true or false
  43. end
  44.  
  45. function isFemale(cid)
  46.     return getPlayerSex(cid) == 0 and true or false
  47. end
  48.  
  49. function getNumberType(n)
  50.     return n % 2 == 0 and "par" or "impar"
  51. end
  52.  
  53. function selectPlayerTeam(cid)
  54.     if getNumberType(getGlobalStorageValue(stor)) == "par" then
  55.         doTeleportThing(cid, defpos)
  56.         setPlayerStorageValue(cid, tstor, 1)
  57.         registerCreatureEvent(cid, "GeneratorCast")
  58.         setGlobalStorageValue(defstor, getGlobalStorageValue(defstor)+1)
  59.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must DEFEND the Generator. Kill the invaders!")
  60.     if isMale(cid) then
  61.         doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
  62.     elseif isFemale(cid) then
  63.         doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88}, -1)
  64.     end
  65.     elseif getNumberType(getGlobalStorageValue(stor)) == "impar" then
  66.         doTeleportThing(cid, invpos)
  67.         setPlayerStorageValue(cid, tstor, 2)
  68.         setGlobalStorageValue(invstor, getGlobalStorageValue(invstor)+1)
  69.         doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You must DISABLE the Generator. Crush the defenders!")
  70.     if isMale(cid) then
  71.         doSetCreatureOutfit(cid, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
  72.     elseif isFemale(cid) then
  73.         doSetCreatureOutfit(cid, {lookType = math.random(136,142), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94}, -1)
  74.     end
  75.     end
  76.         setGlobalStorageValue(stor, getGlobalStorageValue(stor)+1)
  77.         registerCreatureEvent(cid, "GeneratorLogout")
  78.         registerCreatureEvent(cid, "GeneratorDeath")
  79. end
  80.  
  81. function removeWalls()
  82.     for _, walls in ipairs(wall) do
  83.         doRemoveItem(getThingFromPos(walls).uid, 1)
  84.     end
  85. end
  86.  
  87. function createWalls()
  88.     for _, walls in ipairs(wall) do
  89.         doCreateItem(wallid, 1, walls)
  90.     end
  91. end
  92.  
  93. function isGeneratorActived()
  94. return getGlobalStorageValue(gstor) == 1 and true or false
  95. end
  96.  
  97. function generateSparks()
  98.     if isGeneratorActived() then   
  99.         doSendMagicEffect(sparkpos, 11)
  100.         addEvent(generateSparks, 1000)
  101.     end
  102. end
  103.  
  104. function startEvent()
  105.     setGlobalStorageValue(gstor, 1)
  106.     generateSparks()
  107.     doRemoveItem(getThingFromPos(tp_pos).uid, 1)
  108.     doSendMagicEffect(tp_pos, 2)
  109.     broadcastMessage("Defend The Generator Event started.")
  110.     removeWalls()
  111. end
  112.  
  113. function resetEvent()
  114.     for _, pid in ipairs(getPlayersOnline()) do
  115.         if isDefender(pid) or isInvader(pid) then
  116.             setPlayerStorageValue(pid, tstor, -1)
  117.             doRemoveCondition(pid, CONDITION_OUTFIT)
  118.             doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
  119.             addEvent(doRemoveCreature, 3000, pid)
  120.         end
  121.     end
  122.             setGlobalStorageValue(stor, -1)
  123.             setGlobalStorageValue(sstor, -1)
  124.             setGlobalStorageValue(defstor, -1)
  125.             setGlobalStorageValue(invstor, -1)
  126.             setGlobalStorageValue(gstor, -1)
  127.             createWalls()
  128. end
  129.  
  130. function destroyGenerator()
  131.     if getGlobalStorageValue(stor) == -1 then return true end
  132.     for _, tid in ipairs(getPlayersOnline()) do
  133.         if isInvader(tid) then
  134.             if not doPlayerAddItem(tid, prizes[prand].id, prizes[prand].count) then
  135.             local parcel = doCreateItemEx(ITEM_PARCEL)
  136.                 doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
  137.                 doPlayerSendMailByName(getCreatureName(tid), parcel, getPlayerTown(tid))
  138.                 doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
  139.             end
  140.                 doPlayerSendTextMessage(tid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
  141.         end
  142.     end
  143.     broadcastMessage("The generator is destroyed! The Invaders Team won!")
  144.     resetEvent()
  145. end
  146.  
  147. function isDefender(cid)
  148. return getPlayerStorageValue(cid, tstor) == 1 and true or false
  149. end
  150.  
  151. function isInvader(cid)
  152. return getPlayerStorageValue(cid, tstor) == 2 and true or false
  153. end
  154.  
  155. function openTeleport()
  156.     local tp = 1387
  157.     local tele = doCreateItem(tp, 1, tp_pos)
  158.         setGlobalStorageValue(defstor, 0)
  159.         setGlobalStorageValue(invstor, 0)
  160.         doItemSetAttribute(tele, "aid", 23590)
  161.         doSendMagicEffect(tp_pos, 10)
  162.         setGlobalStorageValue(stor, 0)
  163.         broadcastMessage("Defend The Generator Event is now open!")
  164. end
  165. ]]></config>
  166. ------------------------------------------------------------------------------------
  167. <talkaction words="/generator" access="5" event="buffer"><![CDATA[
  168. domodlib('generator')
  169.     if not param then
  170.         doPlayerSendCancel(cid, 'Incorrect params. Choose if the event will "open", "force" or "reset".') return true
  171.     elseif param == "open" then
  172.         if getGlobalStorageValue(stor) ~= -1 or getGlobalStorageValue(stor) > 0 then
  173.             doPlayerSendCancel(cid, "You can't start the event now.") return true
  174.         end
  175.             openTeleport()
  176.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've opened the Defend The Generator event.") return true
  177.     elseif param == "force" then
  178.         if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(sstor) >= 1 then
  179.             doPlayerSendCancel(cid, "You can't force the event now.") return true
  180.         end
  181.             setGlobalStorageValue(sstor, 1)
  182.             startEvent()
  183.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've closed the Defend The Generator event.") return true
  184.     elseif param == "reset" then
  185.         if getGlobalStorageValue(stor) == -1 or getGlobalStorageValue(sstor) == -1 then
  186.             doPlayerSendCancel(cid, "You can't end the event now.") return true
  187.         end
  188.             resetEvent()
  189.             doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You've reseted the Defend The Generator event.") return true
  190.     end
  191. return true
  192. ]]></talkaction>
  193. ------------------------------------------------------------------------------------
  194. <action actionid="25177" event="script"><![CDATA[
  195. domodlib('generator')
  196.     if isDefender(cid) and isGeneratorActived() then
  197.         doPlayerSendCancel(cid, "You cannot deactivate the generator. You are defending it!") return true
  198.     elseif isInvader(cid) and isGeneratorActived() then
  199.         setGlobalStorageValue(gstor, -1)
  200.         broadcastMessage(""..getCreatureName(cid).." [INVADER] turned OFF the generator! Defenders Team now have "..gtime.." seconds to turn on it again or they will lose!")
  201.         y = addEvent(destroyGenerator, gtime*1000)
  202.     elseif isDefender(cid) and not isGeneratorActived() then
  203.         setGlobalStorageValue(gstor, 1)
  204.         generateSparks()
  205.         broadcastMessage(""..getCreatureName(cid).." [DEFENDER] turned ON the generator!")
  206.         stopEvent(y)
  207.     elseif isInvader(cid) and not isGeneratorActived() then
  208.         doPlayerSendCancel(cid, "The generator is already off!") return true
  209.     end
  210.         doSendAnimatedText(getThingPos(item.uid), getGlobalStorageValue(gstor) == -1 and "Off!" or "On!", math.random(1, 255))
  211. return true
  212. ]]></action>
  213. ------------------------------------------------------------------------------------
  214. <movevent type="StepIn" actionid="23590" event="script"><![CDATA[
  215. domodlib('generator')
  216. function onStepIn(cid, position, fromPosition)
  217.     if getGlobalStorageValue(stor) == (maxplayers-1) then
  218.         setGlobalStorageValue(sstor, 1)
  219.         startEvent()
  220.     else
  221.         broadcastMessage(""..getCreatureName(cid).." entered in the Defend The Generator Event. There is "..(maxplayers-(getGlobalStorageValue(stor)+1)).." slots remaining.")
  222.     end
  223.         selectPlayerTeam(cid)
  224. return true
  225. end
  226. ]]></movevent>
  227. ------------------------------------------------------------------------------------
  228. <event type="logout" name="GeneratorLogout" event="script"><![CDATA[  
  229. domodlib('generator')
  230. function onLogout(cid)
  231.     if getPlayerStorageValue(cid, tstor) >= 1 then
  232.         doPlayerSendCancel(cid, "You can't logout when you are in this event!") return false
  233.     end
  234. return true
  235. end
  236. ]]></event>
  237. ------------------------------------------------------------------------------------
  238. <event type="preparedeath" name="GeneratorDeath" event="script"><![CDATA[  
  239. domodlib('generator')
  240. function onPrepareDeath(cid)
  241.     if isInvader(cid) and getGlobalStorageValue(invstor) > 1 then
  242.         setGlobalStorageValue(invstor, getGlobalStorageValue(invstor)-1)
  243.         broadcastMessage(""..getCreatureName(cid).." [INVADER] died. "..getGlobalStorageValue(defstor).." Defenders and "..getGlobalStorageValue(invstor).." Invaders left.")
  244.     elseif isInvader(cid) and getGlobalStorageValue(invstor) == 1 then
  245.         for _, wid in ipairs(getPlayersOnline()) do
  246.             if isDefender(wid) then
  247.                 if not doPlayerAddItem(wid, prizes[prand].id, prizes[prand].count) then
  248.                 local parcel = doCreateItemEx(ITEM_PARCEL)
  249.                     doAddContainerItem(parcel, prizes[prand].id, prizes[prand].count)
  250.                     doPlayerSendMailByName(getCreatureName(wid), parcel, getPlayerTown(wid))
  251.                     doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap. Your prize was sent to the depot.")
  252.                 end
  253.                     doPlayerSendTextMessage(wid, MESSAGE_STATUS_CONSOLE_BLUE, "You win "..prizes[prand].count.."x "..getItemNameById(prizes[prand].id)..".")
  254.             end
  255.         end
  256.         broadcastMessage("All the Invaders are dead. Defenders won the Defend The Generator Event!")
  257.         resetEvent()
  258.     elseif isDefender(cid) then
  259.         setGlobalStorageValue(defstor, getGlobalStorageValue(defstor)-1)
  260.         broadcastMessage(""..getCreatureName(cid).." [DEFENDER] died. "..getGlobalStorageValue(defstor).." Defenders and "..getGlobalStorageValue(invstor).." Invaders left.")
  261.     end
  262.         setPlayerStorageValue(cid, tstor, -1)
  263.         doCreatureSetDropLoot(cid, false)
  264.         doPlayerSetLossSkill(cid, 0)
  265.         doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, 0)
  266. return true
  267. end
  268. ]]></event>
  269. ------------------------------------------------------------------------------------
  270. <event type="combat" name="GeneratorCast" event="script"><![CDATA[  
  271. domodlib('generator')
  272. function onCombat(cid, target)
  273.     if isPlayer(cid) and isPlayer(target) then
  274.         if isDefender(cid) and isDefender(target) or isInvader(cid) and isInvader(target) then
  275.             doPlayerSendCancel(cid, "You may not attack your team mates.") return false
  276.         end
  277.     end
  278. return true
  279. end
  280. ]]></event>
  281. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement