Advertisement
ped_so

Untitled

May 25th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.12 KB | None | 0 0
  1. local minResets
  2. if servidornumero == 4 then
  3. minResets = 0
  4. else
  5. minResets = 0
  6. end
  7.  
  8. if not Battlefield then
  9. Battlefield = {
  10. open = false,
  11.  
  12. idChannelEvent = 16,
  13.  
  14. -- Storages para salvar HP e MANA
  15. safeSkills = 4487,
  16. healthStorage = 4488,
  17. manaStorage = 4489,
  18. magicStorage = 4496,
  19. triesmgStg = 4582,
  20.  
  21. skillLevel = {
  22. [1] = {name = SKILL_SHIELD, storage = 4490, triesStg = 4583},
  23. [2] = {name = SKILL_FIST, storage = 4491, triesStg = 4584},
  24. [3] = {name = SKILL_CLUB, storage = 4492, triesStg = 4585},
  25. [4] = {name = SKILL_SWORD, storage = 4493, triesStg = 4586},
  26. [5] = {name = SKILL_AXE, storage = 4494, triesStg = 4587},
  27. [6] = {name = SKILL_DISTANCE, storage = 4495, triesStg = 4588},
  28. -- [7] = {name = SKILL_MAGLEVEL, storage = 4496, triesStg = XXXX},
  29. },
  30.  
  31. wall = {
  32. id = 22578,
  33.  
  34. top = Position(478, 362, 4),
  35. bottom = Position(478, 366, 4)
  36. },
  37.  
  38. bordasArena = {
  39. fromPosition = Position(446, 355, 6),
  40. toPosition = Position(509, 373, 6)
  41. },
  42.  
  43. itensBloqueados = {
  44. [1] = {id = 2349},
  45. [2] = {id = 22648},
  46. [3] = {id = 7403},
  47. [4] = {id = 8851},
  48. [5] = {id = 15643},
  49. [6] = {id = 8921},
  50. [7] = {id = 8922},
  51. [8] = {id = 7423},
  52. [9] = {id = 8926},
  53. [10] = {id = 8904},
  54. [11] = {id = 6534},
  55. [12] = {id = 7453},
  56. [13] = {id = 8856},
  57. [14] = {id = 8853},
  58. [15] = {id = 7418},
  59. [16] = {id = 7392},
  60. [17] = {id = 25411},
  61. [19] = {id = 18390},
  62. [20] = {id = 25418},
  63. [21] = {id = 25523},
  64. [22] = {id = 25416},
  65. [23] = {id = 25522},
  66. [24] = {id = 25415},
  67. [25] = {id = 10309},
  68. [26] = {id = 10310},
  69. },
  70.  
  71. rewardsTimeLimit = {
  72. -- {itemid, quantity}
  73. {id = 2160, quantidade = 5},
  74. {id = 7369, quantidade = 1, ehTrofeu = true},
  75. },
  76.  
  77. rewardDefault = {
  78. -- {itemid, quantity}
  79. {id = 2160, quantidade = 15},
  80. {id = 7369, quantidade = 1, ehTrofeu = true},
  81. {id = 9971, quantidade = 1},
  82. },
  83.  
  84. expReward = 1000000, -- 10KK * qnt de jogadores vivos!
  85.  
  86. minLevel = 8,
  87.  
  88. playerCount = 0, -- Não alterar!!
  89. minPlayers = 8, -- Quantidade necessária para o evento iniciar
  90. maxPlayers = 50, -- Quantidade máxima de players dentro do evento
  91.  
  92.  
  93. teams = {
  94. [1] = {
  95. name = 'Fusion Force',
  96.  
  97. outfit = {
  98. lookType = 152,
  99. lookAddons = 3,
  100. lookHead = 90,
  101. lookBody = 90,
  102. lookLegs = 90,
  103. lookFeet = 90,
  104. },
  105.  
  106. position = Position(462, 370, 6), -- Posição do time
  107.  
  108. players = {},
  109. kills = 0,
  110. size = 0,
  111. vidaExtra = 0,
  112. },
  113. [2] = {
  114. name = 'Red Devils',
  115.  
  116. outfit = {
  117. lookType = 152,
  118. lookAddons = 3,
  119. lookHead = 94,
  120. lookLegs = 94,
  121. lookBody = 94,
  122. lookFeet = 94,
  123. },
  124.  
  125. position = Position(493, 370, 6),
  126.  
  127. players = {},
  128. kills = 0,
  129. size = 0,
  130. vidaExtra = 0,
  131. },
  132. }
  133. }
  134.  
  135. function Battlefield:Open()
  136. if self.playerCount >= self.minPlayers then
  137. if self.open then
  138. return false -- O evento já estava aberto, então não inicia
  139. end
  140. for y = self.wall.top.y, self.wall.bottom.y do
  141. local tile = Tile({x = self.wall.top.x, y = y, z = self.wall.top.z})
  142. if tile then
  143. local wall = tile:getItemById(self.wall.id)
  144. if wall then
  145. wall:remove()
  146. end
  147. end
  148. end
  149. self.open = true
  150. Game.sendEventMessage("A guerra começou! Boa sorte a todos, e que vença o melhor! :)")
  151. if self.teams[1].size > self.teams[2].size then
  152. Game.sendEventMessage("Por haver mais jogadores dentro da aliança, a horda irá ganhar uma vida extra.")
  153. self.teams[2].vidaExtra = 1
  154. elseif self.teams[1].size < self.teams[2].size then
  155. Game.sendEventMessage("Por haver mais jogadores dentro da horda, a aliança irá ganhar uma vida extra.")
  156. self.teams[1].vidaExtra = 1
  157. else
  158. Game.sendEventMessage("O jogo está equilibrado! Nenhuma equipe irá precisar de vida extra! :).")
  159. end
  160. local fromPos = self.bordasArena.fromPosition
  161. local toPos = self.bordasArena.toPosition
  162. for x = fromPos.x, toPos.x do
  163. for y = fromPos.y, toPos.y do
  164. for z = fromPos.z, toPos.z do
  165. local tile = Tile(Position(x, y, z))
  166. if tile then
  167. local c = tile:getTopCreature()
  168. if c and c:isPlayer() then
  169. c:teleportTo(Position(c:getPosition().x, c:getPosition().y, c:getPosition().z - 1))
  170. end
  171. end
  172. end
  173. end
  174. end
  175. return true -- Evento começou
  176. else
  177. Game.sendEventMessage("A guerra não aconteceu por não haver a quantidade necessária de jogadores... :(")
  178. for _, team in ipairs(self.teams) do
  179. for name, info in pairs(team.players) do
  180. local player = Player(name)
  181. if player then
  182. self:cancelEvent(player)
  183. end
  184. end
  185. end
  186. self.teams[1].players = {}
  187. self.teams[1].size = 0
  188. self.teams[1].kills = 0
  189. self.teams[1].vidaExtra = 0
  190. self.teams[2].players = {}
  191. self.teams[2].size = 0
  192. self.teams[2].kills = 0
  193. self.teams[2].vidaExtra = 0
  194. return false -- Evento não começou
  195. end
  196. end
  197.  
  198. function Battlefield:cancelEvent(player)
  199. local info = self:findPlayer(player)
  200. if not info then -- Se não encontrou jogador lá dentro
  201. return false
  202. end
  203. player:unregisterEvent("Battlefield_HealthChange")
  204. player:unregisterEvent("Battlefield_PrepareDeath")
  205. player:unregisterEvent("Battlefield_ManaChange")
  206. player:unregisterEvent("Battlefield_Logout")
  207.  
  208. -- Teleportar para o templo e zerar os times
  209. player:teleportTo(player:getTown():getTemplePosition())
  210. self.teams[info.team].size = self.teams[info.team].size - 1
  211. self.teams[info.team].players[info.name] = nil
  212.  
  213. -- Devolvendo HP e MANA (importante)
  214. player:setMaxHealth(player:getStorageValue(self.healthStorage))
  215. player:setMaxMana(player:getStorageValue(self.manaStorage))
  216.  
  217. local skillMax = 0
  218. -- Devolvendo SKILL (importante)
  219. if isMage(player:getVocation():getId(), 0) then
  220. skillMax = 120
  221. if player:getMagicLevel() >= skillMax then
  222. player:setSkill(SKILL_MAGLEVEL, player:getStorageValue(self.magicStorage))
  223. end
  224. else
  225. for _, skill in pairs(self.skillLevel) do
  226. local name = skill.name
  227. local storage = skill.storage
  228. local triesStg = skill.triesStg
  229. if name == SKILL_SHIELD then
  230. skillMax = 130
  231. else
  232. skillMax = 130
  233. end
  234. player:setSkill(name, player:getStorageValue(storage))
  235. player:setSkill(name, player:getStorageValue(storage))
  236. player:addSkillTries(name, player:getStorageValue(triesStg))
  237. end
  238. end
  239.  
  240. player:setStorageValue(self.safeSkills, -1)
  241.  
  242. -- Encher HP/Mana e conditions
  243. player:addHealth(player:getMaxHealth())
  244. player:addMana(player:getMaxMana())
  245. player:removeCondition(CONDITION_INFIGHT)
  246. player:removeCondition(CONDITION_OUTFIT)
  247. return true
  248. end
  249.  
  250. function Battlefield:Close(winner)
  251. if not self.open then -- O evento não estava aberto, então não tem o que fechar
  252. return false
  253. end
  254.  
  255. self.open = false
  256. local tempoLimite = false
  257.  
  258. -- Recriando a barreira
  259. for y = self.wall.top.y, self.wall.bottom.y do
  260. Game.createItem(self.wall.id, 1, Position(self.wall.top.x, y, self.wall.top.z))
  261. end
  262.  
  263. if not winner then
  264. if self.teams[1].kills > self.teams[2].kills then
  265. winner = 1
  266. elseif self.teams[1].kills < self.teams[2].kills then
  267. winner = 2
  268. end
  269. tempoLimite = true
  270. end
  271.  
  272. local recompensa = {}
  273. if not tempoLimite then
  274. recompensa = self.rewardDefault
  275. else
  276. recompensa = self.rewardsTimeLimit
  277. end
  278.  
  279. if winner then
  280. if not tempoLimite then
  281. broadcastMessage(string.format("[Battlefield] A %s ganhou o evento Battlefield derrotando todo o time inimigo!", self.teams[winner].name), MESSAGE_EVENT_ADVANCE)
  282. else
  283. broadcastMessage(string.format("[Battlefield] A %s ganhou o evento Battlefield por possuir mais jogadores ao final do tempo!", self.teams[winner].name), MESSAGE_EVENT_ADVANCE)
  284. end
  285. else
  286. broadcastMessage("[Battlefield] Houve um empate e ninguém ganhou a recompensa.", MESSAGE_EVENT_ADVANCE)
  287. end
  288.  
  289. -- Somente contando a quantidade de jogadores
  290. local contagemJogadores = 0
  291. for _, team in ipairs(self.teams) do
  292. for name, info in pairs(team.players) do
  293. local player = Player(name)
  294. if player then
  295. if _ == winner then
  296. contagemJogadores = contagemJogadores + 1
  297. end
  298. end
  299. end
  300. end
  301.  
  302. -- Entregando as recompensas
  303. for _, team in ipairs(self.teams) do
  304. for name, info in pairs(team.players) do
  305. local player = Player(name)
  306. if player then
  307. self:cancelEvent(player)
  308. if _ == winner then
  309. for k, item in ipairs(recompensa) do
  310. local ehTrofeu = item.ehTrofeu
  311. local id = item.id
  312. local quantidade = item.quantidade
  313. local reward
  314. if item.ehTrofeu == true then
  315. local data = os.date("%d/%m/%Y")
  316. reward = player:addItem(id, quantidade)
  317. if reward then
  318. reward:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Evento Battlefield - " .. data .. " - " .. player:getName() .. " - " .. team.name .. ".")
  319. end
  320. else
  321. reward = player:addItem(id, quantidade)
  322. end
  323. end
  324. local expNova = (self.expReward)*contagemJogadores
  325. doPlayerAddExpStage(player, expNova)
  326. end
  327. end
  328. end
  329. end
  330.  
  331. return true
  332. end
  333.  
  334. function Battlefield:findPlayer(player)
  335. local name = player:getName()
  336. return self.teams[1].players[name] or self.teams[2].players[name]
  337. end
  338.  
  339. function Battlefield:onJoin(player)
  340. local ALLIANCE =
  341. createConditionObject(CONDITION_OUTFIT)
  342. setConditionParam(ALLIANCE, CONDITION_PARAM_TICKS, - 1)
  343. addOutfitCondition(ALLIANCE, {lookType = self.teams[1].outfit.lookType, lookAddons = self.teams[1].outfit.lookAddons,
  344. lookHead = self.teams[1].outfit.lookHead, lookBody = self.teams[1].outfit.lookBody, lookLegs = self.teams[1].outfit.lookLegs,
  345. lookFeet = self.teams[1].outfit.lookFeet})
  346.  
  347. local HORDE = createConditionObject(CONDITION_OUTFIT)
  348. setConditionParam(HORDE, CONDITION_PARAM_TICKS, - 1)
  349. addOutfitCondition(HORDE, {lookType = self.teams[2].outfit.lookType, lookAddons = self.teams[2].outfit.lookAddons,
  350. lookHead = self.teams[2].outfit.lookHead, lookBody = self.teams[2].outfit.lookBody, lookLegs = self.teams[2].outfit.lookLegs,
  351. lookFeet = self.teams[2].outfit.lookFeet})
  352.  
  353. local block = false
  354.  
  355. for _, item in pairs(self.itensBloqueados) do
  356. local id = item.id
  357. if player:getItemCount(id) >= 1 then
  358. player:sendCancelMessage('Desculpe, não é permitido entrar com ' .. ItemType(id):getName() .. ' no evento Battlefield.')
  359. block = true
  360. end
  361. end
  362. if self.playerCount >= self.maxPlayers then
  363. player:sendCancelMessage('Desculpe, já existem ' .. self.maxPlayers .. ' jogadores dentro do evento Battlefield.')
  364. block = true
  365. end
  366. if player:getReset() < minResets then
  367. player:sendCancelMessage('Você não possui resets suficientes. Volte quando possuir ' .. minResets .. ' resets.')
  368. block = true
  369. end
  370. if player:getLevel() < self.minLevel and not(player:getReset() >= minResets) then
  371. player:sendCancelMessage('Você não possui level suficiente. Volte quando possuir level ' .. self.minLevel .. '.')
  372. block = true
  373. end
  374.  
  375. if not block then
  376. local team
  377. if self.teams[1].size == self.teams[2].size then
  378. team = math.random(1, 2)
  379. elseif self.teams[1].size > self.teams[2].size then
  380. team = 2
  381. else
  382. team = 1
  383. end
  384.  
  385. if team == 1 then
  386. doAddCondition(player, ALLIANCE)
  387. player:teleportTo(self.teams[team].position)
  388. else
  389. doAddCondition(player, HORDE)
  390. player:teleportTo(self.teams[team].position)
  391. end
  392.  
  393. local info = {name = player:getName(), team = team}
  394. self.teams[team].size = self.teams[team].size + 1
  395. self.teams[team].players[player:getName()] = info
  396. self.playerCount = self.playerCount + 1
  397.  
  398. player:openChannel(self.idChannelEvent)
  399. Game.sendEventMessage(string.format("%s entrou na batalha pela %s!", info.name, self.teams[team].name))
  400. Game.sendEventMessage(string.format("Jogadores na %s: %s || Jogadores na %s: %s", self.teams[1].name, self.teams[1].size, self.teams[2].name, self.teams[2].size))
  401.  
  402. -- Salvando HP e MANA (importante)
  403. local vida = player:getMaxHealth()
  404. local mana = player:getMaxMana()
  405. player:setStorageValue(self.healthStorage, vida)
  406. player:setStorageValue(self.manaStorage, mana)
  407.  
  408. local skillMax = 0
  409. -- Salvando SKILL (importante)
  410. if isMage(player:getVocation():getId(), 0) then
  411. skillMax = 120
  412. player:setStorageValue(self.magicStorage, player:getMagicLevel())
  413. player:setStorageValue(self.triesmgStg, player:getManaSpent())
  414. if player:getMagicLevel() > skillMax then
  415. player:setSkill(SKILL_MAGLEVEL, skillMax)
  416. end
  417. else
  418. for _, skill in pairs(self.skillLevel) do
  419. local name = skill.name
  420. local storage = skill.storage
  421. local triesStg = skill.triesStg
  422. if name == SKILL_SHIELD then
  423. skillMax = 130
  424. else
  425. skillMax = 130
  426. end
  427. player:setStorageValue(storage, player:getSkillLevel(name))
  428. player:setStorageValue(triesStg, player:getSkillTries(name))
  429. if player:getSkillLevel(name) > skillMax then
  430. player:setSkill(name, skillMax)
  431. end
  432. end
  433. end
  434.  
  435. player:setStorageValue(self.safeSkills, 1)
  436.  
  437. -- Mudando HP e MANA (importante)
  438. player:setMaxHealth(player:getLevel()*player:getVocation():getHealthGain())
  439. player:setMaxMana(player:getLevel()*player:getVocation():getManaGain())
  440.  
  441. player:registerEvent("Battlefield_PrepareDeath")
  442. player:registerEvent("Battlefield_HealthChange")
  443. player:registerEvent("Battlefield_ManaChange")
  444. player:registerEvent("Battlefield_Logout")
  445. return true -- Entrou no evento!
  446. end
  447. end
  448.  
  449. function Battlefield:onLeave(player)
  450. local info = self:findPlayer(player)
  451. if not info then -- Se não encontrou jogador lá dentro
  452. return false
  453. end
  454.  
  455. player:unregisterEvent("Battlefield_HealthChange")
  456. player:unregisterEvent("Battlefield_PrepareDeath")
  457. player:unregisterEvent("Battlefield_ManaChange")
  458. player:unregisterEvent("Battlefield_Logout")
  459.  
  460. player:teleportTo(player:getTown():getTemplePosition())
  461. self.teams[info.team].size = self.teams[info.team].size - 1
  462. self.teams[info.team].players[info.name] = nil
  463.  
  464. local skillMax = 0
  465. -- Devolvendo SKILL (importante)
  466. if isMage(player:getVocation():getId(), 0) then
  467. skillMax = 120
  468. player:setSkill(SKILL_MAGLEVEL, player:getStorageValue(self.magicStorage))
  469. player:addManaSpent(player:getStorageValue(self.triesmgStg))
  470. else
  471. for _, skill in pairs(self.skillLevel) do
  472. local name = skill.name
  473. local storage = skill.storage
  474. local triesStg = skill.triesStg
  475. if name == SKILL_SHIELD then
  476. skillMax = 130
  477. else
  478. skillMax = 130
  479. end
  480. player:setSkill(name, player:getStorageValue(storage))
  481. player:addSkillTries(name, player:getStorageValue(triesStg))
  482. end
  483. end
  484.  
  485. player:setStorageValue(self.safeSkills, -1)
  486.  
  487. -- Devolvendo HP e MANA (importante)
  488. player:setMaxHealth(player:getStorageValue(self.healthStorage))
  489. player:setMaxMana(player:getStorageValue(self.manaStorage))
  490.  
  491. -- Enchendo HP e MANA (importante)
  492. player:addHealth(player:getMaxHealth())
  493. player:addMana(player:getMaxMana())
  494.  
  495. player:removeCondition(CONDITION_INFIGHT)
  496. player:removeCondition(CONDITION_OUTFIT)
  497.  
  498. if self.teams[info.team].size == 0 then
  499. self:Close(info.team == 1 and 2 or 1)
  500. end
  501.  
  502. return true
  503. end
  504.  
  505. function Battlefield:onDeath(player, killer)
  506. local info = self:findPlayer(player)
  507. if not info then
  508. return false
  509. end
  510. if killer and killer.getName then
  511. local killerInfo = self:findPlayer(killer)
  512. if killerInfo and killerInfo.team ~= info.team then
  513. local killerTeam = self.teams[killerInfo.team]
  514. killerTeam.kills = killerTeam.kills + 1
  515. if self.teams[info.team].vidaExtra == 1 then
  516. Game.sendEventMessage(string.format("%s foi morto por %s no evento Battlefield! Devido ao seu time possuir uma vida extra, o jogador foi movido ao início da arena.", player:getName(), killer:getName()))
  517. else
  518. Game.sendEventMessage(string.format("%s foi morto por %s no evento Battlefield!", player:getName(), killer:getName()))
  519. end
  520. end
  521. end
  522. if self.teams[info.team].vidaExtra == 1 then
  523. player:teleportTo(self.teams[info.team].position)
  524. player:addHealth(player:getMaxHealth())
  525. player:addMana(player:getMaxMana())
  526. self.teams[info.team].vidaExtra = 0
  527. else
  528. self:onLeave(player)
  529. end
  530. return true
  531. end
  532. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement