Advertisement
Eshkation-

Tamagotchi v2.0

Jun 13th, 2014
4,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.33 KB | None | 0 0
  1. -- Tamagotchi v2.0 by Eshkation. Bugs or Ideias? Comment on topic!
  2.  
  3. tfm.exec.disableAutoShaman(true)
  4. tfm.exec.disableAutoNewGame(true)
  5. tfm.exec.disableAfkDeath(true)
  6. tfm.exec.newGame("@5087869")
  7.  
  8. moveTime = os.time()
  9.  
  10. username = "Eshkation" -- Put your name here!
  11.  
  12. clickToHatch = 0
  13. clickToClear = 0
  14.  
  15. level = 1
  16. petInfo = {mood = 100, hungry = 100, sleep = 100}
  17. petName = ""
  18. petResponses = {" looks quizically at you..."," starts hopping around!"," smiles slyly."," looks suspiciously at you.."," runs around really fast."," looks shocked!"," is not sure what to say.."," looks hungry. Uh..."," turns away dramatically!"," whispers a secret in your ear!"," stares blankly back."," considers what you said.."," doesn't reply."," yawns in response."," doesn't like the tone of your voice!"," smiles eagerly!"," paws at you playfully."," puts their paw on your shoulder and looks worried."," looks proud!"," electric shocks you!"," regrets what has been done..."," seems to beckon for you."," stares at you ominously."," whistles a cute tune!"," teaches you a trick!"," tells you you're their favorite!"," wonders what you're thinking about..."," cannot possibly consider that!"," spins in a circle!"," doesn't wish to reply at this time"," looks wistfully out the window."," shouts at the top of their lungs!"," rolls over."," just sits there and looks cute."," contemplates life."," wags their tail!"," whimpers in response."," rolls their eyes."," frowns thoughtfully."," giggles at what you said!"," laughs heartily!"," understands what you mean."," replies insightfully."," copies what you said!"," looks like they want to be petted!"," agrees wholeheartedly!"," disagrees somewhat..."}
  19. chat = {""}
  20. chatCount = 0
  21. defaultColor = 0
  22. removePetInfo = false
  23. sleep = false
  24. timing = {}
  25. actions = {clearPet = false}
  26. grow  = 0
  27. poop = false
  28.  
  29. system.bindMouse(username)
  30.  
  31. Tamagotchis = {
  32. [1] = { -- Egg
  33. X = {365, 375, 385, 395, 405, 415, 355, 345, 425, 425, 335, 335, 435, 435, 435, 435, 325, 325, 325, 325, 335, 345, 425, 415, 355, 365, 375, 385, 395, 405, 405, 395, 385, 375, 375, 365, 365, 355, 355, 345, 335, 415, 405, 385, 395, 375, 365, 355, 345, 335, 425, 415, 405, 425, 415, 405, 395, 405, 395, 385, 395, 385, 375, 385, 375, 365};
  34. Y = {145, 145, 145, 145, 155, 165, 155, 165, 175, 185, 175, 185, 195, 205, 215, 225, 195, 205, 215, 225, 235, 245, 235, 245, 255, 255, 255, 255, 255, 255, 165, 165, 165, 165, 175, 175, 185, 185, 195, 195, 205, 175, 175, 175, 175, 185, 195, 205, 205, 215, 205, 205, 205, 215, 215, 215, 215, 225, 225, 225, 235, 235, 235, 245, 245, 245};
  35. body = {type = 12, color = 0x6B6B6B}
  36. };
  37.  
  38. [2] = {
  39. X = {365, 395, 355, 405, 395, 385, 375, 365, 355, 355, 405, 405, 395, 385, 375, 365, 375, 385, 345, 355, 365, 415, 405, 395, 345, 355, 365, 375, 385, 395, 405, 415};
  40. Y = {145, 145, 155, 155, 155, 155, 155, 155, 165, 175, 165, 175, 175, 175, 175, 175, 165, 165, 185, 185, 185, 185, 185, 185, 195, 195, 195, 195, 195, 195, 195, 195};
  41. body = {type = 12, color = 0x404199};
  42. name = "Bubbly"
  43. };
  44.  
  45. [2.1] = {
  46. X = {305, 315, 325, 335, 345, 355, 365, 295, 305, 375, 365, 355, 315, 315, 305, 295, 295, 295, 305, 315, 325, 335, 375, 345, 345, 345, 345, 385, 395, 405, 415, 425, 435, 435, 435, 445, 445, 435, 425, 415, 425, 445, 445, 435, 425, 415, 405, 395, 385, 375, 365, 355, 345, 335, 325, 315, 305, 295, 295, 405, 395, 385, 375, 365, 355, 375, 375, 415, 415};
  47. Y = {135, 135, 135, 145, 135, 135, 135, 145, 155, 145, 155, 165, 165, 175, 185, 195, 205, 215, 225, 225, 215, 215, 155, 175, 185, 195, 205, 155, 155, 155, 155, 165, 175, 185, 195, 205, 215, 225, 225, 225, 235, 235, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 235, 215, 225, 225, 225, 215, 235, 185, 195, 185, 195};
  48. body = {type = 12, color = 0x404199};
  49. name = "Dewgeel"
  50. };
  51.  
  52. [3] = {
  53. X = {365, 375, 385, 395, 355, 355, 355, 375, 375, 365, 395, 395, 385, 365, 365, 385, 375, 385, 395, 395, 405, 405, 405, 415, 405, 415, 425};
  54. Y = {155, 155, 155, 155, 165, 175, 185, 165, 175, 175, 165, 175, 175, 185, 195, 185, 195, 195, 185, 195, 165, 175, 185, 185, 195, 195, 195};
  55. body = {type = 12, color = 0x1F8F38};
  56. name = "Squirm"
  57. };
  58.  
  59. [3.1] = {
  60. X = {315, 325, 335, 345, 355, 365, 365, 365, 305, 305, 305, 335, 335, 355, 355, 325, 325, 375, 385, 385, 385, 375, 365, 365, 375, 355, 375, 365, 355, 345, 335, 335, 325, 315, 305, 295, 285, 275, 295, 295, 285, 275, 275, 265, 255, 255, 255, 245, 245, 245, 285, 275, 265, 255, 375, 365, 355, 335, 345, 325, 315, 315, 315, 325};
  61. Y = {105, 105, 115, 105, 105, 115, 125, 135, 115, 125, 135, 125, 135, 135, 145, 135, 145, 145, 155, 165, 175, 185, 195, 205, 215, 215, 225, 225, 225, 215, 215, 225, 225, 225, 225, 215, 205, 205, 135, 145, 145, 155, 165, 165, 175, 185, 195, 205, 215, 225, 225, 225, 225, 225, 175, 175, 175, 175, 175, 175, 185, 195, 205, 205};
  62. body = {type = 12, color = 0x1F8F38};
  63. name = "Froaklet"
  64. };
  65.  
  66. [4] = {
  67. X = {335, 345, 355, 325, 335, 345, 365, 375, 385, 375, 365, 355, 345, 355, 365, 375, 385, 385, 335, 335, 345, 355, 365, 375, 345, 365};
  68. Y ={165, 165, 175, 175, 185, 185, 165, 165, 175, 185, 185, 195, 205, 205, 205, 205, 215, 225, 215, 225, 225, 225, 225, 225, 215, 215};
  69. body = {type = 12, color = 0xAFA800};
  70. name = "Sprout"
  71. };
  72.  
  73. [4.1] = {
  74. X = {345, 335, 355, 365, 375, 385, 395, 405, 325, 315, 305, 295, 285, 285, 285, 405, 405, 295, 305, 315, 325, 325, 315, 375, 365, 365, 375, 385, 395, 395, 385, 295, 305, 355, 355, 335, 335, 355, 335, 365, 375, 325, 315, 335, 345, 355, 385, 305, 395, 395, 395, 395, 395, 295, 295, 295, 295, 295, 305, 385, 405, 405, 285, 285, 325, 325, 375, 375, 355, 395, 385, 375, 375, 365, 365, 355, 345, 335, 335, 325, 315, 305, 295};
  75. Y = {125, 125, 125, 115, 115, 125, 125, 115, 115, 115, 125, 125, 115, 125, 135, 125, 135, 135, 135, 135, 135, 125, 125, 125, 125, 135, 135, 135, 135, 145, 145, 145, 145, 135, 145, 135, 145, 155, 155, 165, 165, 165, 165, 175, 175, 175, 175, 175, 185, 195, 205, 215, 225, 185, 195, 205, 215, 225, 225, 225, 235, 245, 235, 245, 195, 205, 195, 205, 215, 245, 245, 235, 245, 245, 235, 235, 235, 235, 245, 245, 245, 245, 245};
  76. body = {type = 12, color = 0xAFA800};
  77. name = "Leafer"
  78. };
  79.  
  80. [5] = {
  81. X = {355, 365, 375, 385, 395, 395, 395, 395, 395, 385, 375, 375, 365, 365, 355, 345, 345, 345, 345, 345, 385, 375, 375, 365, 355, 365, 355, 365, 375, 385};
  82. Y = {135, 135, 135, 135, 145, 155, 165, 175, 185, 175, 175, 185, 185, 175, 175, 175, 185, 145, 155, 165, 155, 155, 145, 145, 145, 155, 165, 165, 165, 165};
  83. body = {type = 12, color = 0x000642};
  84. name = "Glob"
  85. };
  86.  
  87. [5.1] = {
  88. X = {315, 325, 335, 345, 355, 365, 375, 305, 295, 285, 285, 385, 395, 405, 405, 395, 385, 375, 375, 365, 355, 345, 335, 325, 315, 355, 335, 305, 295, 275, 275, 295, 285, 295, 265, 265, 265, 275, 285, 295, 305, 315, 325, 315, 325, 335, 345, 355, 345, 385, 375, 375, 365, 355, 385, 395, 405, 405, 395, 385, 375, 365, 385, 375, 365, 355, 345, 335, 325, 315, 305, 325, 315, 315, 305, 305, 315, 325, 335, 335, 345, 345, 345, 335, 355, 355, 365, 365, 375};
  89. Y = {125, 125, 125, 125, 125, 125, 125, 135, 145, 155, 165, 135, 135, 145, 155, 155, 155, 155, 145, 155, 155, 155, 155, 155, 155, 145, 145, 165, 175, 175, 185, 185, 195, 195, 185, 195, 205, 215, 215, 225, 225, 215, 205, 225, 225, 225, 225, 205, 215, 205, 215, 225, 225, 225, 225, 215, 205, 195, 195, 185, 175, 165, 195, 195, 195, 195, 195, 195, 195, 195, 195, 165, 165, 175, 175, 185, 185, 175, 175, 165, 165, 175, 185, 185, 165, 175, 175, 185, 185};
  90. body = {type = 12, color = 0x000642};
  91. name = "Clamshul"
  92. }}
  93.  
  94. objects = {
  95. [1] = { -- poop
  96. X = {535, 535, 535, 545, 555, 545, 525, 525, 535, 545, 525, 515, 515, 555, 555, 555, 565, 565, 555, 555, 515, 515, 505, 505, 515, 515};
  97. Y = {215, 205, 195, 205, 215, 215, 205, 215, 225, 225, 225, 215, 225, 225, 175, 165, 155, 145, 135, 125, 165, 155, 145, 135, 125, 115};
  98. body = {type = 12, color = 0x231000}
  99. };
  100.  
  101. [2] = { -- sleep
  102. X = {525, 535, 545, 555, 565, 555, 545, 535, 525, 535, 545, 555, 565, 495, 505, 515, 515, 505, 495, 505, 515};
  103. Y = {65, 65, 65, 65, 65, 75, 85, 95, 105, 105, 105, 105, 105, 125, 125, 125, 135, 145, 155, 155, 155};
  104. body = {type = 12, color = 0xB4B4B4}
  105. }}
  106.  
  107. function getResponse(player,answer)
  108.     table.insert(chat,1,string.format("%s<V>%s said:<N> %s\n",chat[1],player,answer))
  109.     message = petResponses[math.random(#petResponses)]
  110.     message = string.format("<V>%s<N>%s",petName,message)
  111.     table.insert(chat,1,chat[1]..message.."\n")
  112.     ui.addTextArea(2, "<P align ='center'> <font face='Soopafresh'> CHAT!</font> <P align ='left'> \n"..chat[1], nil, 590, 77, 200, nil, 0x324650, 0x000000, 1);
  113.     chatCount = chatCount +1
  114.     if player ~= "INFO" then
  115.         setPetInfo("mood",-5)
  116.     elseif chatCount == 8 then
  117.         chat = {""}
  118.         chatCound = 0
  119.     end
  120. end
  121.  
  122. function selectType(player)
  123. clearPath()
  124. if level == 1 then level = level+math.random(1,4) end
  125. petname = Tamagotchis[level].name
  126.  
  127. if level == 2 or 3 or 4 or 5 then
  128. ui.addPopup(1, 2, string.format("A %s just hatched from the egg! \nWhat would you like to name your new %s?",petname,petname),player,300,200,200,200,true)
  129. timing = {poop = os.time(), sleep = os.time(), growUp = os.time(), delay = os.time()}
  130. end
  131. end
  132.  
  133. function sendUI()
  134. ui.addTextArea(1, string.format("<P align='center'>| <A href ='event:Pokepet'>Poke</A> | <A href ='event:TalkWithPet'>Say something </A>| <A href ='event:releasePet'>Release pet</A> | <A href ='event:actions'>Actions</A> | <A href ='event:petInfo'>%s info</A> |",petName), nil, 5, 20, 790, nil, 0x324650, 0x000000, 1);
  135. end
  136.  
  137.  
  138. function setPetInfo(info,number)
  139.     if petInfo[info] <= 100 and petInfo[info] > 0 then
  140.         petInfo[info] = petInfo[info]-number
  141.     end
  142.     if petInfo[info] > 100 then petInfo[info] = 100 end
  143. end
  144.  
  145. function eventTextAreaCallback(id, player, callback)
  146. ui.removeTextArea(4)
  147. if callback == "TalkWithPet" then
  148.     ui.addPopup(2, 2, string.format("%s, talk with %s!",player,petName),player,300,200,200,200,true)
  149.  
  150. elseif callback == "Pokepet" then
  151.     mood = {0xAE0300,0x313DB6}
  152.     ID = math.random(#mood)
  153.     defaultColor = Tamagotchis[level].body.color
  154.     Tamagotchis[level].body.color = mood[ID]
  155.  
  156.     if ID == 1 then setPetInfo("mood",10) end
  157.         drawTamagotchi(Tamagotchis[level])
  158.         Tamagotchis[level].body.color = defaultColor
  159.  
  160. elseif callback == "releasePet" then
  161.     ui.addPopup(3, 1, string.format("Do you want to release %s? %s will live freely in the wild for the rest of their years! Are you sure you want to release %s?",petName,petName,petName),player,300,200,200,nil,true)
  162.  
  163. elseif callback == "actions" then
  164.     ui.addTextArea(4, "<P align='center'><font face='Soopafresh'>Actions</font>\n<A href='event:clearPet'>Clear Tamagotchi!</A>\n-------------------\n<A href='event:petSleep'>Time to bed!</A>\n-------------------\n<A href='event:petFood'>Feed Tamagotchi!</A>", player, 7, 128, 100, nil, 0x324650, 0x000001, 1);
  165.  
  166. elseif callback == "clearPet" and sleep == false then
  167.     actions.clearPet = true
  168.  
  169. elseif callback == "petFood" and sleep == false then
  170.     setPetInfo("hungry",-20)
  171.    
  172. elseif callback == "petSleep" and poop == false then
  173.     sleep = true
  174.     timing.sleep = os.time()
  175.     drawObject(objects[2])
  176.  
  177. elseif callback == "petInfo" then
  178.     ui.addTextArea(3, string.format("<P align='center'><font face='Soopafresh'>Pet Info!</font><P aling='left'>\n• Happy: %s\n• Sleep: %s \n• Food: %s",petInfo.mood.."%", petInfo.hungry.."%", petInfo.sleep.."%"), nil, 7, 128, 100, nil, 0x324650, 0x000001, 1);
  179.     removePetInfo = true
  180. end
  181. end
  182.  
  183.  
  184.  
  185. function eventPopupAnswer(id,player,answer)
  186. if id == 1 then
  187.     petName = answer
  188.     sendUI()
  189.  
  190. elseif id == 2 then
  191.     getResponse(player,answer)
  192.  
  193. elseif id == 3 then
  194.     if answer == "yes" then
  195.         ui.addPopup(4, 0, string.format("Goodbye forever %s! %s has gone off to forest with other %s!",petName,petName,Tamagotchis[level].name),player,300,200,200,nil,true)
  196.         newTamagotchi()
  197.     end
  198. end
  199. end
  200.  
  201. function eventMouse(player,pX,pY)
  202.     if pX > 100 and pX < 400 and pY > 100 and pY < 300 then
  203.         if level == 1 then
  204.             tfm.exec.displayParticle(5,pX,pY,math.random(-5,5),math.random(-5,5),0,0)
  205.             clickToHatch = clickToHatch+1
  206.             if clickToHatch == 20 then
  207.                 selectType(player)
  208.                 clickToHatch = 0
  209.             end
  210.            
  211.         elseif actions.clearPet == true then
  212.             for x = 4,1,-1 do tfm.exec.displayParticle(3,pX,pY,math.random(-5,5),math.random(-5,5),0,0) end
  213.             clickToClear = clickToClear+1
  214.             if clickToClear == 20 then
  215.                 clickToClear = 0
  216.                 clearObject()
  217.                 timing.poop = os.time()
  218.                 poop = false
  219.                 actions.clearPet = false
  220.             end
  221.         end
  222.     end
  223. end
  224.  
  225. function eventNewPlayer(player)
  226.     sendUI()
  227. end
  228.  
  229. function drawTamagotchi(pet)
  230. pos = math.random(-10,10)
  231.         for id = #pet.X,1,-1 do
  232.             tfm.exec.addPhysicObject(id, pet.X[id]+pos, pet.Y[id], pet.body)
  233.         end
  234. end
  235.  
  236. function drawObject(obj)
  237.     for id = #obj.X,1,-1 do
  238.         tfm.exec.addPhysicObject(id*100, obj.X[id], obj.Y[id], obj.body)
  239.     end
  240. end
  241.  
  242. function clearPath()
  243.     for id = 300,1,-1 do
  244.         tfm.exec.removePhysicObject(id)
  245.         ui.removeTextArea(id)
  246.     end
  247. end
  248.  
  249. function clearObject()
  250.     for id = 300,1,-1 do
  251.         tfm.exec.removePhysicObject(id*100)
  252.     end
  253. end
  254.  
  255. function growPet()
  256.     grow = grow+1
  257. if grow <= 1 then
  258.         level = level+0.1
  259.         ui.addPopup(4, 0, string.format("<P align='center'>%s is beginning to change! \n...\n......\n..........\n%s evolved into %s!",petName,petName,Tamagotchis[level].name),nil,300,200,200,nil,true)
  260.         timing.growUp = os.time()
  261. else
  262.         setBaby()
  263. end
  264. end
  265.  
  266. function setBaby()
  267. ui.addPopup(4, 0, string.format("<P align='center'>%s has had a good life. But it's time for them to pass on. \n...\n......\n..........\n%s has changed back into an egg!",petName,petName),nil,300,200,200,nil,true)
  268. newTamagotchi()
  269. end
  270.  
  271. function eventLoop()
  272. if moveTime < os.time()-5000 then
  273.     drawTamagotchi(Tamagotchis[level])
  274.     moveTime = os.time()
  275.     if removePetInfo == true then ui.removeTextArea(3) end
  276.    
  277. elseif level > 1 then
  278.     if timing.poop < os.time()-120000 and poop == false then
  279.         drawObject(objects[1])
  280.         poop = true
  281.         timing.poop = os.time()
  282.        
  283.     elseif timing.sleep < os.time()-30000 and sleep == true then
  284.         sleep = false
  285.         clearObject()
  286.         print("<N>Hey! you pet is now awake!")
  287.         setPetInfo("sleep",25)
  288.        
  289.     elseif timing.delay < os.time()-8000 then
  290.         timing.delay = os.time()
  291.         for info,id in pairs(petInfo) do
  292.             setPetInfo(info,math.random(-10,10))
  293.         end
  294.        
  295.     elseif timing.growUp < os.time()-300000 then
  296.         growPet()
  297.     end
  298. end
  299. end
  300.  
  301. function newTamagotchi()
  302. clearPath()
  303. clearObject()
  304. level = 1
  305. grow = 0
  306. sleep = false
  307. drawTamagotchi(Tamagotchis[level])
  308. chat = {""}
  309. print("<N>Hey! This is an egg! Why don't you try click on it?")
  310. end
  311.  
  312. newTamagotchi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement