Bolodefchoco_LUAXML

[Script] Farm (Alpha)

Feb 12th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.17 KB | None | 0 0
  1. --Bolodefchoco
  2. --2016
  3.  
  4. data = {
  5.     formats = {
  6.         plants = "<N>Level required <G>: <VP>%s\n<N>Type <G>: <VP>%s\n\n<N>Harvest Time <G>: <VP>%s\n\n<N>Price <G>: <VP>$%s\n<N>Resale <G>: <VP>$%s",
  7.         items = "<N>Level required <G>: <VP>%s\n<N>Type <G>: <VP>%s\n\n<N>Uses <G>: <VP>%s\n<N>Health <G>: <VP>-%s\n\n<N>Price <G>: <VP>$%s",
  8.         expansions = "<N>Level required <G>: <VP>%s\n\n<N>Size <G>: <VP>+%spx\n<N>Gaps <G>: <VP>+%s\n\n<N>Price <G>: <VP>$%s",
  9.     },
  10.     types = {"Flowers","Fruits","Vegetables","Water pots","Rakes","Pesticides","Fertilizers","Bugs"},
  11.     plants = {
  12.         [1] = {
  13.             --[[ Name ]] [1] = "Banana",
  14.             --[[ Level ]] [2] = 25,
  15.             --[[ Type ]] [3] = 2,
  16.             --[[ Harvest Time ]] [4] = 4500,
  17.             --[[ Price ]] [5] = 10,
  18.             --[[ Resale ]] [6] = 15,
  19.             --[[ Image ]] [7] = {"",400,60},
  20.         },
  21.         [2] = {
  22.             [1] = "Grape",
  23.             [2] = 35,
  24.             [3] = 2,
  25.             [4] = 1000,
  26.             [5] = 15,
  27.             [6] = 18,
  28.             [7] = {"",400,60},
  29.         },
  30.     },
  31.     items = {
  32.         [1] = {
  33.             --[[ Name ]] [1] = "Simple hoe",
  34.             --[[ Level ]] [2] = 2,
  35.             --[[ Type ]] [3] = 5,
  36.             --[[ Uses ]] [4] = "Infinity",
  37.             --[[ Health ]] [5] = 0,
  38.             --[[ Price ]] [6] = 10,
  39.             --[[ Image ]] [7] = {"",400,60},
  40.         },
  41.         [2] = {
  42.             [1] = "Toxic Pesticide",
  43.             [2] = 5,
  44.             [3] = 6,
  45.             [4] = 2,
  46.             [5] = 5,
  47.             [6] = 8,
  48.             [7] = {"",400,60},
  49.         },
  50.     },
  51.     expansions = {
  52.         [1] = {
  53.             --[[ Name ]] [1] = "Full size",
  54.             --[[ Level ]] [2] = 35,
  55.             --[[ Size ]] [3] = 800,
  56.             --[[ Gaps ]] [4] = 6,
  57.             --[[ Price ]] [5] = 80,
  58.             --[[ Images ]] [7] = {"",400,60},
  59.         },
  60.     },
  61. }
  62. mice={}
  63. eventNewPlayer=function(n)
  64.     if not mice[n] then
  65.         mice[n] = {
  66.             plants = {
  67.                 [1] = {"id","quantity","health"},
  68.             },
  69.             area = 800, -- u can buy + space
  70.             planted = {
  71.                 [1] = {"id","speed","health","position"},
  72.             }, -- Plants planteds
  73.             coins = 25,
  74.             water = 5, -- Grow up faster
  75.             fertilizer = 3, -- Grow up faster x2
  76.             hoe = 10, -- Clean an already used gap/earth
  77.             pesticide = 0, -- Removes 50% of health but removes the bugs
  78.             ladybug = 0, -- + expensive than pesticide, remove bugs, but keep healthy
  79.             level = 0,
  80.             sold = 0,
  81.             shop_page = 1,
  82.             shop_cat = "plants",
  83.             image = "",
  84.         }
  85.     end
  86.     system.bindMouse(n,true)
  87.     system.bindKeyboard(n,79,true,true) -- O
  88. end
  89. table.foreach(tfm.get.room.playerList,eventNewPlayer)
  90.  
  91. getTime=function(time)
  92.     if type(time)~="number" then return "?" end
  93.     local second = time%60
  94.     local minutes = time/60
  95.     local minute = minutes%60
  96.     local hours = minutes/60
  97.     local hour = hours%24
  98.     local day = hours/24
  99.     return ("%dd %dh %dm %ds"):format(day,hour,minute,second)
  100. end
  101.  
  102. ui.shop=function(n)
  103.     tfm.exec.removeImage(mice[n].image)
  104.     local where = data[mice[n].shop_cat][mice[n].shop_page]
  105.     local formats = mice[n].shop_cat == "plants" and {where[2],where[3],getTime(where[4]),where[5],where[6]} or mice[n].shop_cat == "items" and {where[2],where[3],where[4],where[5],where[6]} or {where[2],where[3],where[4],where[5]}
  106.     mice[n].image = tfm.exec.addImage(where[7][1],"!0",where[7][2],where[7][3],n)
  107.     ui.addTextArea(0,"",n,155,45,490,330,0xDAFF,0xDAFF,1,true)
  108.     ui.addTextArea(1,"",n,157,47,486,326,0x223040,0x223040,1,true)
  109.     ui.addTextArea(2,"",n,160,50,480,320,0x1a2433,0x1a2433,1,true)
  110.     ui.addTextArea(3,"",n,430,60,200,300,0x213147,0x213147,1,true)--Image
  111.     ui.addTextArea(4,"<font size='13' letterSpacing='1'>"..data.formats[mice[n].shop_cat]:format(table.unpack(formats)),n,172,200,240,123,0x213147,0x213147,1,true)
  112.     ui.addTextArea(5,"<p align='center'><B><BV><a href='event:close_shop'>Close</a>",n,170,340,240,20,0x213147,0x213147,1,true)
  113.     ui.addTextArea(6,("<p align='center'><font size='12'><B><a href='event:shop_left'><BV>&lt;&lt;</BV></a>      <font size='15'>%s</font>      <a href='event:shop_right'><BV>&gt;&gt;</BV></a>"):format(where[1]),n,170,87,240,25,0x213147,0x213147,1,true)
  114.     ui.addTextArea(7,("<font size='12'><N>Coins <G>: <V>$%s\n<N>Area <G>: <V>%spx\n<N>Level <G>: <V>%s"):format(mice[n].coins,mice[n].area,mice[n].level),n,170,130,240,52,0x213147,0x213147,1,true)
  115.     ui.addTextArea(8,"",n,171,56,240,15,0x334b6c,0x334b6c,1,true)
  116.     ui.addTextArea(9,("<p align='center'><font size='13'>%s<a href='event:plants'>Plants</a> <BL>- %s<a href='event:items'>Items</a> <BL>- %s<a href='event:expansions'>Expansions"):format(mice[n].shop_cat=="plants" and "<J>" or "<N>",mice[n].shop_cat=="items" and "<J>" or "<N>",mice[n].shop_cat=="expansions" and "<J>" or "<N>"),n,170,53,240,25,1,1,0,true)
  117. end
  118.  
  119. eventKeyboard=function(n,k)
  120.     if k == 79 then
  121.         ui.shop(n)
  122.     end
  123. end
  124.  
  125. eventTextAreaCallback=function(i,n,c)
  126.     local p = {};for v in c:gmatch("[^_]+") do p[#p+1]=v end
  127.     if p[1] == "close" then
  128.         if p[2] == "shop" then
  129.             tfm.exec.removeImage(mice[n].image)
  130.             mice[n].shop_cat = "plants"
  131.             mice[n].shop_page = 1
  132.             for i = 0,9 do
  133.                 ui.removeTextArea(i,n)
  134.             end
  135.         end
  136.     end
  137.     if p[1] == "plants" or p[1] == "items" or p[1] == "expansions" then
  138.         mice[n].shop_cat = p[1]
  139.         mice[n].shop_page = 1
  140.         ui.shop(n)
  141.     end
  142.     if p[1] == "shop" then
  143.         if p[2] == "left" or p[2] == "right" then
  144.             mice[n].shop_page = (p[2]=="left" and (mice[n].shop_page>1 and mice[n].shop_page-1 or #data[mice[n].shop_cat]) or (mice[n].shop_page<#data[mice[n].shop_cat] and mice[n].shop_page+1 or 1))
  145.             ui.shop(n)
  146.         end
  147.     end    
  148. end
Add Comment
Please, Sign In to add comment