Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- newPopup=function(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss,invert)
- if not invert then
- ui.addTextArea(6969+id,"",targetPlayer,x,y+1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
- ui.addTextArea(7979+id,"",targetPlayer,x,y-1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
- else
- ui.addTextArea(6969+id,"",targetPlayer,x,y-1,width,height,0x000001,0x000001,backgroundAlpha,emboss)
- ui.addTextArea(7979+id,"",targetPlayer,x,y+1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha,emboss)
- end
- ui.addTextArea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss)
- end
- data={}
- items={
- plank={x=0,y=0},
- ore={x=0,y=0},
- }
- imagesToRemove={}
- assets={
- items={
- ['Planks']='15dedea314a.png',
- ['Pickaxe']='15dedeadd6a.png',
- ['Sword']='15dedeb0514.png',
- ['camp_fire']='15dedeb2fb4.png',
- ['Stone']='15dedeb7429.png',
- ['Coals']='15dfb388864.png',
- }
- }
- tfm.exec.disableAutoTimeLeft()
- tfm.exec.disableAutoNewGame()
- split=function(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
- function eventNewGame()
- tfm.exec.snow(140, 10)
- tfm.exec.setGameTime(140)
- xml = tfm.get.room.xmlMapInfo.xml
- for p in string.gmatch(xml, '<P .-/>') do
- for plank in string.gmatch(xml, 'Planks=".-"') do
- plank=plank:gsub('Planks="',''):gsub('"','')
- item=split(plank,",")
- items.plank.x=tonumber(item[1])
- items.plank.y=tonumber(item[2])
- end
- end
- for p in string.gmatch(xml, '<P .-/>') do
- for ore in string.gmatch(xml, 'Ores=".-"') do
- ore=ore:gsub('Ores="',''):gsub('"','')
- item=split(ore,",")
- items.ore.x=tonumber(item[1])
- items.ore.y=tonumber(item[2])
- end
- end
- end
- function eventLoop(t,r)
- local ids={}
- for i,img in pairs(imagesToRemove) do
- if img.time < os.time()-img.timeTR then
- tfm.exec.removeImage(img.url)
- table.insert(ids,i)
- end
- end
- for i,v in pairs(ids) do
- table.remove(imagesToRemove,v)
- end
- ids={}
- for name,v in pairs(tfm.get.room.playerList) do
- if not v.isDead then
- if data[name].cold_timer < os.time()-data[name].cold_time and t > 8000 then
- data[name].cold = data[name].cold+math.random(1,4)
- data[name].cold_time=math.random(0,2500)
- data[name].cold_timer=os.time();
- end
- status(name)
- end
- end
- end
- function status(name)
- if data[name].cold >= 100 then
- data[name].cold=100
- data[name].life=data[name].life-math.random(1,5)
- end
- ui.addTextArea(0,"",name,8,375,100,12,0x1E90FF,0x1E90FF,nil,true)
- if data[name].cold >= 5 then
- ui.addTextArea(1,"",name,8,375,data[name].cold,12,0x00BFFF,0x00BFFF,nil,true)
- end
- ui.addTextArea(2,"Frio/Cold: "..data[name].cold.."%",name,8,372,100,16,0,0,0,true)
- if data[name].life >= 100 then
- data[name].life=100
- elseif data[name].life <= 0 then
- data[name].life=0
- tfm.exec.killPlayer(name)
- end
- ui.addTextArea(-1,"",name,8,350,100,12,0xCD0000,0xCD0000,nil,true)
- if data[name].life >= 5 then
- ui.addTextArea(-2,"",name,8,350,data[name].life,12,0xFF0000,0xFF0000,nil,true)
- end
- ui.addTextArea(-3,"Vida/Life: "..data[name].life.."%",name,8,347,100,16,0,0,0,true)
- end
- function eventKeyboard(name,key,down,x,y)
- if key == 9 then
- if not data[name].openInv then
- 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)
- newPopup(7,"",name,200,40,345,200,0x1d3b40,0x1d3b40,nil,true)
- x=202
- for i,item in pairs(data[name].inventory) do
- newPopup(7878+i,"",name,x,42,40,40,0x1d3b40,0x1d3b40,nil,true,true)
- ui.addTextArea(9898+i,"<font size='9' face='Arial'>"..tostring(item.count),name,x,70,40,20,0,0,0,true)
- id=tfm.exec.addImage (assets.items[item.name], "&1", x+5, 45, name)
- table.insert(data[name].imgs,id)
- x=x+55
- end
- data[name].openInv=true
- else
- for i=6,7 do
- ui.removeTextArea(i)ui.removeTextArea(6969+i)ui.removeTextArea(7979+i)
- end
- for i=1,#data[name].inventory do
- ui.removeTextArea(7878+i)ui.removeTextArea(6969+(7878+i))ui.removeTextArea(7979+(7878+i))
- ui.removeTextArea(9898+i)
- end
- for i,img in pairs(data[name].imgs) do
- tfm.exec.removeImage(img)
- end
- data[name].openInv=false
- end
- end
- if key == 40 then
- if data[name].collect_time < os.time()-1500 then
- x=x-63
- y=y-38
- 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
- tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
- id=tfm.exec.addImage (assets.items['Planks'], "!1", 770, 365, name)
- table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=250})
- giveItem(name,{name="Planks",count=1})
- end
- x=x+63-21
- 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
- tfm.exec.displayParticle (15, 750, 380, 0, 0, 0, 0, name)
- local ores={"Stone","Coals","Stone","Stone","Stone","Stone"}
- local oreSelected = ores[math.random(#ores)]
- id=tfm.exec.addImage (assets.items[oreSelected], "!1", 770, 365, name)
- table.insert(imagesToRemove,{time=os.time(),url=id,timeTR=250})
- giveItem(name,{name=oreSelected,count=1})
- end
- data[name].collect_time=os.time();
- end
- end
- end
- function giveItem(name,dados)
- local newItem=true
- for id,item in pairs(data[name].inventory) do
- if item.name==dados.name then
- item.count=item.count+dados.count
- newItem=false
- end
- end
- if newItem then
- table.insert(data[name].inventory,dados)
- end
- end
- function eventNewPlayer(name)
- data[name]={
- havePickaxe=true,
- openInv=false,
- cold=0,
- cold_time=0,
- cold_timer=0,
- inventory={
- {name="Stone",count=3}
- },
- collect_time=0,
- imgs={},
- life=100
- }
- system.bindKeyboard(name,40,true)
- system.bindKeyboard(name,9,true)
- end
- --function eventTextAreaCallback(id,name,link)
- -- if link == "buy:pickaxe" then
- -- if data[name].planks >= 6 then
- -- data[name].planks=data[name].planks-1
- -- data[name].havePickaxe=true
- -- end
- -- end
- --end
- function eventChatCommand(name,cmd)
- if cmd == "r all" and name == "Contistente" then
- for all in pairs(tfm.get.room.playerList) do tfm.exec.respawnPlayer(all) end
- end
- end
- for all in pairs(tfm.get.room.playerList) do eventNewPlayer(all) end
- tfm.exec.newGame('@7124314')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement