Advertisement
Dudugz-Contistente

Untitled

Mar 12th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. self={}
  2. data={}
  3.  
  4. -- id,nome,preço;id2,nome2,preço2;id3,nome3,preço3;
  5. self.shopList="1,Power 1,10;2,Power 2,20;3,Power 3,50;"
  6.  
  7. function split(t,s)
  8. local a={}
  9. for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
  10. table.insert(a,i)
  11. end
  12. return a
  13. end
  14.  
  15. textarea=ui.addTextArea
  16. function ui.addTextArea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss,black_marcation,ground_marcation)
  17. --if not backgroundColor then backgroundColor=0x324650 end
  18. --if not borderColor then borderColor=0x000001 end
  19. if black_marcation then
  20. textarea(6969+id,"",targetPlayer,x,y+1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
  21. end
  22.  
  23. if ground_marcation then
  24. textarea(7979+id,"",targetPlayer,x,y-1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
  25. end
  26. textarea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss)
  27. end
  28.  
  29. self.ParseData = function(Opcode1,Opcode2,values)
  30. local values = split(values, ",")
  31.  
  32. if Opcode1 == "\x01" then -- Loja
  33. if Opcode2 == "\x01" then -- Janela
  34. name = values[1]
  35. money = values[2]
  36.  
  37. local shopList = split(self.shopList, ";")
  38.  
  39. ui.addTextArea(1,"",name,150,75,500,300,nil,0x324650,nil,true,true)
  40. ui.addTextArea(2,"<p align='center'><J><font size='15'><B>Loja",name,150,77,500,22,nil,0x324645,nil,true,true)
  41. ui.addTextArea(3,"<font size='13'><p align='center'><R><B><a href='event:close'>Fechar</a>",name,152,352,496,20,0x1a2b30,0x1a2b30,nil,true,true)
  42. ui.addTextArea(4,"<p align='center'><J><font size='12'><B><VP>"..money,name,542,318,100,22,nil,0x324645,nil,true,true)
  43.  
  44. x=82
  45. y=112
  46.  
  47. for i,v in pairs(shopList) do
  48. x = x+70
  49. item = {}
  50. item.info = split(v, ",")
  51.  
  52. ui.addTextArea(1000+item.info[1],item.info[2],name,x,y,55,60,0x0b161c,0x0b161c,nil,true)
  53. ui.addTextArea(2000+item.info[1],"<p align='center'><B><V><a href='event:buy,"..i.."'>"..item.info[3].."$</a>",name,x+1,y+45,55-2,16,0x38516b,0x38516b,nil,true,true,true,true)
  54. end
  55.  
  56. elseif Opcode2 == "\x02" then -- Comprar
  57. name = values[1]
  58. id = values[2]
  59.  
  60. player = data[name]
  61.  
  62. local shopList = split(self.shopList, ";")
  63.  
  64. for i,v in pairs(shopList) do
  65. item={}
  66. item.info = split(v, ",")
  67.  
  68. if item.info[1] == id then
  69. price = item.info[3]
  70. break
  71. end
  72. end
  73.  
  74. if price ~= nil then
  75. if player.shopCoins >= price then
  76. self.sendMessage("",name)
  77. else
  78. self.sendMessage("Você precisa de "..(item.info[3]-player.shopCoins).." moedas para comprar <B>'"..item.info[2].."</B>.'",name)
  79. end
  80. end
  81. end
  82. end
  83. end
  84.  
  85. self.sendMessage = function(message,name)
  86. if tfm.get.room.name:byte(2) == 3 then
  87. ui.addTextArea(8000,message,name,230,100,340,200,0x324650,0x324650,nil,true,true,true,true)
  88. else
  89. tfm.exec.chatMessage(message,name)
  90. end
  91. end
  92.  
  93. self.ParseCommands = function(id,name,command)
  94. if command:find("buy") then
  95. local values = split(command, ",")
  96. self.ParseData("\x01","\x02",name..","..values[2])
  97. end
  98. end
  99.  
  100. eventTextAreaCallback = self.ParseCommands
  101.  
  102. function eventNewPlayer(name)
  103. data[name]={
  104. shopCoins = 0
  105. }
  106. self.ParseData("\x01","\x01",name..","..data[name].shopCoins)
  107. end
  108.  
  109. for all in pairs(tfm.get.room.playerList) do
  110. eventNewPlayer(all)
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement