Advertisement
Osni21

Desert

Nov 8th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.27 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <mod name="Team Event" version="2.0" author="GalaxyBR" contact="support@lualand.net" enabled="yes">
  3. <description>
  4.  
  5. Full auto Team BattleEvent(v2.0) for 0.4 :
  6.  
  7. 1- I currently rescripted this event from scratch again.
  8.  
  9. 2- This version is much more better than the one before, it is more cleaner, clearer and with more options.
  10.  
  11. 3- This version was tested on 0.4 latest one 4626, should work on lower rev too.
  12.  
  13. 4- Removed the npc part it is now based on tp creation.
  14.  
  15. 5- More silent boradcasting for in event progress and no spam, I hope!
  16.  
  17. 6- you now get the options to show event stats on cancel msg area and (to / not to) show left players with names each x interval.
  18.  
  19. 8- Team balancer have been added to only balance count in both teams.
  20.  
  21. 9- Added a countdown option before fight starts.
  22.  
  23. 10- Now starts on a defined time every day
  24.  
  25. </description>
  26.  
  27. <config name="teamSetting"><![CDATA[
  28. --[[Local Config]]--
  29.  
  30. inBlue = 9900
  31. inRed = 9901
  32. joiner = 9907
  33.  
  34. blueKills = 9902
  35. redKills = 9903
  36.  
  37. eventRecruiting = 9904
  38. eventStarted = 9905
  39. eventTime = 9906
  40.  
  41. itemToGet = 9908
  42. countItemToGet = 9909
  43.  
  44. nextExecute = 9910
  45.  
  46. blueCount = 9911
  47. redCount = 9912
  48.  
  49. --// Positions
  50.  
  51. teleporterPosition = {x = 163, y = 167, z = 7}
  52.  
  53. waitRoomPlace = {x = 1239, y = 1047, z = 1}
  54.  
  55. waitRoomDimensions = {
  56. startPos = {x = 1235, y = 1044, z = 1},
  57. endPos = {x = 1244, y = 1056, z = 1}
  58. }
  59.  
  60.  
  61. eventPlaceDimensions = {
  62. startPos = {x = 1173, y = 1017, z = 2},
  63. endPos = {x = 1298, y = 1074, z = 2}
  64. }
  65. blueTeamPos = {x = 1178, y = 1060, z = 2}
  66. redTeamPos = {x = 1293, y = 1027, z = 2}
  67.  
  68.  
  69. --// General settings
  70.  
  71. recruitTime = 5
  72.  
  73. minimumPlayersJoins = 2
  74.  
  75. balanceTeams = true
  76.  
  77.  
  78. removeTeleportOnEventEnd = true
  79.  
  80. eventMaxTime = 5
  81.  
  82. showEventSats = true
  83.  
  84. sendLeftPlayers = true
  85. intervalToSendLeftPlayers = 11
  86.  
  87.  
  88. countDownOnStart = true
  89.  
  90. countDownFrom = 10
  91.  
  92. minJoinLevel = 100
  93.  
  94. rewards = {
  95. [100] = { {6527,80} , {"golden coin",30} }
  96. }
  97. ]]></config>
  98. <lib name="teamFunctions"><![CDATA[
  99. domodlib('teamSetting')
  100.  
  101. local bmale = createConditionObject(CONDITION_OUTFIT)
  102. setConditionParam(bmale, CONDITION_PARAM_TICKS, -1)
  103. addOutfitCondition(bmale, {lookType = math.random(128,134), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})
  104.  
  105. local bfemale = createConditionObject(CONDITION_OUTFIT)
  106. setConditionParam(bfemale, CONDITION_PARAM_TICKS, -1)
  107. addOutfitCondition(bfemale, {lookType = math.random(136,142), lookHead = 88, lookBody = 88, lookLegs = 88, lookFeet = 88, lookTypeEx = 0, lookAddons = 3})
  108.  
  109. local rmale = createConditionObject(CONDITION_OUTFIT)
  110. setConditionParam(rmale, CONDITION_PARAM_TICKS, -1)
  111. addOutfitCondition(rmale, {lookType = math.random(128,134), lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
  112.  
  113. local rfemale = createConditionObject(CONDITION_OUTFIT)
  114. setConditionParam(rfemale, CONDITION_PARAM_TICKS, -1)
  115. addOutfitCondition(rfemale, {lookType = math.random(136,142),lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = 3})
  116.  
  117. local infight = createConditionObject(CONDITION_INFIGHT,-1)
  118. --[[Local Config]]--
  119.  
  120. --[[Functions]]--
  121.  
  122. -- General info
  123. function isFightOn()
  124. return getStorage(eventStarted) > 0
  125. end
  126. function isRecruitOn()
  127. return getStorage(eventRecruiting) > 0
  128. end
  129. function getMinJoinLevel()
  130. return minJoinLevel
  131. end
  132. function getJoiners()
  133. joiners = {}
  134. for _,cid in ipairs(getPlayersOnline()) do
  135. if isJoiner(cid) then
  136. if isInRecruitArea(cid) or isInFightArea(cid) then
  137. table.insert(joiners,cid)
  138. end
  139. end
  140. end
  141. return joiners
  142. end
  143.  
  144. function getLeftMembersNames(team)
  145. str = "Oponents left("..#team..") :"
  146. left = ""
  147. for k,cid in ipairs(team) do left = (left ..""..(k == 1 and "" or ", ")..""..getCreatureName(cid).."["..getPlayerLevel(cid).."]" ) end
  148. str = str .." " .. (left == "" and "none" or left).. "."
  149. return str
  150. end
  151. function disPlayEventStats()
  152. if not showEventSats then return false end
  153. if getStorage(eventTime) - os.time() <= 0 then return false end
  154.  
  155. left = os.date("%M:%S",(getStorage(eventTime) - os.time()))
  156. for _,cid in ipairs(getJoiners()) do
  157. oponentsLeft = isBlue(cid) and #getRedMembers() or #getBlueMembers()
  158. teamMatesLeft = isBlue(cid) and math.max(0,#getBlueMembers()-1) or math.max(0,#getRedMembers()-1)
  159. doPlayerSendCancel(cid,"Tempo Restante: ".. left.." || Inimigos Restantes: "..oponentsLeft.."/"..oponentCount(cid).." || Aliados Restantes: "..teamMatesLeft.."/".. math.max(0,matesCount(cid)-1))
  160. end
  161.  
  162. end
  163.  
  164. function doSendLeftPlayers()
  165. if not sendLeftPlayers then return false end
  166. if intervalToSendLeftPlayers <= 10 then return false end
  167. for _,cid in ipairs(getJoiners()) do
  168. doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],getLeftMembersNames(isRed(cid) and getBlueMembers() or getRedMembers()))
  169. end
  170. end
  171.  
  172. function getBlueMembers()
  173. members = {}
  174. for _,cid in ipairs(getPlayersOnline()) do
  175. if isBlue(cid) then
  176. table.insert(members,cid)
  177. end
  178. end
  179. return members
  180. end
  181. function getRedMembers()
  182. members = {}
  183. for _,cid in ipairs(getPlayersOnline()) do
  184. if isRed(cid) then
  185. table.insert(members,cid)
  186. end
  187. end
  188. return members
  189. end
  190.  
  191.  
  192. -- starting fight
  193.  
  194. function startRecruiting()
  195. doSetStorage(eventRecruiting,1)
  196. end
  197. function startEvent()
  198. doSetStorage(eventRecruiting,-1)
  199.  
  200. if removeTeleportOnEventEnd then
  201. tp = getTileItemById(teleporterPosition,1387).uid
  202. if tp > 0 then doRemoveItem(tp) end
  203. end
  204.  
  205. if not balanceTeams() then
  206. resetEvent()
  207. return false
  208. end
  209. for _,cid in ipairs(getBlueMembers()) do
  210. doTeleportThing(cid,blueTeamPos,false)
  211. doSendMagicEffect(getThingPos(cid),10)
  212. end
  213. setBlueCount(#getBlueMembers())
  214. for _,cid in ipairs(getRedMembers()) do
  215. doTeleportThing(cid,redTeamPos,false)
  216. doSendMagicEffect(getThingPos(cid),10)
  217. end
  218. setRedCount(#getRedMembers())
  219. startCountDown()
  220. return true
  221. end
  222.  
  223. function setBlueCount(count)
  224. doSetStorage(blueCount,-1)
  225. doSetStorage(blueCount,count)
  226. end
  227. function oponentCount(cid)
  228. return isBlue(cid) and getStorage(redCount) or getStorage(blueCount)
  229. end
  230. function matesCount(cid)
  231. return isBlue(cid) and getStorage(blueCount) or getStorage(redCount)
  232. end
  233.  
  234. function setRedCount(count)
  235. doSetStorage(redCount,-1)
  236. doSetStorage(redCount,count)
  237. end
  238. function balanceTeams()
  239. members = getJoiners()
  240. if #members < minimumPlayersJoins then
  241. doBroadcastMessage("Team-Battle event was cancelled as only ".. #members .. " players joined.")
  242. return false
  243. end
  244. if (math.mod(#members,2) ~= 0) then
  245. kicked = members[#members]
  246. clearTeamEventStorages(kicked)
  247. doPlayerSendTextMessage(kicked,MESSAGE_TYPES["info"],"Sorry, you have been kicked out of event for balancing both teams.")
  248. end
  249. count = 1
  250. for _,cid in ipairs(getJoiners()) do
  251. if (math.mod(count,2) ~= 0) then
  252. addToBlue(cid)
  253. else
  254. addToRed(cid)
  255. end
  256. count = count + 1
  257. end
  258. return true
  259. end
  260. function startCountDown()
  261. if(countDownOnStart) then
  262. for _,cid in ipairs(getJoiners()) do
  263. doCreatureSetNoMove(cid,true)
  264. for i = 0,countDownFrom do
  265. addEvent(doPlayerSendTextMessage,i*1000, cid, MESSAGE_TYPES["info"], (i == 0 and countDownFrom or countDownFrom-i) )
  266. end
  267. end
  268. addEvent(startFight,(countDownFrom+1)*1000)
  269. else
  270. startFight()
  271. end
  272. end
  273. function startFight()
  274. doSetStorage(eventStarted,1)
  275. for _,cid in ipairs(getJoiners()) do
  276. doCreatureSetNoMove(cid,false)
  277. doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],"Fight Starts!")
  278. end
  279. addEvent(endTeamEvent,eventMaxTime*60*1000,"maxTime")
  280. doSetStorage(eventTime,os.time()+eventMaxTime*60)
  281. end
  282.  
  283. function teleportToWaitRoom(cid)
  284. doTeleportThing(cid,waitRoomPlace)
  285. doSendMagicEffect(waitRoomPlace,10)
  286. if getPlayerGroupId(cid) < 4 then
  287. addToJoiners(cid)
  288. end
  289. doPlayerSendTextMessage(cid,MESSAGE_TYPES["blue"],"Please be patient till the event starts and don't logout.")
  290. return true
  291. end
  292.  
  293.  
  294.  
  295. -- Modifing teams & checking member states
  296. function isBlue(cid)
  297. return (getPlayerStorageValue(cid,inBlue) > 0)
  298. end
  299. function isRed(cid)
  300. return (getPlayerStorageValue(cid,inRed) > 0)
  301. end
  302. function isJoiner(cid)
  303. return (getPlayerStorageValue(cid,joiner) > 0)
  304. end
  305. function addToBlue(cid)
  306. setPlayerStorageValue(cid,inBlue,1)
  307. doAddCondition(cid, (getPlayerSex(cid) == 1) and bmale or bfemale)
  308. doAddCondition(cid,infight)
  309. end
  310. function addToRed(cid)
  311. setPlayerStorageValue(cid,inRed,1)
  312. doAddCondition(cid, (getPlayerSex(cid) == 1) and rmale or rfemale)
  313. doAddCondition(cid,infight)
  314. end
  315. function addToJoiners(cid)
  316. setPlayerStorageValue(cid,joiner,1)
  317. end
  318. function removeFromBlue(cid)
  319. setPlayerStorageValue(cid,inBlue,-1)
  320. end
  321. function removeFromRed(cid)
  322. setPlayerStorageValue(cid,inRed,-1)
  323. end
  324. function removeFromjoiners(cid)
  325. setPlayerStorageValue(cid,joiner,-1)
  326. end
  327. function isInRecruitArea(cid)
  328. return isInRange(getThingPos(cid),waitRoomDimensions.startPos,waitRoomDimensions.endPos)
  329. end
  330. function isInFightArea(cid)
  331. return isInRange(getThingPos(cid),eventPlaceDimensions.startPos,eventPlaceDimensions.endPos)
  332. end
  333. function clearTeamEventStorages(cid)
  334. if isInRecruitArea(cid) or isInFightArea(cid) then
  335. doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
  336. doSendMagicEffect(getThingPos(cid),10)
  337. end
  338.  
  339. if isFightOn() then
  340. if isJoiner(cid) then
  341. if isBlue(cid) then
  342. addRedKills()
  343. elseif isRed(cid) then
  344. addBlueKills()
  345. end
  346. doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"You have died in Team-Battle Event.")
  347. end
  348. end
  349.  
  350. removeFromjoiners(cid)
  351. removeFromBlue(cid)
  352. removeFromRed(cid)
  353. doRemoveConditions(cid, false)
  354.  
  355. end
  356. function haveUnrecivedReward(cid)
  357. return getPlayerStorageValue(cid,itemToGet) > 0 and getPlayerStorageValue(cid,countItemToGet) > 0
  358. end
  359. function recieveLateReward(cid)
  360. if haveUnrecivedReward(cid) then
  361. if not doPlayerAddItem(cid,getPlayerStorageValue(cid,itemToGet),getPlayerStorageValue(cid,countItemToGet),false) then
  362. msg = "You need to free some space then relog to take your reward."
  363. doPlayerSendTextMessage(cid,MESSAGE_TYPES["warning"],msg)
  364. else
  365. setPlayerStorageValue(cid,itemToGet,-1)
  366. setPlayerStorageValue(cid,countItemToGet,-1)
  367. doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],"You have recieved your reward.")
  368. end
  369. end
  370. end
  371.  
  372. -- Win or lose
  373. function thereIsAWinner()
  374. if redWon() or blueWon() then
  375. return true
  376. end
  377. return false
  378. end
  379. function blueWon()
  380. return( (#getBlueMembers() > 0 ) and ( #getRedMembers() == 0) )
  381. end
  382. function redWon()
  383. return( (#getRedMembers() > 0) and (#getBlueMembers() == 0) )
  384. end
  385. function isDraw()
  386. return #getBlueMembers() == #getRedMembers()
  387. end
  388. function getWinner()
  389. if #getBlueMembers() > #getRedMembers() then
  390. return {getBlueMembers(),getRedMembers(),"Blue team won."}
  391. elseif #getRedMembers() > #getBlueMembers() then
  392. return {getRedMembers(),getBlueMembers(),"Red team won."}
  393. else
  394. return { {},{},"it was a draw."}
  395. end
  396. end
  397.  
  398.  
  399. -- Adding kills
  400. function addBlueKills()
  401. doSetStorage(blueKills, math.max(1,getStorage(blueKills)+1))
  402. end
  403. function addRedKills()
  404. doSetStorage(redKills, math.max(1,getStorage(redKills)+1))
  405. end
  406.  
  407. -- Ending event
  408.  
  409. function endTeamEvent(type)
  410. if isFightOn() then
  411. doSetStorage(eventStarted,-1)
  412. doBroadcastMessage("Team-Battle event ended and "..getWinner()[3])
  413. if not isDraw() then
  414. win(getWinner()[1],type)
  415. lose(getWinner()[2],type)
  416. else
  417. draw()
  418. end
  419. end
  420. addEvent(resetEvent,2 * 1000) --- tp player to home remove all storages and reset event global storages
  421. end
  422.  
  423. function getPercent()
  424. rand= math.random(1,100)
  425. prev = 0
  426. chosenItem = 0
  427. for k, v in pairs(rewards) do
  428. if rand > prev and rand <= k+prev then
  429. chosenItem = k
  430. break
  431. else
  432. prev = k+prev
  433. end
  434. end
  435. return chosenItem
  436. end
  437.  
  438. function generateReward(cid)
  439. percent = getPercent()
  440. if percent == 0 then
  441. print("Error in the reward item. Please inform Doggynub.")
  442. return true
  443. end
  444.  
  445. randomizer = rewards[percent][math.random(1,#rewards[percent])]
  446. item = not tonumber(randomizer[1]) and getItemIdByName(randomizer[1]) or randomizer[1]
  447. count = isItemStackable(item) and math.min(randomizer[2],100) or 1
  448. if item == nil or item == 0 then
  449. print("Error in the item format. Please inform Doggynub.")
  450. return true
  451. end
  452.  
  453. msg = "You have won ".. (count == 1 and "a" or count) .." " .. getItemNameById(item) .. "" .. (count == 1 and "" or "s").."."
  454.  
  455. if not doPlayerAddItem(cid,item,count,false) then
  456. msg = msg.. "You need to free some space then relog to take your reward."
  457. setPlayerStorageValue(cid,itemToGet,item)
  458. setPlayerStorageValue(cid,countItemToGet,count)
  459. end
  460.  
  461. doPlayerSendTextMessage(cid,MESSAGE_TYPES["white"],msg)
  462.  
  463. end
  464.  
  465.  
  466.  
  467. function generateStatsMessage(cid, type, stats)
  468. msg = {
  469. ["KO"] = { ["win"] = "Event ended. Your team have won by killing all oponent's team members. You will recieve your reward shortly, check incoming messages.",
  470. ["lose"] = "Event ended. Your team have lost as the Oponent team killed all your team's members."
  471. },
  472. ["maxTime"] = {
  473. ["win"] = "Event max-time finished and your team have won. You will recieve your reward shortly, check incoming messages.",
  474. ["lose"] = "Event max-time finished and your team have lost.",
  475. ["draw"] = "Event max-time finished and it is a draw.(no team won)"
  476. }
  477. }
  478. doPlayerSendTextMessage(cid,MESSAGE_TYPES["info"],msg[type][stats])
  479.  
  480. end
  481. function win(winners,type)
  482. for _,cid in ipairs(winners) do
  483. generateStatsMessage(cid, type, "win")
  484. generateReward(cid)
  485. end
  486. end
  487. function lose(losers,type)
  488. for _,cid in ipairs(losers) do
  489. generateStatsMessage(cid, type, "lose")
  490. end
  491. end
  492. function draw()
  493. for _,cid in ipairs(getJoiners()) do
  494. generateStatsMessage(cid, "maxTime", "draw")
  495. end
  496. end
  497.  
  498. function resetEvent()
  499. doSetStorage(eventRecruiting,-1)
  500. doSetStorage(nextExecute,-1)
  501. doSetStorage(eventStarted,-1)
  502. doSetStorage(eventTime,-1)
  503. doSetStorage(blueKills,-1)
  504. doSetStorage(redKills,-1)
  505. for _,cid in ipairs(getPlayersOnline()) do
  506. if isBlue(cid) or isRed(cid) or isJoiner(cid) then
  507. clearTeamEventStorages(cid)
  508. end
  509. end
  510. end
  511.  
  512.  
  513. ]]></lib>
  514. <event type="login" name="teambattleLogin" event="script"><![CDATA[
  515. domodlib('teamFunctions')
  516.  
  517. function onLogin(cid)
  518. clearTeamEventStorages(cid)
  519. recieveLateReward(cid)
  520.  
  521. registerCreatureEvent(cid, "teamEventStats")
  522. registerCreatureEvent(cid, "teambattleLogout")
  523. registerCreatureEvent(cid, "teambattleCombat")
  524. return true
  525. end
  526. ]]></event>
  527. <event type="combat" name="teambattleCombat" event="script"><![CDATA[
  528. domodlib('teamFunctions')
  529.  
  530. function onCombat(cid, target)
  531. if isFightOn() then
  532. if isBlue(cid) and isBlue(target) then
  533. return false
  534. end
  535. if isRed(cid) and isRed(target) then
  536. return false
  537. end
  538. end
  539. return true
  540. end
  541.  
  542. ]]></event>
  543. <event type="logout" name="teambattleLogout" event="script"><![CDATA[
  544. domodlib('teamFunctions')
  545.  
  546. function onLogout(cid)
  547. clearTeamEventStorages(cid)
  548. if thereIsAWinner() then
  549. endTeamEvent("KO")
  550. end
  551. return true
  552. end
  553.  
  554. ]]></event>
  555. <event type="statschange" name="teamEventStats" event="script"><![CDATA[
  556. domodlib('teamFunctions')
  557.  
  558. corpse_ids = {
  559. [0] = 3065, -- female
  560. [1] = 3058 -- male
  561. }
  562. function onStatsChange(cid, attacker, type, combat, value)
  563. if combat == COMBAT_HEALING then
  564. return true
  565. end
  566. if getCreatureHealth(cid) > value then
  567. return true
  568. end
  569.  
  570. if isInFightArea(cid) and isFightOn() then
  571. if isBlue(cid) or isRed(cid) then
  572. corpse = doCreateItem(corpse_ids[getPlayerSex(cid)], 1, getThingPos(cid))
  573. doCreateItem(2016, 2, getThingPos(cid))
  574. clearTeamEventStorages(cid)
  575. doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".\n[Team-Event kill]")
  576. doCreatureAddHealth(cid,getCreatureMaxHealth(cid))
  577. if thereIsAWinner() then
  578. endTeamEvent("KO")
  579. end
  580.  
  581. return false
  582.  
  583. end
  584.  
  585. end
  586.  
  587. return true
  588. end
  589. ]]></event>
  590.  
  591. <globalevent name = "teamBattletime" interval="1" event="script"><![CDATA[
  592. domodlib('teamFunctions')
  593.  
  594. function onThink()
  595. if isFightOn() then
  596. disPlayEventStats()
  597.  
  598. if getStorage(nextExecute) == -1 or getStorage(nextExecute) <= os.time() then
  599. doSendLeftPlayers()
  600. doSetStorage(nextExecute,os.time()+intervalToSendLeftPlayers)
  601. end
  602. end
  603. return true
  604. end
  605.  
  606. ]]></globalevent>
  607. <movevent type="StepIn" actionid="9990" event="script"><![CDATA[
  608. domodlib('teamFunctions')
  609.  
  610. function onStepIn(cid, item, position, fromPosition)
  611. if not isRecruitOn() then
  612. doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Event isn't currently opened.")
  613. doTeleportThing(cid,fromPosition)
  614. doSendMagicEffect(fromPosition,2)
  615. return true
  616. end
  617. if getPlayerLevel(cid) < getMinJoinLevel() then
  618. doPlayerSendTextMessage(cid,MESSAGE_TYPES["orange"],"Only players of level ".. getMinJoinLevel().. "+ can join this event.")
  619. doTeleportThing(cid,fromPosition)
  620. return true
  621. end
  622. teleportToWaitRoom(cid)
  623. return true
  624. end
  625.  
  626.  
  627.  
  628.  
  629. ]]> </movevent>
  630. </mod>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement