Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. newPopup=function(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss,invert)
  2. if not invert then
  3. ui.addTextArea(6969+id,"",targetPlayer,x,y+1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
  4. ui.addTextArea(7979+id,"",targetPlayer,x,y-1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
  5. else
  6. ui.addTextArea(6969+id,"",targetPlayer,x,y-1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
  7. ui.addTextArea(7979+id,"",targetPlayer,x,y+1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
  8. end
  9. ui.addTextArea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss)
  10. end
  11.  
  12. data={}
  13. items={
  14. plank={x=0,y=0},
  15. ore={x=0,y=0},
  16. }
  17.  
  18. imagesToRemove={}
  19.  
  20. assets={
  21. items={
  22. ['Planks']='15dedea314a.png',
  23. ['Pickaxe']='15dedeadd6a.png',
  24. ['Sword']='15dedeb0514.png',
  25. ['camp_fire']='15dedeb2fb4.png',
  26. ['Stone']='15dedeb7429.png',
  27. }
  28. }
  29.  
  30. tfm.exec.disableAutoTimeLeft()
  31. tfm.exec.disableAutoNewGame()
  32.  
  33. split=function(t,s)
  34. local a={}
  35. for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
  36. table.insert(a,i)
  37. end
  38. return a
  39. end
  40.  
  41. function eventNewGame()
  42. tfm.exec.snow(140, 10)
  43. tfm.exec.setGameTime(140)
  44.  
  45. xml = tfm.get.room.xmlMapInfo.xml
  46.  
  47. for p in string.gmatch(xml, '<P .-/>') do
  48. for plank in string.gmatch(xml, 'Planks=".-"') do
  49. plank=plank:gsub('Planks="',''):gsub('"','')
  50.  
  51. item=split(plank,",")
  52. items.plank.x=tonumber(item[1])
  53. items.plank.y=tonumber(item[2])
  54. end
  55. end
  56.  
  57. for p in string.gmatch(xml, '<P .-/>') do
  58. for ore in string.gmatch(xml, 'Ores=".-"') do
  59. ore=ore:gsub('Ores="',''):gsub('"','')
  60.  
  61. item=split(ore,",")
  62. items.ore.x=tonumber(item[1])
  63. items.ore.y=tonumber(item[2])
  64. end
  65. end
  66. end
  67.  
  68. function eventLoop(t,r)
  69. local ids={}
  70. for i,img in pairs(imagesToRemove) do
  71. if img.time < os.time()-img.timeTR then
  72. tfm.exec.removeImage(img.url)
  73. table.insert(ids,i)
  74. end
  75. end
  76.  
  77. for i,v in pairs(ids) do
  78. table.remove(imagesToRemove,v)
  79. end
  80.  
  81. ids={}
  82.  
  83. for name,v in pairs(tfm.get.room.playerList) do
  84. if not v.isDead then
  85. system.bindKeyboard(name,40,true)
  86. if data[name].cold_timer < os.time()-data[name].cold_time and t > 8000 then
  87. data[name].cold = data[name].cold+math.random(1,2)
  88. data[name].cold_time=math.random(0,3000)
  89. data[name].cold_timer=os.time();
  90. end
  91.  
  92. if data[name].cold >= 100 then
  93. data[name].cold=100
  94. tfm.exec.killPlayer(name)
  95. tfm.exec.addShamanObject (54, v.x, v.y, 2, 0, 0, true)
  96. end
  97.  
  98. ui.addTextArea(0,"",name,8,375,100,12,0x1E90FF,0x1E90FF,nil,true)
  99. if data[name].cold >= 5 then
  100. ui.addTextArea(1,"",name,8,375,data[name].cold,12,0x00BFFF,0x00BFFF,nil,true)
  101. end
  102. ui.addTextArea(2,"Frio/Cold: "..data[name].cold.."%",name,8,372,100,16,0,0,0,true)
  103. end
  104. end
  105. end
  106.  
  107. function eventKeyboard(name,key,down,x,y)
  108. if key == 9 then
  109. if not data[name].openCraft then
  110. newPopup(6,"",name,200,40,39,200,0x1d3b40,0x1d3b40,nil,true)
  111. newPopup(7,"",name,200,42,246,20,0x1d3b40,0x1d3b40,nil,true,true)
  112. data[name].openCraft=true
  113. else
  114. for i=6,7 do
  115. ui.removeTextArea(i)ui.removeTextArea(6969+i)ui.removeTextArea(7979+i)
  116. end
  117. data[name].openCraft=false
  118. end
  119. end
  120.  
  121. if key == 40 then
  122. if data[name].collect_time < os.time()-1200 then
  123. x=x-63
  124. y=y-38
  125. if x >= items.plank.x - 20 and x <= items.plank.x + 20 and y >= items.plank.y - 20 and y <= items.plank.y + 20 then
  126. tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
  127. id=tfm.exec.addImage (assets.items['Planks'], "!1", 770, 365, name)
  128. table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=200})
  129. giveItem(name,{name="Planks",count=1})
  130. end
  131.  
  132. x=x+63-21
  133. if x >= items.ore.x - 20 and x <= items.ore.x + 20 and y >= items.ore.y - 20 and y <= items.ore.y + 20 and data[name].havePickaxe then
  134. tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
  135. id=tfm.exec.addImage (assets.items[''], "!1", 770, 365, name)
  136. table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=200})
  137. giveItem(name,{name="Coals",count=1})
  138. end
  139.  
  140. data[name].collect_time=os.time();
  141. end
  142. end
  143. end
  144.  
  145. function giveItem(name,dados)
  146. local newItem=true
  147.  
  148. for id,item in pairs(data[name].inventory) do
  149. if item.name==dados.name then
  150. item.count=item.count+dados.count
  151. newItem=false
  152. end
  153. end
  154.  
  155. if newItem then
  156. table.insert(data[name].inventory,dados)
  157. end
  158. end
  159.  
  160. function eventNewPlayer(name)
  161. data[name]={
  162. havePickaxe=false,
  163. openCraft=false,
  164. cold=0,
  165. cold_time=0,
  166. cold_timer=0,
  167. inventory={
  168. {name="Stone",count=3}
  169. },
  170. collect_time=0
  171. }
  172. end
  173.  
  174. --function eventTextAreaCallback(id,name,link)
  175. -- if link == "buy:pickaxe" then
  176. -- if data[name].planks >= 6 then
  177. -- data[name].planks=data[name].planks-1
  178. -- data[name].havePickaxe=true
  179. -- end
  180. -- end
  181. --end
  182.  
  183. for all in pairs(tfm.get.room.playerList) do eventNewPlayer(all) end
  184. tfm.exec.newGame('@7124314')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement