Advertisement
Dudugz-Contistente

Untitled

Aug 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 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. ['Coals']='15dfb388864.png',
  28. }
  29. }
  30.  
  31. tfm.exec.disableAutoTimeLeft()
  32. tfm.exec.disableAutoNewGame()
  33.  
  34. split=function(t,s)
  35. local a={}
  36. for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
  37. table.insert(a,i)
  38. end
  39. return a
  40. end
  41.  
  42. function eventNewGame()
  43. tfm.exec.snow(140, 10)
  44. tfm.exec.setGameTime(140)
  45.  
  46. xml = tfm.get.room.xmlMapInfo.xml
  47.  
  48. for p in string.gmatch(xml, '<P .-/>') do
  49. for plank in string.gmatch(xml, 'Planks=".-"') do
  50. plank=plank:gsub('Planks="',''):gsub('"','')
  51.  
  52. item=split(plank,",")
  53. items.plank.x=tonumber(item[1])
  54. items.plank.y=tonumber(item[2])
  55. end
  56. end
  57.  
  58. for p in string.gmatch(xml, '<P .-/>') do
  59. for ore in string.gmatch(xml, 'Ores=".-"') do
  60. ore=ore:gsub('Ores="',''):gsub('"','')
  61.  
  62. item=split(ore,",")
  63. items.ore.x=tonumber(item[1])
  64. items.ore.y=tonumber(item[2])
  65. end
  66. end
  67. end
  68.  
  69. function eventLoop(t,r)
  70. local ids={}
  71. for i,img in pairs(imagesToRemove) do
  72. if img.time < os.time()-img.timeTR then
  73. tfm.exec.removeImage(img.url)
  74. table.insert(ids,i)
  75. end
  76. end
  77.  
  78. for i,v in pairs(ids) do
  79. table.remove(imagesToRemove,v)
  80. end
  81.  
  82. ids={}
  83.  
  84. for name,v in pairs(tfm.get.room.playerList) do
  85. if not v.isDead then
  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,4)
  88. data[name].cold_time=math.random(0,2500)
  89. data[name].cold_timer=os.time();
  90. end
  91.  
  92. status(name)
  93. end
  94. end
  95. end
  96.  
  97. function status(name)
  98. if data[name].cold >= 100 then
  99. data[name].cold=100
  100. data[name].life=data[name].life-math.random(1,5)
  101. end
  102.  
  103. ui.addTextArea(0,"",name,8,375,100,12,0x1E90FF,0x1E90FF,nil,true)
  104. if data[name].cold >= 5 then
  105. ui.addTextArea(1,"",name,8,375,data[name].cold,12,0x00BFFF,0x00BFFF,nil,true)
  106. end
  107. ui.addTextArea(2,"Frio/Cold: "..data[name].cold.."%",name,8,372,100,16,0,0,0,true)
  108.  
  109. if data[name].life >= 100 then
  110. data[name].life=100
  111. elseif data[name].life <= 0 then
  112. data[name].life=0
  113. tfm.exec.killPlayer(name)
  114. end
  115.  
  116. ui.addTextArea(-1,"",name,8,350,100,12,0xCD0000,0xCD0000,nil,true)
  117. if data[name].life >= 5 then
  118. ui.addTextArea(-2,"",name,8,350,data[name].life,12,0xFF0000,0xFF0000,nil,true)
  119. end
  120. ui.addTextArea(-3,"Vida/Life: "..data[name].life.."%",name,8,347,100,16,0,0,0,true)
  121. end
  122. function eventKeyboard(name,key,down,x,y)
  123. if key == 9 then
  124. if not data[name].openInv then
  125. newPopup(6,"<a href='event:craft:open'><p align='center'>Workbench / Bancada de Trabalho</p></a>",name,200,260,345,20,0x1d3b40,0x1d3b40,nil,true)
  126. newPopup(7,"",name,200,40,345,200,0x1d3b40,0x1d3b40,nil,true)
  127. x=202
  128.  
  129. for i,item in pairs(data[name].inventory) do
  130. newPopup(7878+i,"",name,x,42,40,40,0x1d3b40,0x1d3b40,nil,true,true)
  131. ui.addTextArea(9898+i,"<font size='9' face='Arial'>"..tostring(item.count),name,x,70,40,20,0,0,0,true)
  132. id=tfm.exec.addImage (assets.items[item.name], "&1", x+5, 45, name)
  133. table.insert(data[name].imgs,id)
  134. x=x+55
  135. end
  136. data[name].openInv=true
  137. else
  138. for i=6,7 do
  139. ui.removeTextArea(i)ui.removeTextArea(6969+i)ui.removeTextArea(7979+i)
  140. end
  141.  
  142. for i=1,#data[name].inventory do
  143. ui.removeTextArea(7878+i)ui.removeTextArea(6969+(7878+i))ui.removeTextArea(7979+(7878+i))
  144. ui.removeTextArea(9898+i)
  145. end
  146.  
  147. for i,img in pairs(data[name].imgs) do
  148. tfm.exec.removeImage(img)
  149. end
  150. data[name].openInv=false
  151. end
  152. end
  153.  
  154. if key == 40 then
  155. if data[name].collect_time < os.time()-1500 then
  156. x=x-63
  157. y=y-38
  158. 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
  159. tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
  160. id=tfm.exec.addImage (assets.items['Planks'], "!1", 770, 365, name)
  161. table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=250})
  162. giveItem(name,{name="Planks",count=1})
  163. end
  164.  
  165. x=x+63-21
  166. 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
  167. tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
  168. local ores={"Stone","Coals","Stone","Stone","Stone","Stone"}
  169. local oreSelected = ores[math.random(#ores)]
  170.  
  171. id=tfm.exec.addImage (assets.items[oreSelected], "!1", 770, 365, name)
  172. table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=250})
  173. giveItem(name,{name=oreSelected,count=1})
  174. end
  175.  
  176. data[name].collect_time=os.time();
  177. end
  178. end
  179. end
  180.  
  181. function giveItem(name,dados)
  182. local newItem=true
  183.  
  184. for id,item in pairs(data[name].inventory) do
  185. if item.name==dados.name then
  186. item.count=item.count+dados.count
  187. newItem=false
  188. end
  189. end
  190.  
  191. if newItem then
  192. table.insert(data[name].inventory,dados)
  193. end
  194. end
  195.  
  196. function eventNewPlayer(name)
  197. data[name]={
  198. havePickaxe=true,
  199. openInv=false,
  200. cold=0,
  201. cold_time=0,
  202. cold_timer=0,
  203. inventory={
  204. {name="Stone",count=3}
  205. },
  206. collect_time=0,
  207. imgs={},
  208. life=100
  209. }
  210.  
  211. system.bindKeyboard(name,40,true)
  212. system.bindKeyboard(name,9,true)
  213. end
  214.  
  215. --function eventTextAreaCallback(id,name,link)
  216. -- if link == "buy:pickaxe" then
  217. -- if data[name].planks >= 6 then
  218. -- data[name].planks=data[name].planks-1
  219. -- data[name].havePickaxe=true
  220. -- end
  221. -- end
  222. --end
  223.  
  224. function eventChatCommand(name,cmd)
  225. if cmd == "r all" and name == "Contistente" then
  226. for all in pairs(tfm.get.room.playerList) do tfm.exec.respawnPlayer(all) end
  227. end
  228. end
  229.  
  230. for all in pairs(tfm.get.room.playerList) do eventNewPlayer(all) end
  231. tfm.exec.newGame('@7124314')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement