Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.66 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Zombie_Event" version="3.0" author="VirrageS" contact="otland.net" enabled="yes">
  3.  
  4. <config name="config_zombie_event">
  5. <![CDATA[
  6. configZombieEvent = {
  7. storages = {
  8. main = 'zombieEventMain', -- set free storage
  9. player = 'zombieEventPlayer', -- set free storage
  10. joining = 'zombieEventJoining', -- set free storage
  11. kills = 'zombieEventKills', -- set free storage
  12. exhaust = 'zombieEventExhaust', -- set free storage
  13. countEvent = 'zombieEventCountEvent' -- set free storage
  14. },
  15.  
  16. position = {x=32131,y=32322,z=7}, -- position to which player is teleporting
  17. room = {
  18. from = {x=32107,y=32301,z=7}, -- left top corner of event room
  19. to = {x=32155,y=32338,z=7} -- right bottom corner of event room
  20. },
  21.  
  22. rewards = {9971, 5952, 2160, 9971}, -- reward id which player can win (reward is random)
  23. players = {
  24. max = 20, -- max players in event
  25. min = 1, -- min players to event start
  26. minLevel = 100, -- min level to join to event
  27. pvpEnabled = false -- can players hit theirselfs
  28. },
  29.  
  30. days = {
  31. ['Tuesday'] = {'21:59:20'},
  32. ['Thursday'] = {'21:59:20'},
  33. ['Friday'] = {'21:59:20'},
  34. ['Sunday'] = {'21:59:20'}
  35. },
  36.  
  37. spawnDelay = 2000, -- miliseconds
  38. amountCreatingMonsters = 5,
  39. monsters = {'Zombie Event', 'Zombie Event', 'Zombie Event', 'Zombie Event', 'Zombie Event'}, -- name of monsters which is creating in event
  40.  
  41. delayTime = 1.0, -- time in which players who joined to event are teleporting to teleport position [miuntes]
  42. startEvent = 1, -- time from teleport to start event [seconds]
  43. stopEvent = 9200, -- [seconds]
  44. text = '-ENG-\nTo win and get a reward, kill as many zombies for 20 minutes or stay the same in the arena.'
  45. }
  46. ]]>
  47. </config>
  48.  
  49. <lib name="lib_zombie_event">
  50. <![CDATA[
  51. function doStopZombieEvent()
  52. if getStorage(configZombieEvent.storages.main) > 0 then
  53. local playerTable, creatureTable = {}, {}
  54.  
  55. for x = configZombieEvent.room.from.x, configZombieEvent.room.to.x do
  56. for y = configZombieEvent.room.from.y, configZombieEvent.room.to.y do
  57. local n, i = getTileInfo({x=x, y=y, z=configZombieEvent.room.from.z}).creatures, 1
  58. if n ~= 0 then
  59. local v = getThingfromPos({x=x, y=y, z=configZombieEvent.room.from.z, stackpos=i}).uid
  60. while v ~= 0 do
  61. if isPlayer(v) then
  62. table.insert(playerTable, v)
  63. if n == #playerTable then
  64. break
  65. end
  66. elseif isMonster(v) then
  67. table.insert(creatureTable, v)
  68. if n == #creatureTable then
  69. break
  70. end
  71. end
  72. i = i + 1
  73. v = getThingfromPos({x=x, y=y, z=configZombieEvent.room.from.z, stackpos=i}).uid
  74. end
  75. end
  76. end
  77. end
  78.  
  79. if #playerTable > 1 then
  80. table.sort(playerTable, function(a, b) return (getCreatureStorage(a, configZombieEvent.storages.kills)) > (getCreatureStorage(b, configZombieEvent.storages.kills)) end)
  81.  
  82. local prize = math.random(#configZombieEvent.rewards)
  83.  
  84. doTeleportThing(playerTable[1], getTownTemplePosition(getPlayerTown(playerTable[1])))
  85. doCreatureSetStorage(playerTable[1], configZombieEvent.storages.kills, 0)
  86. doPlayerAddItem(playerTable[1], configZombieEvent.rewards[prize], 1)
  87. doCreatureAddHealth(playerTable[1], getCreatureMaxHealth(playerTable[1]) - getCreatureHealth(playerTable[1]))
  88. doCreatureAddMana(playerTable[1], getCreatureMaxMana(playerTable[1]) - getCreatureMana(playerTable[1]))
  89. doPlayerSendTextMessage(playerTable[1], MESSAGE_EVENT_ADVANCE, 'You win! You have received '..getItemNameById(configZombieEvent.rewards[prize])..' as reward.')
  90. doBroadcastMessage('Zombie Plague Attack has finished. The winner is '..getCreatureName(playerTable[1])..'. Congratulations!')
  91. doSetStorage(configZombieEvent.storages.main, -1)
  92.  
  93. db.query("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Zombie\", \"" .. getCreatureName(playerTable[1]) .. "\", \"" .. getItemNameById(configZombieEvent.rewards[prize]) .. "\", " .. getStorage(configZombieEvent.storages.countEvent) ..");")
  94.  
  95. for i = 2, #playerTable do
  96. doCreatureAddHealth(playerTable[i], getCreatureMaxHealth(playerTable[i]) - getCreatureHealth(playerTable[i]))
  97. doCreatureAddMana(playerTable[i], getCreatureMaxMana(playerTable[i]) - getCreatureMana(playerTable[i]))
  98. doTeleportThing(playerTable[i], getTownTemplePosition(getPlayerTown(playerTable[i])))
  99. doPlayerSendTextMessage(playerTable[i], MESSAGE_EVENT_ADVANCE, 'You loss.')
  100. doSendMagicEffect(getThingPos(playerTable[i]), CONST_ME_STUN)
  101. doCreatureSetStorage(playerTable[i], configZombieEvent.storages.kills, 0)
  102. end
  103.  
  104. for i = 1, #creatureTable do
  105. if isMonster(creatureTable[i]) then
  106. doRemoveCreature(creatureTable[i])
  107. end
  108. end
  109.  
  110. doSetStorage(configZombieEvent.storages.countEvent, getStorage(configZombieEvent.storages.countEvent) + 1)
  111. elseif #playerTable == 0 then
  112. for i = 1, #creatureTable do
  113. if isMonster(creatureTable[i]) then
  114. doRemoveCreature(creatureTable[i])
  115. end
  116. end
  117.  
  118. doBroadcastMessage('No one win in Zombie Plague Attack.')
  119. doSetStorage(configZombieEvent.storages.main, -1)
  120. doSetStorage(configZombieEvent.storages.countEvent, getStorage(configZombieEvent.storages.countEvent) + 1)
  121. end
  122. end
  123. end
  124.  
  125. function doStartZombieEvent()
  126. doSetStorage(configZombieEvent.storages.joining, -1)
  127.  
  128. if configZombieEvent.players.min <= doCountPlayersZombieEvent() then
  129. for _, cid in ipairs(getPlayersOnline()) do
  130. if getCreatureStorage(cid, configZombieEvent.storages.player) > 0 then
  131. doCreatureSetStorage(cid, configZombieEvent.storages.player, -1)
  132. doTeleportThing(cid, configZombieEvent.position)
  133. doCreatureSetNoMove(cid, false)
  134. doRemoveCondition(cid, CONDITION_INFIGHT)
  135.  
  136. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Get ready. Zombie Plague Attack starts in '..configZombieEvent.startEvent..' seconds.')
  137. end
  138. end
  139.  
  140. addEvent(doSetStorage, configZombieEvent.startEvent * 1000, configZombieEvent.storages.main, 1)
  141. addEvent(doStopZombieEvent, configZombieEvent.stopEvent * 1000)
  142. addEvent(doRepeatCheckZombieEvent, configZombieEvent.startEvent * 1000 + 2000)
  143.  
  144. doBroadcastMessage('Zombie Plague Attack has started. LET\'S GO!')
  145. else
  146. for _, cid in ipairs(getPlayersOnline()) do
  147. if getCreatureStorage(cid, configZombieEvent.storages.player) > 0 then
  148. doCreatureSetNoMove(cid, false)
  149. doRemoveCondition(cid, CONDITION_INFIGHT)
  150. end
  151. end
  152.  
  153. doBroadcastMessage('Zombie Plague Attack hasn\'t started beacuse there were not enough players.')
  154. end
  155. end
  156.  
  157. function doRepeatCheckZombieEvent()
  158. if getStorage(configZombieEvent.storages.main) > 0 then
  159. local playerTable, creatureTable, xTable, yTable = {}, {}, {}, {}
  160.  
  161. for x = configZombieEvent.room.from.x, configZombieEvent.room.to.x do
  162. for y = configZombieEvent.room.from.y, configZombieEvent.room.to.y do
  163. local n, i = getTileInfo({x=x, y=y, z=configZombieEvent.room.to.z}).creatures, 1
  164. if n ~= 0 then
  165. local v = getThingfromPos({x=x, y=y, z=configZombieEvent.room.to.z, stackpos=i}).uid
  166. while v ~= 0 do
  167. if isPlayer(v) then
  168. table.insert(playerTable, v)
  169. if n == #playerTable then
  170. break
  171. end
  172. elseif isMonster(v) then
  173. table.insert(creatureTable, v)
  174. if n == #creatureTable then
  175. break
  176. end
  177. end
  178. i = i + 1
  179. v = getThingfromPos({x=x, y=y, z=configZombieEvent.room.to.z, stackpos=i}).uid
  180. end
  181. end
  182.  
  183. table.insert(xTable, x)
  184. table.insert(yTable, y)
  185. end
  186. end
  187.  
  188. if #playerTable == 1 then
  189. local prize = math.random(#configZombieEvent.rewards)
  190.  
  191. addEvent(doTeleportThing, 200, playerTable[1], getTownTemplePosition(getPlayerTown(playerTable[1])), true)
  192. doPlayerAddItem(playerTable[1], configZombieEvent.rewards[prize], 1)
  193. doCreatureSetStorage(playerTable[1], configZombieEvent.storages.kills, 0)
  194. doCreatureAddHealth(playerTable[1], getCreatureMaxHealth(playerTable[1]) - getCreatureHealth(playerTable[1]))
  195. doCreatureAddMana(playerTable[1], getCreatureMaxMana(playerTable[1]) - getCreatureMana(playerTable[1]))
  196. doPlayerSendTextMessage(playerTable[1], MESSAGE_EVENT_ADVANCE, 'You win! You have received '..getItemNameById(configZombieEvent.rewards[prize])..' as reward.')
  197. doBroadcastMessage('Zombie Plague Attack has finished. The winner is '..getCreatureName(playerTable[1])..'. Congratulations.')
  198. db.query("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Zombie\", \"" .. getCreatureName(playerTable[1]) .. "\", \""..getItemNameById(configZombieEvent.rewards[prize]).."\", "..getStorage(configZombieEvent.storages.countEvent)..");")
  199.  
  200. for i = 1, #creatureTable do
  201. if isMonster(creatureTable[i]) then
  202. doRemoveCreature(creatureTable[i])
  203. end
  204. end
  205.  
  206. doSetStorage(configZombieEvent.storages.main, -1)
  207. doSetStorage(configZombieEvent.storages.countEvent, getStorage(configZombieEvent.storages.countEvent) + 1)
  208. return
  209. elseif #playerTable == 0 then
  210. for i = 1, #creatureTable do
  211. if isMonster(creatureTable[i]) then
  212. doRemoveCreature(creatureTable[i])
  213. end
  214. end
  215.  
  216. doBroadcastMessage('No one win in Zombie Plague Attack.')
  217. doSetStorage(configZombieEvent.storages.main, -1)
  218.  
  219. doSetStorage(configZombieEvent.storages.countEvent, getStorage(configZombieEvent.storages.countEvent) + 1)
  220. return
  221. end
  222.  
  223. local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
  224. for i = 1, configZombieEvent.amountCreatingMonsters do
  225. doCreateMonster(configZombieEvent.monsters[math.random(#configZombieEvent.monsters)], pos, false, false, false)
  226. doSendMagicEffect(pos, CONST_ME_BATS)
  227. end
  228.  
  229. addEvent(doRepeatCheckZombieEvent, configZombieEvent.spawnDelay)
  230. end
  231. end
  232.  
  233. function doCountPlayersZombieEvent()
  234. local x = 0
  235. for _, cid in ipairs(getPlayersOnline()) do
  236. if getCreatureStorage(cid, configZombieEvent.storages.player) > 0 then
  237. x = x + 1
  238. end
  239. end
  240. return x
  241. end
  242.  
  243. function doStartCountingZombieEvent(x)
  244. if configZombieEvent.delayTime-x > 0 then
  245. doBroadcastMessage('Zombie Plague Attack is going to start in '..configZombieEvent.delayTime-x..' minutes. You can join to the event by saying "!zombie join".')
  246. addEvent(doStartCountingZombieEvent, 60*1000, x+1)
  247. end
  248. end
  249. ]]>
  250. </lib>
  251.  
  252. <talkaction words="!zombie" event="script">
  253. <![CDATA[
  254. domodlib("config_zombie_event")
  255.  
  256. function onSay(cid, words, param)
  257. if getStorage(configZombieEvent.storages.joining) ~= 1 then
  258. return doPlayerSendCancel(cid, 'Zombie Plague Attack hasn\'t started yet.')
  259. elseif param == '' then
  260. return doPlayerSendCancel(cid, 'Command param required (say: "!zombie join" or "!zombie leave.").')
  261. elseif getPlayerLevel(cid) < configZombieEvent.players.minLevel then
  262. return doPlayerSendCancel(cid, 'You can\'t join to the event if you don\'t have a require '..configZombieEvent.players.minLevel..' level.')
  263. elseif getTileInfo(getThingPos(cid)).protection ~= true then
  264. return doPlayerSendCancel(cid, 'You can\'t join to the event if you aren\'t in protection zone.')
  265. elseif exhaustion.check(cid, configZombieEvent.storages.exhaust) ~= false then
  266. return doPlayerSendCancel(cid, 'You must wait '..exhaustion.get(cid, configZombieEvent.storages.exhaust)..' seconds to use this command again.')
  267. end
  268.  
  269. if param == 'join' then
  270. if getCreatureStorage(cid, configZombieEvent.storages.player) > 0 then
  271. return doPlayerSendCancel(cid, 'You have arleady joined to event. Wait patiently for start.')
  272. elseif doCountPlayersZombieEvent() == configZombieEvent.players.max then
  273. return doPlayerSendCancel(cid, 'Max players in the event have been reached.')
  274. end
  275.  
  276. doCreatureSetNoMove(cid, true)
  277. doPlayerPopupFYI(cid, configZombieEvent.text)
  278. doCreatureSetStorage(cid, configZombieEvent.storages.player, 1)
  279. doAddCondition(cid, createConditionObject(CONDITION_INFIGHT, -1))
  280. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You have joined to Zombie Plague Attack. You can\'t move until event don\'t start. Wait patiently for the event start.')
  281. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have joined to Zombie Plague Attack.')
  282. elseif param == 'leave' then
  283. if getCreatureStorage(cid, configZombieEvent.storages.player) <= 0 then
  284. return doPlayerSendCancel(cid, 'You can\'t leave from the event if you don\'t join.')
  285. end
  286.  
  287. doCreatureSetNoMove(cid, false)
  288. doCreatureSetStorage(cid, configZombieEvent.storages.player, -1)
  289. doRemoveCondition(cid, CONDITION_INFIGHT)
  290. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have left from the Zombie Plague Attack.')
  291. end
  292.  
  293. exhaustion.set(cid, configZombieEvent.storages.exhaust, 5)
  294. return true
  295. end
  296. ]]>
  297. </talkaction>
  298.  
  299. <talkaction words="!startzombie" access="5" event="script">
  300. <![CDATA[
  301. domodlib("config_zombie_event")
  302. domodlib("lib_zombie_event")
  303.  
  304. function onSay(cid, words, param)
  305. if getStorage(configZombieEvent.storages.main) > 0 then
  306. return doPlayerSendCancel(cid, 'Zombie Plague Attack is already running.')
  307. end
  308.  
  309. doStartCountingZombieEvent(0)
  310.  
  311. for _, pid in ipairs(getPlayersOnline()) do
  312. if getCreatureStorage(pid, configZombieEvent.storages.player) > 0 then
  313. doCreatureSetStorage(pid, configZombieEvent.storages.player, -1)
  314. doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
  315. doCreatureSetStorage(pid, configZombieEvent.storages.kills, 0)
  316. end
  317. end
  318.  
  319. doSetStorage(configZombieEvent.storages.joining, 1)
  320. addEvent(doStartZombieEvent, configZombieEvent.delayTime * 60 * 1000)
  321. return true
  322. end
  323. ]]>
  324. </talkaction>
  325.  
  326. <talkaction words="!stopzombie" access="5" event="script">
  327. <![CDATA[
  328. domodlib("config_zombie_event")
  329. domodlib("lib_zombie_event")
  330.  
  331. function onSay(cid, words, param)
  332. if getStorage(configZombieEvent.storages.main) > 0 then
  333. doStopZombieEvent()
  334. else
  335. doPlayerSendCancel(cid, 'You can not do it if Zombie Plague Attack is not enabled.')
  336. end
  337. return true
  338. end
  339. ]]>
  340. </talkaction>
  341.  
  342. <globalevent name="Zombie_Event_Days" interval="1000" event="script">
  343. <![CDATA[
  344. domodlib("config_zombie_event")
  345. domodlib("lib_zombie_event")
  346.  
  347. local daysOpen = {}
  348. for k, v in pairs(configZombieEvent.days) do
  349. table.insert(daysOpen, k)
  350. end
  351.  
  352. function onThink(interval)
  353. if isInArray(daysOpen, os.date('%A')) then
  354. if isInArray(configZombieEvent.days[os.date('%A')], os.date('%X', os.time())) then
  355. if getStorage(configZombieEvent.storages.joining) ~= 1 then
  356. doStartCountingZombieEvent(0)
  357.  
  358. for _, pid in ipairs(getPlayersOnline()) do
  359. if getCreatureStorage(pid, configZombieEvent.storages.player) > 0 then
  360. doCreatureSetStorage(pid, configZombieEvent.storages.player, -1)
  361. doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
  362. doCreatureSetStorage(pid, configZombieEvent.storages.kills, 0)
  363. end
  364. end
  365.  
  366. doSetStorage(configZombieEvent.storages.joining, 1)
  367. addEvent(doStartZombieEvent, configZombieEvent.delayTime * 60 * 1000)
  368. end
  369. end
  370. end
  371. return true
  372. end
  373. ]]>
  374. </globalevent>
  375.  
  376. <event type="statschange" name="Zombie_Event_Dead" event="script">
  377. <![CDATA[
  378. domodlib("config_zombie_event")
  379.  
  380. function onStatsChange(cid, attacker, type, combat, value)
  381. if type == 1 and getCreatureHealth(cid) <= value then
  382. if isInRange(getThingPos(cid), configZombieEvent.room.from, configZombieEvent.room.to) then
  383. if isPlayer(cid) then
  384. doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
  385. doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
  386. doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  387. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You loss due to attack.')
  388.  
  389. doSendAnimatedText(getThingPos(cid), value, TEXTCOLOR_RED)
  390. doSendMagicEffect(getThingPos(cid), CONST_ME_TELEPORT)
  391. doCreatureSetStorage(cid, configZombieEvent.storages.kills, 0)
  392. return false
  393. end
  394. end
  395. elseif configZombieEvent.players.pvpEnabled ~= true and isInArray({1,3}, type) and isPlayer(attacker) and isPlayer(cid) then
  396. if isInRange(getThingPos(cid), configZombieEvent.room.from, configZombieEvent.room.to) then
  397. return false
  398. end
  399. end
  400. return true
  401. end
  402. ]]>
  403. </event>
  404.  
  405. <event type="kill" name="Zombie_Event_Kill" event="script">
  406. <![CDATA[
  407. domodlib("config_zombie_event")
  408.  
  409. function onKill(cid, target, damage, flags)
  410. if isInRange(getThingPos(cid), configZombieEvent.room.from, configZombieEvent.room.to) then
  411. if isInArray(configZombieEvent.monsters, getCreatureName(target)) then
  412. doCreatureSetStorage(cid, configZombieEvent.storages.kills, math.max(0, getCreatureStorage(cid, configZombieEvent.storages.kills) + 1))
  413. end
  414. end
  415. return true
  416. end
  417. ]]>
  418. </event>
  419.  
  420. <event type="login" name="Zombie_Event_Login" event="script">
  421. <![CDATA[
  422. domodlib("config_zombie_event")
  423.  
  424. function onLogin(cid)
  425. if getCreatureStorage(cid, configZombieEvent.storages.player) > 0 then
  426. doCreatureSetStorage(cid, configZombieEvent.storages.player, -1)
  427. doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
  428. doCreatureSetNoMove(cid, false)
  429. doRemoveCondition(cid, CONDITION_INFIGHT)
  430. doCreatureSetStorage(cid, configZombieEvent.storages.player.kills, 0)
  431. end
  432.  
  433. registerCreatureEvent(cid, 'Zombie_Event_Dead')
  434. registerCreatureEvent(cid, 'Zombie_Event_Kill')
  435. return true
  436. end
  437. ]]>
  438. </event>
  439.  
  440. <globalevent name="Zombie_Event_Start" type="startup" event="script">
  441. <![CDATA[
  442. domodlib("config_zombie_event")
  443.  
  444. function onStartup()
  445. doSetStorage(configZombieEvent.storages.main, -1)
  446. doSetStorage(configZombieEvent.storages.joining, -1)
  447. return true
  448. end
  449. ]]>
  450. </globalevent>
  451. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement