Advertisement
Guest User

Fire storm

a guest
Dec 20th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.22 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mod name="Fire_Storm_Event" version="3.0" author="CollocorpuseK" contact="otland.net" enabled="yes">
  3.  
  4. <config name="config_fire_storm_event">
  5. <![CDATA[
  6. configFireStormEvent = {
  7. storages = {
  8. main = '13335', -- set free storage
  9. player = '13336', -- set free storage
  10. joining = '13337', -- set free storage
  11. exhaust = '13338', -- set free storage
  12. countEvent = '13339' -- set free storage
  13. },
  14.  
  15. position = {x=1171 ,y=912,z=7}, -- position which player is teleported to
  16. room = {
  17. from = {x=1140,y=885,z=7}, -- left top corner of event room
  18. to = {x=1616,y=1654,z=7} -- right bottom corner of event room
  19. },
  20.  
  21. rewards = {2345}, -- reward id which player can win (reward is random)
  22. players = {
  23. max = 50,
  24. min = 2,
  25. minLevel = 100
  26. },
  27.  
  28. days = {
  29. ['Monday'] = {'12:47:00'},
  30. ['Tuesday'] = {'12:47:00'},
  31. ['Wednesday'] = {'12:47:00'},
  32. ['Thursday'] = {'12:47:00'},
  33. ['Friday'] = {'12:47:00'},
  34. ['Saturday'] = {'12:47:00'},
  35. ['Sunday'] = {'12:47:00'}
  36. },
  37.  
  38. fireStormDelay = 1000, -- milisecond
  39.  
  40.  
  41. delayTime = 5.0, -- time in which players who joined to event are teleporting to teleport position
  42. startEvent = 1, -- time from teleport to start event
  43. text = 'To win and get a Rewards, stay as long as possible in the arena.'
  44. }
  45.  
  46. fight = createConditionObject(CONDITION_INFIGHT)
  47. setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
  48.  
  49. y, x = 1, 1 -- don't change it
  50. ]]>
  51. </config>
  52.  
  53. <lib name="lib_fire_storm_event">
  54. <![CDATA[
  55. function doStartFireStormEvent()
  56. doSetStorage(configFireStormEvent.storages.joining, -1)
  57.  
  58. if configFireStormEvent.players.min <= doCountPlayersFireStormEvent() then
  59. for _, cid in ipairs(getPlayersOnline()) do
  60. if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
  61. doCreatureSetNoMove(cid, false)
  62. doRemoveCondition(cid, CONDITION_INFIGHT)
  63. doTeleportThing(cid, configFireStormEvent.position)
  64. doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
  65.  
  66. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Get ready. Fire Storm starts in '..configFireStormEvent.startEvent..' seconds.')
  67. end
  68. end
  69.  
  70. addEvent(doSetStorage, configFireStormEvent.startEvent * 1000, configFireStormEvent.storages.main, 1)
  71. addEvent(doRepeatCheckFireStorm, configFireStormEvent.startEvent * 1000 + 2000)
  72.  
  73. doBroadcastMessage('Fire Storm has started. LET\'S GO!')
  74. else
  75. for _, cid in ipairs(getPlayersOnline()) do
  76. if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
  77. doCreatureSetNoMove(cid, false)
  78. doRemoveCondition(cid, CONDITION_INFIGHT)
  79. end
  80. end
  81.  
  82. doBroadcastMessage('Fire Storm hasn\'t started beacuse there were not enough players.')
  83. end
  84. end
  85.  
  86. function doRepeatCheckFireStorm()
  87. if getStorage(configFireStormEvent.storages.main) > 0 then
  88. local xTable, yTable, playerTable = {}, {}, {}
  89.  
  90. for x = configFireStormEvent.room.from.x, configFireStormEvent.room.to.x do
  91. for y = configFireStormEvent.room.from.y, configFireStormEvent.room.to.y do
  92. table.insert(xTable, x)
  93. table.insert(yTable, y)
  94.  
  95. local n, i = getTileInfo({x=x, y=y, z=configFireStormEvent.room.to.z}).creatures, 1
  96. if n ~= 0 then
  97. local v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
  98. while v ~= 0 do
  99. if isPlayer(v) then
  100. table.insert(playerTable, v)
  101. if n == #playerTable then
  102. break
  103. end
  104. end
  105. i = i + 1
  106. v = getThingfromPos({x=x, y=y, z=configFireStormEvent.room.to.z, stackpos=i}).uid
  107. end
  108. end
  109. end
  110. end
  111.  
  112. if #playerTable == 1 then
  113. local prize = math.random(#configFireStormEvent.rewards)
  114. doCreatureAddHealth(playerTable[1], getCreatureMaxHealth(playerTable[1]) - getCreatureHealth(playerTable[1]))
  115. doCreatureAddMana(playerTable[1], getCreatureMaxMana(playerTable[1]) - getCreatureMana(playerTable[1]))
  116. doTeleportThing(playerTable[1], getTownTemplePosition(getPlayerTown(playerTable[1])), true)
  117. doPlayerAddItem(playerTable[1], configFireStormEvent.rewards[prize], 1)
  118. doPlayerSendTextMessage(playerTable[1], MESSAGE_EVENT_ADVANCE, 'You win! You have received ' .. getItemNameById(configFireStormEvent.rewards[prize]) .. ' as reward.')
  119. doBroadcastMessage('Fire Storm has finished. The winner is ' .. getCreatureName(playerTable[1]) .. '. Congratulations.')
  120. doSetStorage(configFireStormEvent.storages.main, -1)
  121.  
  122. db.executeQuery("INSERT INTO `events` (`event_name`, `winner_name`, `won_item`, `time_win`) VALUES (\"Fire\", \"" .. getCreatureName(playerTable[1]) .. "\", \"" .. getItemNameById(configFireStormEvent.rewards[prize]) .. "\", " .. getStorage(configFireStormEvent.storages.countEvent) ..");")
  123. doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
  124.  
  125. x, y = 1, 1
  126. elseif #playerTable > 1 then
  127. for a = 1, y do
  128. addEvent(
  129. function()
  130. local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
  131.  
  132. for _, player in ipairs(playerTable) do
  133. local pPos = getThingPos(player)
  134. if pPos.x == pos.x and pPos.y == pos.y and pPos.z == pos.z then
  135. doCreatureAddHealth(player, - getCreatureMaxHealth(player))
  136. end
  137. end
  138. doSendDistanceShoot({x = pos.x - math.random(4, 6), y = pos.y - 5, z = pos.z}, pos, CONST_ANI_FIRE)
  139.  
  140. addEvent(doSendMagicEffect, 150, pos, CONST_ME_HITBYFIRE)
  141. addEvent(doSendMagicEffect, 150, pos, CONST_ME_FIREAREA)
  142. end,
  143. math.random(100,1000)
  144. )
  145. end
  146. if x == 5 * y then
  147. y = y + 1
  148. end
  149.  
  150. x = x + 1
  151. else
  152. doBroadcastMessage('No one survived the Fire Storm.')
  153. doSetStorage(configFireStormEvent.storages.main, -1)
  154. doSetStorage(configFireStormEvent.storages.countEvent, getStorage(configFireStormEvent.storages.countEvent) + 1)
  155. x, y = 1, 1
  156. end
  157.  
  158. addEvent(doRepeatCheckFireStorm, configFireStormEvent.fireStormDelay)
  159. end
  160. end
  161.  
  162. function doCountPlayersFireStormEvent()
  163. local x = 0
  164. for _, cid in ipairs(getPlayersOnline()) do
  165. if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
  166. x = x + 1
  167. end
  168. end
  169. return x
  170. end
  171.  
  172. function doStartCountingFireStormEvent(x)
  173. if configFireStormEvent.delayTime-x > 0 then
  174. doBroadcastMessage('Fire Storm will start in '..configFireStormEvent.delayTime-x..' minutes. You can join to the event by say "!fire join".')
  175. addEvent(doStartCountingFireStormEvent, 60*1000, x+1)
  176. end
  177. end
  178. ]]>
  179. </lib>
  180. <talkaction words="!fire" event="script">
  181. <![CDATA[
  182. domodlib("config_fire_storm_event")
  183.  
  184. function onSay(cid, words, param)
  185. if getStorage(configFireStormEvent.storages.joining) ~= 1 then
  186. return doPlayerSendCancel(cid, 'Fire Storm hasn\'t started yet.')
  187. elseif param == '' then
  188. return doPlayerSendCancel(cid, 'Command param required (say: "!fire join" or "!fire leave.").')
  189. elseif getPlayerLevel(cid) < configFireStormEvent.players.minLevel then
  190. return doPlayerSendCancel(cid, 'You can\'t join to the event if you don\'t have a require '..configFireStormEvent.players.minLevel..' level.')
  191. elseif getTileInfo(getThingPos(cid)).protection ~= true then
  192. return doPlayerSendCancel(cid, 'You can\'t join to the event if you aren\'t in protection zone.')
  193. elseif exhaustion.check(cid, configFireStormEvent.storages.exhaust) ~= false then
  194. return doPlayerSendCancel(cid, 'You must wait '..exhaustion.get(cid, configFireStormEvent.storages.exhaust)..' seconds to use this command again.')
  195. end
  196.  
  197. if param == 'join' then
  198. if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
  199. return doPlayerSendCancel(cid, 'You have arleady joined to event. Wait patiently for start.')
  200. elseif doCountPlayersFireStormEvent() == configFireStormEvent.players.max then
  201. return doPlayerSendCancel(cid, 'Max players in the event have been reached.')
  202. end
  203.  
  204. doCreatureSetNoMove(cid, true)
  205. doPlayerPopupFYI(cid, configFireStormEvent.text)
  206. doCreatureSetStorage(cid, configFireStormEvent.storages.player, 1)
  207. doAddCondition(cid, fight)
  208. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'You have joined to Fire Storm Event. You can\'t move until event start. Wait patiently for the event start.')
  209. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have joined to Fire Storm Event.')
  210. elseif param == 'leave' then
  211. if getCreatureStorage(cid, configFireStormEvent.storages.player) <= 0 then
  212. return doPlayerSendCancel(cid, 'You can\'t leave from the event if you don\'t join.')
  213. end
  214.  
  215. doCreatureSetNoMove(cid, false)
  216. doRemoveCondition(cid, CONDITION_INFIGHT)
  217. doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
  218. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You have left from the Fire Storm Event.')
  219. end
  220.  
  221. exhaustion.set(cid, configFireStormEvent.storages.exhaust, 5)
  222.  
  223. return true
  224. end
  225. ]]>
  226. </talkaction>
  227.  
  228. <talkaction words="!startfire" access="5" event="script">
  229. <![CDATA[
  230. domodlib("config_fire_storm_event")
  231. domodlib("lib_fire_storm_event")
  232.  
  233. function onSay(cid, words, param)
  234. if getStorage(configFireStormEvent.storages.main) > 0 then
  235. return doPlayerSendCancel(cid, 'Fire Storm Event is already running.')
  236. end
  237.  
  238. doStartCountingFireStormEvent(0)
  239.  
  240. for _, pid in ipairs(getPlayersOnline()) do
  241. if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
  242. doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
  243. doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
  244. end
  245. end
  246.  
  247. doSetStorage(configFireStormEvent.storages.joining, 1)
  248. addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
  249. return true
  250. end
  251. ]]>
  252. </talkaction>
  253.  
  254. <globalevent name="Fire_Storm_Event_Days" interval="1000" event="script">
  255. <![CDATA[
  256. domodlib("config_fire_storm_event")
  257. domodlib("lib_fire_storm_event")
  258.  
  259. local daysOpen = {}
  260. for k, v in pairs(configFireStormEvent.days) do
  261. table.insert(daysOpen, k)
  262. end
  263.  
  264. function onThink(interval)
  265. if isInArray(daysOpen, os.date('%A')) then
  266. if isInArray(configFireStormEvent.days[os.date('%A')], os.date('%X', os.time())) then
  267. if getStorage(configFireStormEvent.storages.joining) ~= 1 then
  268. doStartCountingFireStormEvent(0)
  269.  
  270. for _, pid in ipairs(getPlayersOnline()) do
  271. if getCreatureStorage(pid, configFireStormEvent.storages.player) > 0 then
  272. doCreatureSetStorage(pid, configFireStormEvent.storages.player, -1)
  273. doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)), true)
  274. end
  275. end
  276.  
  277. doSetStorage(configFireStormEvent.storages.joining, 1)
  278. addEvent(doStartFireStormEvent, configFireStormEvent.delayTime * 60 * 1000)
  279. end
  280. end
  281. end
  282. return true
  283. end
  284. ]]>
  285. </globalevent>
  286.  
  287. <event type="statschange" name="Fire_Storm_Event_Dead" event="script">
  288. <![CDATA[
  289. domodlib("config_fire_storm_event")
  290.  
  291. function onStatsChange(cid, attacker, type, combat, value)
  292. if type == 1 and getCreatureHealth(cid) <= value then
  293. if isInRange(getThingPos(cid), configFireStormEvent.room.from, configFireStormEvent.room.to) then
  294. doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
  295. doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
  296. doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
  297. doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'You loss.')
  298. return false
  299. end
  300. end
  301. return true
  302. end
  303. ]]>
  304. </event>
  305.  
  306. <event type="login" name="Fire_Storm_Event_Login" event="script">
  307. <![CDATA[
  308. domodlib("config_fire_storm_event")
  309.  
  310. function onLogin(cid)
  311. if getCreatureStorage(cid, configFireStormEvent.storages.player) > 0 then
  312. doCreatureSetStorage(cid, configFireStormEvent.storages.player, -1)
  313. doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
  314. doCreatureSetNoMove(cid, false)
  315. doRemoveCondition(cid, CONDITION_INFIGHT)
  316. end
  317.  
  318. registerCreatureEvent(cid, 'Fire_Storm_Event_Dead')
  319. return true
  320. end
  321. ]]>
  322. </event>
  323.  
  324. <globalevent name="Fire_Storm_Event_Start" type="startup" event="script">
  325. <![CDATA[
  326. domodlib("config_fire_storm_event")
  327.  
  328. function onStartup()
  329. doSetStorage(configFireStormEvent.storages.main, -1)
  330. doSetStorage(configFireStormEvent.storages.joining, -1)
  331. return true
  332. end
  333. ]]>
  334. </globalevent>
  335. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement