Guest User

Untitled

a guest
Sep 10th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.15 KB | None | 0 0
  1.  
  2. ---- based on Jordanhenry pet system version 1.77 (changelog)
  3. ---- edited by hellboy
  4.  
  5. -- config
  6. PETS = {
  7. PREFIX = "PET_",
  8. CHANNELID = 10,
  9.  
  10. CONFIG = {
  11. introduction = "You may catch pets using command '!petcatch'. If your pet dies, you have to revive it in order to summon it again. Some pets have a special requirement in order to catch them, some cannot be catched at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
  12. sameSpeed = true,
  13.  
  14. healOnLevelUp = true,
  15. standardHpAdd = 5,
  16. expMultipler = 1,
  17. maxLevel = 10,
  18.  
  19. healSoulCost = 0.1,
  20. healSoulBase = 25,
  21.  
  22. reviveSoulBaseCost = 50,
  23. reviveSoulLevelCost = 0.2
  24. },
  25. IDENTIFICATION = {
  26. [1] = {
  27. name = "Cat",
  28. health = 100,
  29. evolve = {
  30. to = 3,
  31. at = 10
  32. },
  33. check = true
  34. },
  35. [2] = {
  36. name = "Dog",
  37. health = 100,
  38. evolve = {
  39. to = 4,
  40. at = 10
  41. },
  42. check = true
  43. },
  44. [3] = {
  45. name = "Tiger",
  46. health = 300,
  47. check = false,
  48. info = "Evolves from Cat."
  49. },
  50. [4] = {
  51. name = "Lion",
  52. health = 300,
  53. mountId = 40,
  54. check = false,
  55. info = "Evolves from Dog."
  56. },
  57. [5] = {
  58. name = "Husky",
  59. health = 150,
  60. check = function(player) return player:getPremiumDays() > 0 end,
  61. info = "Requires a premium account."
  62. },
  63. [6] = {
  64. name = "Wolf",
  65. health = 200,
  66. evolve = {
  67. to = 7,
  68. at = 4
  69. },
  70. check = function(player) return player:getLevel() >= 10 end,
  71. info = "Requires level 10."
  72. },
  73. [7] = {
  74. name = "War Wolf",
  75. health = 500,
  76. evolve = {
  77. to = 8,
  78. at = 55
  79. },
  80. check = false,
  81. info = "Evolves from Wolf."
  82. },
  83. [8] = {
  84. name = "Werewolf",
  85. health = 1000,
  86. check = false,
  87. info = "Evolves from War Wolf."
  88. },
  89. [9] = {
  90. name = "Bear",
  91. health = 300,
  92. mountId = 3,
  93. check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
  94. info = "Only available to druids above level 10."
  95. },
  96. [10] = {
  97. name = "Panda",
  98. health = 300,
  99. mountId = 19,
  100. check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
  101. info = "Only available to druids above level 10."
  102. },
  103. [11] = {
  104. name = "Chicken",
  105. health = 50,
  106. check = true
  107. },
  108. [12] = {
  109. name = "Sheep",
  110. health = 50,
  111. check = true
  112. },
  113. [13] = {
  114. name = "Seagull",
  115. health = 100,
  116. check = function(player) return player:getPremiumDays() > 0 end,
  117. info = "Requires a premium account."
  118. },
  119. [14] = {
  120. name = "Parrot",
  121. health = 100,
  122. check = function(player) return player:getPremiumDays() > 0 end,
  123. info = "Requires a premium account."
  124. },
  125. [15] = {
  126. name = "Penguin",
  127. health = 100,
  128. check = function(player) return player:getPremiumDays() > 0 end,
  129. info = "Requires a premium account."
  130. },
  131. [16] = {
  132. name = "Elephant",
  133. health = 300,
  134. check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 10 end,
  135. contain = 5,
  136. info = "Only available to Premium accounts above level 10."
  137. },
  138. [17] = {
  139. name = "Dragon Hatchling",
  140. health = 300,
  141. evolve = {
  142. to = 18,
  143. at = 20
  144. },
  145. check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 25 and player:isSorcerer() end,
  146. info = "Only available to Premium Sorcerers above level 25."
  147. },
  148. [18] = {
  149. name = "Dragon",
  150. health = 1000,
  151. check = false,
  152. info = "Evolves from Dragon Hatchling."
  153. }
  154. },
  155.  
  156. STORAGE = {
  157. TYPE = 10000,
  158. UID = 10001,
  159. LOSTHEALTH = 10002,
  160. MAXHEALTH = 10003,
  161. EXPERIENCE = 10004,
  162. LEVEL = 10005
  163. },
  164.  
  165. SYSTEM = {
  166. EVOLUTION = true
  167. }
  168. }
  169.  
  170. --/ config
  171. function Player.petSystemMessage(self, txt, talkType)
  172. local playerId = self:getId()
  173. talkType = (talkType == nil) and TALKTYPE_CHANNEL_O or talkType
  174.  
  175. local function eventMessage(playerId, text, talkType)
  176. local player = Player(playerId)
  177. if not player then
  178. return false
  179. end
  180. player:sendChannelMessage('[PET-SYSTEM]', txt, talkType, PETS.CHANNELID)
  181. end
  182. addEvent(eventMessage, 150, playerId, text, talkType)
  183.  
  184. --self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '[PET-SYSTEM] '..txt)
  185. return true
  186. end
  187.  
  188. -- get
  189. function Player.getPetExperience(self)
  190. return self:getStorageValue(PETS.STORAGE.EXPERIENCE)
  191. end
  192.  
  193. function Player.getPetLevel(self)
  194. return self:getStorageValue(PETS.STORAGE.LEVEL)
  195. end
  196.  
  197. function Player.getPetType(self)
  198. return self:getStorageValue(PETS.STORAGE.TYPE)
  199. end
  200.  
  201. function Player.getPetUid(self)
  202. return self:getStorageValue(PETS.STORAGE.UID)
  203. end
  204.  
  205. function Player.getPetMaxHealth(self)
  206. return self:getStorageValue(PETS.STORAGE.MAXHEALTH)
  207. end
  208.  
  209. function Player.getPetLostHealth(self)
  210. return self:getStorageValue(PETS.STORAGE.LOSTHEALTH)
  211. end
  212.  
  213. -- set
  214. function Player.setPetExperience(self, experience)
  215. return self:setStorageValue(PETS.STORAGE.EXPERIENCE, experience)
  216. end
  217.  
  218. function Player.setPetLevel(self, petLevel)
  219. return self:setStorageValue(PETS.STORAGE.LEVEL, petLevel)
  220. end
  221.  
  222. function Player.setPetType(self, petType)
  223. return self:setStorageValue(PETS.STORAGE.TYPE, petType)
  224. end
  225.  
  226. function Player.setPetUid(self, petUid)
  227. return self:setStorageValue(PETS.STORAGE.UID, petUid)
  228. end
  229.  
  230. function Player.setPetMaxHealth(self, health)
  231. return self:setStorageValue(PETS.STORAGE.MAXHEALTH, health)
  232. end
  233.  
  234. function Player.setPetLostHealth(self, health)
  235. return self:setStorageValue(PETS.STORAGE.LOSTHEALTH, health)
  236. end
  237.  
  238. function Player.doAddPet(self, petType)
  239. local pet = Creature(self:getStorageValue(PETS.STORAGE.UID))
  240. if pet then
  241. return false
  242. end
  243.  
  244. self:setPetUid(0)
  245. self:setPetExperience(0)
  246. self:setPetLevel(1)
  247. self:setPetType(petType)
  248.  
  249. self:setPetMaxHealth(PETS.IDENTIFICATION[petType].health)
  250. self:setPetLostHealth(0)
  251. return true
  252. end
  253.  
  254. function Player.doResetPet(self)
  255. for _, i in pairs(PETS.STORAGE) do
  256. self:setStorageValue(i, -1)
  257. end
  258. return true
  259. end
  260.  
  261. function Player.doRemovePet(self)
  262. local petUid = self:getPetUid()
  263. local pet = Creature(petUid)
  264.  
  265. if not pet or not pet:isCreature() then
  266. return true
  267. end
  268. local maxHealth = pet:getMaxHealth()
  269.  
  270. self:setPetMaxHealth(maxHealth)
  271. self:setPetLostHealth(maxHealth - pet:getHealth() )
  272. self:setPetUid(0)
  273.  
  274. pet:remove()
  275. return true
  276. end
  277.  
  278. function Player.summonPet(self, position)
  279. local petUid = self:getPetUid()
  280. local pet = Creature(petUid)
  281. if pet and pet:isCreature() then
  282. return false
  283. end
  284.  
  285. local pet = Game.createMonster(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name), position)
  286. if pet then
  287. position:sendMagicEffect(CONST_ME_TELEPORT)
  288. pet:setMaster(self)
  289. local maxHealth = self:getPetMaxHealth()
  290. pet:setMaxHealth(maxHealth)
  291. pet:addHealth(maxHealth - pet:getHealth() - self:getPetLostHealth() )
  292. self:setPetUid( pet:getId() )
  293. pet:setSkull(SKULL_GREEN)
  294. pet:changeSpeed(PETS.CONFIG.sameSpeed and (self:getBaseSpeed() - pet:getBaseSpeed()) or 0)
  295.  
  296. for _, eventName in pairs({"PetDeath", "PetKill"}) do
  297. pet:registerEvent(eventName)
  298. end
  299. return pet
  300. end
  301. return false
  302. end
  303.  
  304. function getExpNeeded(level)
  305. return ( (50 *level^3) -(150 *level^2) +(400 *level) )/3 *PETS.CONFIG.expMultipler
  306. end
  307.  
  308. function Player.addPetExp(self, amount)
  309. if self:getPetLevel() >= PETS.CONFIG.maxLevel then
  310. return false
  311. end
  312.  
  313. local totalExp = self:getPetExperience() + amount
  314. self:setPetExperience(totalExp)
  315. local petLevel, petType, petUid = self:getPetLevel(), self:getPetType(), self:getPetUid()
  316.  
  317. if totalExp >= getExpNeeded(petLevel + 1) then
  318. local pet = Creature(petUid)
  319. pet:setMaxHealth(pet:getMaxHealth() + (PETS.IDENTIFICATION[petType].hpAdd or PETS.CONFIG.standardHpAdd))
  320. self:setPetLevel(petLevel +1)
  321. self:petSystemMessage("Your "..PETS.IDENTIFICATION[petType].name.." has leveled up to level "..(petLevel +1)..".")
  322.  
  323. if PETS.CONFIG.healOnLevelUp then
  324. pet:addHealth( pet:getMaxHealth() )
  325. end
  326.  
  327. if PETS.SYSTEM.EVOLUTION and (PETS.IDENTIFICATION[petType]).evolve and ((PETS.IDENTIFICATION[petType]).evolve.at <= (petLevel +1)) then
  328. local position = pet:getPosition()
  329. self:doRemovePet()
  330. self:setPetType( (PETS.IDENTIFICATION[petType]).evolve.to)
  331. self:setPetMaxHealth( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).health )
  332. self:setPetLostHealth(0)
  333. self:petSystemMessage("Yours "..(PETS.IDENTIFICATION[petType]).name.." evolvet to "..((PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).name)..".")
  334. self:summonPet(position)
  335. end
  336. end
  337.  
  338. return true
  339. end
  340.  
  341. function Player.canGetPet(self, petId)
  342. [i][b]add on bottom data/lib/lib.lua[/b][/i]
  343. [code]
  344. dofile('data.lib/pets_lib.lua')
  345. [/code]
  346.  
  347. [b] data.lib/pets_lib.lua [/b]
  348. [code]
  349. ---- based on Jordanhenry pet system version 1.77 (changelog)
  350. ---- edited by hellboy
  351.  
  352. -- config
  353. PETS = {
  354. PREFIX = "PET_",
  355. CHANNELID = 10,
  356.  
  357. CONFIG = {
  358. introduction = "You may catch pets using command '!petcatch'. If your pet dies, you have to revive it in order to summon it again. Some pets have a special requirement in order to catch them, some cannot be catched at all and can only be gotten by evolution. Type 'commands' for a list of available commands.",
  359. sameSpeed = true,
  360.  
  361. healOnLevelUp = true,
  362. standardHpAdd = 5,
  363. expMultipler = 1,
  364. maxLevel = 10,
  365.  
  366. healSoulCost = 0.1,
  367. healSoulBase = 25,
  368.  
  369. reviveSoulBaseCost = 50,
  370. reviveSoulLevelCost = 0.2
  371. },
  372. IDENTIFICATION = {
  373. [1] = {
  374. name = "Cat",
  375. health = 100,
  376. evolve = {
  377. to = 3,
  378. at = 10
  379. },
  380. check = true
  381. },
  382. [2] = {
  383. name = "Dog",
  384. health = 100,
  385. evolve = {
  386. to = 4,
  387. at = 10
  388. },
  389. check = true
  390. },
  391. [3] = {
  392. name = "Tiger",
  393. health = 300,
  394. check = false,
  395. info = "Evolves from Cat."
  396. },
  397. [4] = {
  398. name = "Lion",
  399. health = 300,
  400. mountId = 40,
  401. check = false,
  402. info = "Evolves from Dog."
  403. },
  404. [5] = {
  405. name = "Husky",
  406. health = 150,
  407. check = function(player) return player:getPremiumDays() > 0 end,
  408. info = "Requires a premium account."
  409. },
  410. [6] = {
  411. name = "Wolf",
  412. health = 200,
  413. evolve = {
  414. to = 7,
  415. at = 4
  416. },
  417. check = function(player) return player:getLevel() >= 10 end,
  418. info = "Requires level 10."
  419. },
  420. [7] = {
  421. name = "War Wolf",
  422. health = 500,
  423. evolve = {
  424. to = 8,
  425. at = 55
  426. },
  427. check = false,
  428. info = "Evolves from Wolf."
  429. },
  430. [8] = {
  431. name = "Werewolf",
  432. health = 1000,
  433. check = false,
  434. info = "Evolves from War Wolf."
  435. },
  436. [9] = {
  437. name = "Bear",
  438. health = 300,
  439. mountId = 3,
  440. check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
  441. info = "Only available to druids above level 10."
  442. },
  443. [10] = {
  444. name = "Panda",
  445. health = 300,
  446. mountId = 19,
  447. check = function(player) return player:isDruid() and player:getLevel() >= 10 end,
  448. info = "Only available to druids above level 10."
  449. },
  450. [11] = {
  451. name = "Chicken",
  452. health = 50,
  453. check = true
  454. },
  455. [12] = {
  456. name = "Sheep",
  457. health = 50,
  458. check = true
  459. },
  460. [13] = {
  461. name = "Seagull",
  462. health = 100,
  463. check = function(player) return player:getPremiumDays() > 0 end,
  464. info = "Requires a premium account."
  465. },
  466. [14] = {
  467. name = "Parrot",
  468. health = 100,
  469. check = function(player) return player:getPremiumDays() > 0 end,
  470. info = "Requires a premium account."
  471. },
  472. [15] = {
  473. name = "Penguin",
  474. health = 100,
  475. check = function(player) return player:getPremiumDays() > 0 end,
  476. info = "Requires a premium account."
  477. },
  478. [16] = {
  479. name = "Elephant",
  480. health = 300,
  481. check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 10 end,
  482. contain = 5,
  483. info = "Only available to Premium accounts above level 10."
  484. },
  485. [17] = {
  486. name = "Dragon Hatchling",
  487. health = 300,
  488. evolve = {
  489. to = 18,
  490. at = 20
  491. },
  492. check = function(player) return player:getPremiumDays() > 0 and player:getLevel() >= 25 and player:isSorcerer() end,
  493. info = "Only available to Premium Sorcerers above level 25."
  494. },
  495. [18] = {
  496. name = "Dragon",
  497. health = 1000,
  498. check = false,
  499. info = "Evolves from Dragon Hatchling."
  500. }
  501. },
  502.  
  503. STORAGE = {
  504. TYPE = 10000,
  505. UID = 10001,
  506. LOSTHEALTH = 10002,
  507. MAXHEALTH = 10003,
  508. EXPERIENCE = 10004,
  509. LEVEL = 10005
  510. },
  511.  
  512. SYSTEM = {
  513. EVOLUTION = true
  514. }
  515. }
  516.  
  517. --/ config
  518. function Player.petSystemMessage(self, txt, talkType)
  519. local playerId = self:getId()
  520. talkType = (talkType == nil) and TALKTYPE_CHANNEL_O or talkType
  521.  
  522. local function eventMessage(playerId, text, talkType)
  523. local player = Player(playerId)
  524. if not player then
  525. return false
  526. end
  527. player:sendChannelMessage('[PET-SYSTEM]', txt, talkType, PETS.CHANNELID)
  528. end
  529. addEvent(eventMessage, 150, playerId, text, talkType)
  530.  
  531. --self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, '[PET-SYSTEM] '..txt)
  532. return true
  533. end
  534.  
  535. -- get
  536. function Player.getPetExperience(self)
  537. return self:getStorageValue(PETS.STORAGE.EXPERIENCE)
  538. end
  539.  
  540. function Player.getPetLevel(self)
  541. return self:getStorageValue(PETS.STORAGE.LEVEL)
  542. end
  543.  
  544. function Player.getPetType(self)
  545. return self:getStorageValue(PETS.STORAGE.TYPE)
  546. end
  547.  
  548. function Player.getPetUid(self)
  549. return self:getStorageValue(PETS.STORAGE.UID)
  550. end
  551.  
  552. function Player.getPetMaxHealth(self)
  553. return self:getStorageValue(PETS.STORAGE.MAXHEALTH)
  554. end
  555.  
  556. function Player.getPetLostHealth(self)
  557. return self:getStorageValue(PETS.STORAGE.LOSTHEALTH)
  558. end
  559.  
  560. -- set
  561. function Player.setPetExperience(self, experience)
  562. return self:setStorageValue(PETS.STORAGE.EXPERIENCE, experience)
  563. end
  564.  
  565. function Player.setPetLevel(self, petLevel)
  566. return self:setStorageValue(PETS.STORAGE.LEVEL, petLevel)
  567. end
  568.  
  569. function Player.setPetType(self, petType)
  570. return self:setStorageValue(PETS.STORAGE.TYPE, petType)
  571. end
  572.  
  573. function Player.setPetUid(self, petUid)
  574. return self:setStorageValue(PETS.STORAGE.UID, petUid)
  575. end
  576.  
  577. function Player.setPetMaxHealth(self, health)
  578. return self:setStorageValue(PETS.STORAGE.MAXHEALTH, health)
  579. end
  580.  
  581. function Player.setPetLostHealth(self, health)
  582. return self:setStorageValue(PETS.STORAGE.LOSTHEALTH, health)
  583. end
  584.  
  585. function Player.doAddPet(self, petType)
  586. local pet = Creature(self:getStorageValue(PETS.STORAGE.UID))
  587. if pet then
  588. return false
  589. end
  590.  
  591. self:setPetUid(0)
  592. self:setPetExperience(0)
  593. self:setPetLevel(1)
  594. self:setPetType(petType)
  595.  
  596. self:setPetMaxHealth(PETS.IDENTIFICATION[petType].health)
  597. self:setPetLostHealth(0)
  598. return true
  599. end
  600.  
  601. function Player.doResetPet(self)
  602. for _, i in pairs(PETS.STORAGE) do
  603. self:setStorageValue(i, -1)
  604. end
  605. return true
  606. end
  607.  
  608. function Player.doRemovePet(self)
  609. local petUid = self:getPetUid()
  610. local pet = Creature(petUid)
  611.  
  612. if not pet or not pet:isCreature() then
  613. return true
  614. end
  615. local maxHealth = pet:getMaxHealth()
  616.  
  617. self:setPetMaxHealth(maxHealth)
  618. self:setPetLostHealth(maxHealth - pet:getHealth() )
  619. self:setPetUid(0)
  620.  
  621. pet:remove()
  622. return true
  623. end
  624.  
  625. function Player.summonPet(self, position)
  626. local petUid = self:getPetUid()
  627. local pet = Creature(petUid)
  628. if pet and pet:isCreature() then
  629. return false
  630. end
  631.  
  632. local pet = Game.createMonster(PETS.PREFIX .. (PETS.IDENTIFICATION[self:getPetType()].name), position)
  633. if pet then
  634. position:sendMagicEffect(CONST_ME_TELEPORT)
  635. pet:setMaster(self)
  636. local maxHealth = self:getPetMaxHealth()
  637. pet:setMaxHealth(maxHealth)
  638. pet:addHealth(maxHealth - pet:getHealth() - self:getPetLostHealth() )
  639. self:setPetUid( pet:getId() )
  640. pet:setSkull(SKULL_GREEN)
  641. pet:changeSpeed(PETS.CONFIG.sameSpeed and (self:getBaseSpeed() - pet:getBaseSpeed()) or 0)
  642.  
  643. for _, eventName in pairs({"PetDeath", "PetKill"}) do
  644. pet:registerEvent(eventName)
  645. end
  646. return pet
  647. end
  648. return false
  649. end
  650.  
  651. function getExpNeeded(level)
  652. return ( (50 *level^3) -(150 *level^2) +(400 *level) )/3 *PETS.CONFIG.expMultipler
  653. end
  654.  
  655. function Player.addPetExp(self, amount)
  656. if self:getPetLevel() >= PETS.CONFIG.maxLevel then
  657. return false
  658. end
  659.  
  660. local totalExp = self:getPetExperience() + amount
  661. self:setPetExperience(totalExp)
  662. local petLevel, petType, petUid = self:getPetLevel(), self:getPetType(), self:getPetUid()
  663.  
  664. if totalExp >= getExpNeeded(petLevel + 1) then
  665. local pet = Creature(petUid)
  666. pet:setMaxHealth(pet:getMaxHealth() + (PETS.IDENTIFICATION[petType].hpAdd or PETS.CONFIG.standardHpAdd))
  667. self:setPetLevel(petLevel +1)
  668. self:petSystemMessage("Your "..PETS.IDENTIFICATION[petType].name.." has leveled up to level "..(petLevel +1)..".")
  669.  
  670. if PETS.CONFIG.healOnLevelUp then
  671. pet:addHealth( pet:getMaxHealth() )
  672. end
  673.  
  674. if PETS.SYSTEM.EVOLUTION and (PETS.IDENTIFICATION[petType]).evolve and ((PETS.IDENTIFICATION[petType]).evolve.at <= (petLevel +1)) then
  675. local position = pet:getPosition()
  676. self:doRemovePet()
  677. self:setPetType( (PETS.IDENTIFICATION[petType]).evolve.to)
  678. self:setPetMaxHealth( (PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).health )
  679. self:setPetLostHealth(0)
  680. self:petSystemMessage("Yours "..(PETS.IDENTIFICATION[petType]).name.." evolvet to "..((PETS.IDENTIFICATION[(PETS.IDENTIFICATION[petType]).evolve.to]).name)..".")
  681. self:summonPet(position)
  682. end
  683. end
  684.  
  685. return true
  686. end
  687.  
  688. function Player.canGetPet(self, petId)
  689. if self:getGroup():getId() >= 3 then
  690. return true
  691. end
  692.  
  693. if type(PETS.IDENTIFICATION[petId].check) == "function" then
  694. return PETS.IDENTIFICATION[petId].check(self)
  695. end
  696. return PETS.IDENTIFICATION[petId].check
  697. end
  698. [/code]
  699. if self:getGroup():getId() >= 3 then
  700. return true
  701. end
  702.  
  703. if type(PETS.IDENTIFICATION[petId].check) == "function" then
  704. return PETS.IDENTIFICATION[petId].check(self)
  705. end
  706. return PETS.IDENTIFICATION[petId].check
  707. end
Add Comment
Please, Sign In to add comment