Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self={}
- data={}
- -- id,nome,preço;id2,nome2,preço2;id3,nome3,preço3;
- self.shopList="1,Power 1,10;2,Power 2,20;3,Power 3,50;"
- function split(t,s)
- local a={}
- for i,v in string.gmatch(t,string.format("[^%s]+",s or "%s")) do
- table.insert(a,i)
- end
- return a
- end
- textarea=ui.addTextArea
- function ui.addTextArea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss,black_marcation,ground_marcation)
- --if not backgroundColor then backgroundColor=0x324650 end
- --if not borderColor then borderColor=0x000001 end
- if black_marcation then
- textarea(6969+id,"",targetPlayer,x,y+1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
- end
- if ground_marcation then
- textarea(7979+id,"",targetPlayer,x,y-1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
- end
- textarea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss)
- end
- self.ParseData = function(Opcode1,Opcode2,values)
- local values = split(values, ",")
- if Opcode1 == "\x01" then -- Loja
- if Opcode2 == "\x01" then -- Janela
- name = values[1]
- money = values[2]
- local shopList = split(self.shopList, ";")
- ui.addTextArea(1,"",name,150,75,500,300,nil,0x324650,nil,true,true)
- ui.addTextArea(2,"<p align='center'><J><font size='15'><B>Loja",name,150,77,500,22,nil,0x324645,nil,true,true)
- 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)
- ui.addTextArea(4,"<p align='center'><J><font size='12'><B><VP>"..money,name,542,318,100,22,nil,0x324645,nil,true,true)
- x=82
- y=112
- for i,v in pairs(shopList) do
- x = x+70
- item = {}
- item.info = split(v, ",")
- ui.addTextArea(1000+item.info[1],item.info[2],name,x,y,55,60,0x0b161c,0x0b161c,nil,true)
- 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)
- end
- elseif Opcode2 == "\x02" then -- Comprar
- name = values[1]
- id = values[2]
- player = data[name]
- local shopList = split(self.shopList, ";")
- for i,v in pairs(shopList) do
- item={}
- item.info = split(v, ",")
- if item.info[1] == id then
- price = item.info[3]
- break
- end
- end
- if price ~= nil then
- if player.shopCoins >= price then
- self.sendMessage("",name)
- else
- self.sendMessage("Você precisa de "..(item.info[3]-player.shopCoins).." moedas para comprar <B>'"..item.info[2].."</B>.'",name)
- end
- end
- end
- end
- end
- self.sendMessage = function(message,name)
- if tfm.get.room.name:byte(2) == 3 then
- ui.addTextArea(8000,message,name,230,100,340,200,0x324650,0x324650,nil,true,true,true,true)
- else
- tfm.exec.chatMessage(message,name)
- end
- end
- self.ParseCommands = function(id,name,command)
- if command:find("buy") then
- local values = split(command, ",")
- self.ParseData("\x01","\x02",name..","..values[2])
- end
- end
- eventTextAreaCallback = self.ParseCommands
- function eventNewPlayer(name)
- data[name]={
- shopCoins = 0
- }
- self.ParseData("\x01","\x01",name..","..data[name].shopCoins)
- end
- for all in pairs(tfm.get.room.playerList) do
- eventNewPlayer(all)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement