------------------------------------------------------------------------------ <- width of my notepad window -- BBBB Y Y JJJJJJJJJ A CCCC OOO BBBB 1 -- B B Y Y :: J A A C O O B B 11 -- B B Y :: J A A C O O B B 1 1 -- BBBB Y J AAAAAAA C O O BBBB 1 -- B B Y :: J A A C O O B B 1 -- B B Y :: J J A A C O O B B 1 -- BBBB Y JJ A A CCCC OOO BBBB 1111111 -- -- -- By: jacob1 -- -- Favorites menu lua script -- -- Adds a favorites menu above the wall menu that keeps track of your -- favorite and recently used elements -- Left click an element to select and draw with it, use '[' and ']' to -- change the size (not the mousewheel) -- Right click and element to add it to your favorites, permanently -- pinning it to the menu. Right click it again to deselect -- -- -- Other Features: -- -- Better HUD, with some extra info (doesn't have pressure) -- Find tool, will color the last drawn element red and dim everything else -- Easily activate 3 different custom functions of your own with buttons -- Moving Solids, very glitchy -- Decoration editor, drawn on deco like any other element, also edit alpha -- -- -- You may edit the following things as you like: -- The default elements in the favorites list elements = {"SPRK","PSCN","NSCN","DMND","FIRE","THDR","BOMB","SHD4","EQVE","PHOT","BRAY","LOLZ","MORT","RIME","FOG","LOVE","DYST","SPWN","MORE"} -- More isn't an element, its a menu option (Don't change it) -- starting draw radius radius = 5 -- controls when/how menus are drawn displaymenu = 1 maxoptions = 19 nummenus = 14 -- the password, change it to what you want (this is for people that don't know about autorun.lua, becuase this is easily removed) thepassword = "thepowdertoy" if false then -- change to true to do a password test local pass = tpt.input("password", "Enter the password or \"quit\" to quit") while pass ~= thepassword do if pass == "quit" then os.exit() end pass = tpt.input("password", "Wrong password, try again or \"quit\" to quit") end end function getname() return "jacob1" end tpt.get_name = getname ----------------------------------- -- Custom functions -- Edit them to do whatever you want ----------------------------------- function custom1() end function custom2() tpt.start_getPartIndex() while tpt.next_getPartIndex() do local index = tpt.getPartIndex() if tpt.get_property("ctype",index) == 21 then -- acid tpt.set_property("ctype","sing",index) end end end function custom3() end ---------------------------------------------------------------------------------------------------------------------- -- Do not edit anything past this point, unless you know what you are doing -- Feel free to use any of the functions in here, just give credit with --By jacob1 on the function name ---------------------------------------------------------------------------------------------------------------------- function setdebug(debugstuff) debuginfo = debugstuff debugset = true end function drawdebug() local debugcolor = 0 if debugset then debugcolor = 255 end tpt.drawtext(100,100,debuginfo,debugcolor,debugcolor,255,255) end ---------------------------------------------------------------------------------------------------------------------- -- Name Changing Functions -- Switches between numbers and element names, also availible in gol form ---------------------------------------------------------------------------------------------------------------------- -- List By Cr15py, edited By jacob1 particles = {"DUST","WATR","OIL","FIRE","STNE","LAVA","GUN","NITR","CLNE","GAS","C-4","GOO","ICE","METL","SPRK","SNOW","WOOD","NEUT","PLUT","PLNT","ACID","VOID","WTRV","CNCT","DSTW","SALT","SLTW","DMND","BMTL","BRMT","PHOT","URAN","WAX","MWAX","PSCN","NSCN","NITR","INSL","VACU","VENT","RBDM","LRBD","NTCT","SAND","GLAS","PTCT","BGLA","THDR","PLSM","ETRD","NICE","NBLE","BTRY","LCRY","STKM","SWCH","SMKE","DESL","COAL","LOXY","OXYG","INWR","YEST","DYST","THRM","GLOW","BRCK","CFLM","FIRW","FUSE","FSEP","AMTR","BCOL","PCLN","HSWC","IRON","MORT","GOL","DLAY","CO2","DRIC","BUBW","STOR","PVOD","CONV","CAUS","LIGH","TESC","DEST","SPNG","RIME","FOG","BCLN","LOVE","DEUT","WARP","PUMP","FWRK","PIPE","FRZZ","FRZW","GRAV","BIZR","BIZG","BIZS","INST","ISOZ","ISZS","PRTI","PRTO","PSTE","PSTS","ANAR","VINE","INVS","EQVE","SPWN2","SPWN","SHLD","SHD2","SHD3","SHD4","LOLZ","WIFI","FILT","ARAY","BRAY","STK2","BOMB","C-5","SING","QRTZ","PQRT","EMP","BREL","ELEC","ACEL","DCEL","TNT","IGNC","BOYL","GEL","TRON","TTAN","FROG","BRAN","EMBR","HYGN","SOAP","BHOL","WHOL","MERC","PBCN","GPMP","CLST","WIRE","GBMB","FIGH","FRAY","REPL"} function changetoname(el) -- changes element number to an element name if el == 0 then return "X" end local particle = particles[el] if particle == nil then return el else return particle end end function changetonum(el) for i = 1,159 do if el == particles[i] then return i end end return el end golparticles = {"GOL" ,"HLIF","ASIM","2X2" ,"DANI","AMOE","MOVE","PGOL","DMOE","34" ,"LLIF","STAN","SEED","MAZE","COAG","WALL","GNAR","REPL","MYST","LOTE","FRG2","STAR","FROG","BRAN"} function changetonamegol(el) return golparticles[el+1] end function changetonumgol(el) for i = 1,24 do if el == golparticles[i] then return 78+256*(i-1) end end return el end ---------------------------------------------------------------------------------------------------------------------- -- Element Creation -- Use to draw elements like tpt does, c is the element to draw TODO: Must be a number currently ---------------------------------------------------------------------------------------------------------------------- function create_line(x1,y1,x2,y2,rd,c) -- Taken From Powder Toy Source Code c = changetonumgol(c) c = changetonum(c) local cp = false if math.abs(y2-y1)>math.abs(x2-x1) then cp = true end local x = 0 local y = 0 local dx = 0 local dy = 0 local sy = 0 local e = 0.0 local de = 0.0 local first = true if cp then y = x1 x1 = y1 y1 = y y = x2 x2 = y2 y2 = y end if x1 > x2 then y = x1 x1 = x2 x2 = y y = y1 y1 = y2 y2 = y end dx = x2 - x1 dy = math.abs(y2 - y1) if dx ~= 0 then de = dy/dx end y = y1 if y1 < y2 then sy = 1 else sy = -1 end for x = x1, x2 do if cp then drawstuff(y,x,rd,c,first) else drawstuff(x,y,rd,c,first) end if rd > 2 then first = false -- Speed Up Drawing By Not Filling Whole Circle Every Time end e = e + de if e >= .5 then y = y + sy e = e - 1 if cp then drawstuff(y,x,rd,c,first) else drawstuff(x,y,rd,c,first) end end end end function createelement(x,y,c) -- Creates an element at a point, c must be a number, not a string (use c = changetonum(c) (or changetonumgol() for gol particles)) local clone = false local type = tpt.get_property("type",x,y) if type == 9 or type == 74 or type == 83 or type == 85 or type == 93 or type == 153 then clone = true end if c == -1 and tpt.get_property("type",x,y) ~= 0 then tpt.set_property("dcolour",drawcolor,x,y) elseif c == -2 and tpt.get_property("type",x,y) ~= 0 then tpt.set_property("dcolour",0,x,y) elseif c > 0 then if type == 0 or clone or c == 15 then if c%256 ~= 78 then if clone then tpt.set_property("ctype",c,x,y) else tpt.create(x, y, c) if c == 88 then local rd = radius*8 + 7 if rd == 7 then rd = 0 end if rd > 300 then rd = 300 end tpt.set_property("tmp",rd,x,y) end end else if clone then tpt.set_property("ctype",78,x,y) tpt.set_property("tmp",math.floor(c/256),x,y) else tpt.create(x, y, "life") tpt.set_property("ctype",math.floor(c/256),x,y) local tmp = 1 local gol = (c-78)/256 if gol == 20 or gol == 22 or gol == 23 then tmp = 2 elseif gol == 19 then tmp = 3 elseif gol == 21 then tmp = 5 end tpt.set_property("tmp",tmp,x,y) end end end elseif c == 0 then tpt.delete(x, y) end end function drawstuff(x,y,rd,c,fill) -- Draws or erases elements, c is the element local function valid(x,y) if x >= 0 and x < 612 and y >= 0 and y < 384 then return true end end local tempy = y local oldy = y for i = x - rd, x do oldy = tempy local distance = math.sqrt(math.pow((x-i),2) + math.pow((y-tempy),2)) while distance <= rd do tempy = tempy - 1 distance = math.sqrt(math.pow((x-i),2) + math.pow((y-tempy),2)) end tempy = tempy + 1 if fill then for j = tempy, y+y-tempy do if valid(i,j) then createelement(i,j,c) end if valid(x+x-i,j) then createelement(x+x-i,j,c) end end else if oldy ~= tempy then oldy = oldy - 1 end for j = tempy, oldy do if valid(i,j) then createelement(i,j,c) end if valid(x+x-i,j) then createelement(x+x-i,j,c) end if valid(i,y+y-j) then createelement(i,y+y-j,c) end if valid(x+x-i,y+y-j) then createelement(x+x-i,y+y-j,c) end end end end end function floodfill(x,y,c,b,n) -- By Mniip, Edited by jacob1 local function getpixel(x,y) if x > 3 and y > 3 and x < 608 and y < 380 then return tpt.get_property("type",x,y) end return -1 end if n == 0 then num = 0 end -- Doesn't work that well because of too much recursion if c ~= 0 then tpt.create(x,y,c) else tpt.delete(x,y) end tpt.drawpixel(x,y,255,0,0,255) if n > 19996 then return end -- change 19996 to 19995 to fill more area, but it is drawn in a strange shape n = n + 1 if getpixel(x+1,y) == b then floodfill(x+1,y,c,b,n) end if getpixel(x-1,y) == b then floodfill(x-1,y,c,b,n) end if getpixel(x,y+1) == b then floodfill(x,y+1,c,b,n) end if getpixel(x,y-1) == b then floodfill(x,y-1,c,b,n) end end ---------------------------------------------------------------------------------------------------------------------- -- Drawing -- Functions for drawing things, like rectangles or circles ---------------------------------------------------------------------------------------------------------------------- function drawmenuicon(fill) -- draws a menu icon above walls drawrect(613,408-nummenus*16,14,14,255,255,255,255,fill) drawcircle(620,415-nummenus*16,0,255,0,0,255,false) drawcircle(620,415-nummenus*16,1,255,127,0,255,false) drawcircle(620,415-nummenus*16,2,255,255,0,255,false) drawcircle(620,415-nummenus*16,3,0,255,0,255,false) drawcircle(620,415-nummenus*16,4,0,0,255,255,false) drawcircle(620,415-nummenus*16,5,255,127,255,255,false) drawcircle(620,415-nummenus*16,6,127,63,127,255,false) end function drawcircle(x,y,rd,r,g,b,a,fill,mouse) local function valid(x,y,mouse) local xmax = 612 local ymax = 384 if not mouse then xmax = 629 ymax = 423 end if x >= 0 and x < xmax and y >= 0 and y < ymax then return true end end local tempy = y local oldy = y for i = x - rd, x do oldy = tempy local distance = math.sqrt(math.pow(x-i,2) + math.pow(y-tempy,2)) while distance <= rd do tempy = tempy - 1 distance = math.sqrt(math.pow(x-i,2) + math.pow(y-tempy,2)) end tempy = tempy + 1 if oldy ~= tempy then oldy = oldy - 1 end if fill then for j = tempy, y+y-tempy do if valid(i,j,mouse) then tpt.drawpixel(i, j, r, g, b, a) end if valid(x+x-i,j,mouse) and i ~= x then tpt.drawpixel(x+x-i, j, r, g, b, a) end end else for j = tempy,oldy do if valid(i,j,mouse) then tpt.drawpixel(i, j, r, g, b, a) end if valid(x+x-i,j,mouse) and i ~= x then tpt.drawpixel(x+x-i, j, r, g, b, a) end if valid(i,y+y-j,mouse) and i ~= x - rd then tpt.drawpixel(i, y+y-j, r, g, b, a) end if valid(x+x-i,y+y-j,mouse) and i ~= x and i ~= x - rd then tpt.drawpixel(x+x-i, y+y-j, r, g, b, a) end end end end end function drawrect(x,y,w,h,r,g,b,a,fill) -- Draws a rectangle if fill then tpt.fillrect(x-1,y-1,w+2,h+2,r,g,b,a) -- tpt.fillrect only fills middle, not the outline like drawrect does else tpt.drawrect(x,y,w,h,r,g,b,a) end end function drawx(x,y,rd,r,g,b,a) -- Draws a _|_ shape with a hole in the middle (used for flood-fill) drawrect(x-rd,y,2*rd,0,r,g,b,a,1) -- | drawrect(x,y-rd,0,2*rd,r,g,b,a,1) tpt.drawpixel(x,y,0,0,0,255) end function textbox(x,y,width,text,canedit,min,max) --editable textbox, can only edit numbers local text2 = text local editing = false -- rightclick to manually input, will ignore min and max if they are false/nil if canedit and mousex >= x and mousex <= x+width and mousey >= y and mousey <= y+17 then editing = true tpt.set_shortcuts(0) end if editing == true and mouseb == 1 then tpt.drawrect(x,y,width,17,127,255,255,255) else tpt.drawrect(x,y,width,17,192,192,192,255) end if editing == true and (os.clock()*1000)%1000 > 500 then text2 = string.format("%s%s",text,"|") end tpt.drawtext(x+4,y+5,text2,255,255,255,255) if editing == true then if tempkeynum >= 48 and tempkeynum <= 57 then local add = tempkeynum-48 text = text * 10 + add if max and text > max then text = max end elseif tempkeynum == 8 then text = math.floor(text/10) if min and text < min then text = min end elseif tempkeynum == 45 then text = -1*text if max and text > max then text = max end if min and text < min then text = min end end if mouseb == 4 then text = tpt.input("Text editor","Enter a number",text) if max and text > max then text = max end if min and text < min then text = min end end end return text end ---------------------------------------------------------------------------------------------------------------------- -- Mouse And Keyboard Stuff -- Get the mouse and key presses and put them into correct variables ---------------------------------------------------------------------------------------------------------------------- keychar = {0} keynum = {0} modifier = {0} tempkeychar = 0 tempkeynum = 0 tempmodifier = 0 keycounter = 2 numkeysheld = 0 function getkeypress(kc,kn,m,event) -- keeps track of all keys held (sometimes doesn't work if keys pressed rapidly) m = m % 512 if numkeysheld < 0 then numkeysheld = 0 end keycounter = 2 --tpt.drawtext(100,100,kc) tpt.drawtext(100,110,kn) --tpt.drawtext(100,120,m) tpt.drawtext(100,140,event) if event == 1 then local i = numkeysheld numkeysheld = numkeysheld + 1 while i > 0 do keychar[i+1] = keychar[i] keynum[i+1] = keynum[i] modifier[i+1] = modifier[i] i = i - 1 end keychar[1] = kc tempkeychar = kc keynum[1] = kn tempkeynum = kn modifier[1] = m tempmodifier = m else numkeysheld = numkeysheld - 1 local keylifted = 0 local i = 1 while i <= numkeysheld + 1 do if keynum[i] == kn then keylifted = i end i = i + 1 end keychar[keylifted] = 0 tempkeychar = 0 keynum[keylifted] = 0 tempkeynum = 0 modifier[keylifted] = 0 tempmodifier = 0 i = keylifted + 1 while i <= numkeysheld + 1 do keychar[i-1] = keychar[i] keynum[i-1] = keynum[i] modifier[i-1] = modifier[i] i = i + 1 end end end function dokeystuff() -- make keys do things if keycounter == 1 then tempkeychar = 0 tempkeynum = 0 tempmodifier = 0 end if keycounter > 0 then keycounter = keycounter - 1 end --tpt.drawtext(150,100,keychar[1]) tpt.drawtext(150,110,keynum[1]) tpt.drawtext(150,120,modifier[1]) if modifier[1] == 65 or modifier[1] == 66 or modifier[1] == 129 or modifier[1] == 130 then flood = true else flood = false end if tempkeynum == 91 then if modifier[1] == 256 or modifier[1] == 512 then radius = radius - 1 else radius = radius - math.ceil((radius/5)+.1) end if radius < 0 then radius = 0 end elseif tempkeynum == 93 then if modifier[1] == 256 or modifier[1] == 512 then radius = radius + 1 else radius = radius + math.ceil((radius/5)+.1) end if radius > 800 then radius = 800 end end if tempkeychar == "h" and hudon then if huddisable then huddisable = false else huddisable = true end if modifier[1] ~= 1 and modifier[1] ~= 2 then tpt.hud(0) end end if tempkeychar == "s" or tempkeychar == "k" or tempkeychar == "l" then draw = false drawingcolor = false flood = false pcall(tpt.unregister_step,choosecolor) tpt.set_shortcuts(1) end if tempkeychar == "d" and hudon and huddisable == false then debug = debug + 1 if debug == 1 then debug = 2 end if (debug == 3 and extra2 == 1) or debug == 4 then debug = 0 end end end mouseb = 0 mousebq = 0 clickcounter = 3 mousex = 0 mousey = 0 function getmouseclick(mx,my,mb,event) if event ~= 2 then clickcounter = 3 end mousebq = mouseb mouseb = mb --tpt.drawtext(100,100,mouseb) tpt.drawtext(100,110,mousebq) tpt.drawtext(100,120,clickcounter) if (draw or drawingcolor or showslider ~= 0) and mousey < 384 and mousex < 612 then return false end end function domousestuff() -- reset mousebq / mouseb variables after 1 / 2 frames if clickcounter == 1 then mousebq = 0 elseif clickcounter == 2 then mouseb = 0 end if clickcounter > 0 then clickcounter = clickcounter - 1 end mousex = tpt.mousex mousey = tpt.mousey end ---------------------------------------------------------------------------------------------------------------------- -- Lua script Functions -- These are specific functions designed for this script that don't belong in a specific section ---------------------------------------------------------------------------------------------------------------------- currenttime = 0 totaltime = 0 afk = true afktime = 0 totalafktime = 0 afkstart = 0 startuptime = 0 timesplayed = 0 prevafktime = 0 function calculatefps() -- updates fps and elements.txt fpswaitc = fpswaitc + 1 if fpswaitc >= fpswait then fpswaitc = 0 end if fpswaitc == 0 then -- update FPS if os.clock() - time < 10 then oldtime = time time = os.clock() else -- more than 10 seconds online/between fps calculations local diff = time - oldtime time = os.clock() oldtime = time - diff end frames = frames + 1 totalfps = totalfps + fpswait/(time-oldtime) if fpswait/(time-oldtime) > maxfps then maxfps = fpswait/(time-oldtime) end end currenttime = os.clock() if (mousey < 30 and lasty > 30) or math.floor(currenttime) %60 == 0 then writeelements() end if (mousey == lasty or mousey >= 384) and mousex == lastx then if afk == false then afk = true afkstart = currenttime end elseif afk == true then afk = false totalafktime = totalafktime + afktime afktime = 0 end if afk and currenttime - afkstart > 30 then afktime = currenttime - afkstart - 30 end if mousey < 384 then lastx = mousex lasty = mousey end end PT_R = 76 PT_G = 230 PT_B = 167 PT_A = 255 drawingcolor = false drawcolor = 0 function choosecolor() -- By gamax92, edited by jacob1 if mousex < 184 or mousex > 428 or mousey < 128 or mousey > 215 then tpt.set_shortcuts(1) end tpt.fillrect(182,126,248,91,0,0,0) -- make middle all black tpt.drawrect(184,128,244,87,192,192,192) -- outside box tpt.drawrect(184,199,244,0,192,192,192) -- top of OK button tpt.drawtext(189,204,"OK") tpt.fillrect(384,153,37,38,PT_R,PT_G,PT_B,PT_A) -- Color tpt.drawrect(384,153,37,37,192,192,192) -- Color box tpt.drawtext(192,136,"Change decoration color",160,160,255) PT_R = textbox(192,153,45,PT_R,true,0,255) PT_G = textbox(240,153,45,PT_G,true,0,255) PT_B = textbox(288,153,45,PT_B,true,0,255) PT_A = textbox(336,153,45,PT_A,true,0,255) local color = PT_A*16777216 + PT_R*65536 + PT_G*256 + PT_B textbox(192,172,189,"0x" .. string.format("%X", color),false) if tempkeynum == 13 or (mouseb == 1 and mousebq == 0 and mousex >= 184 and mousex <= 428 and mousey >= 199 and mousey <= 215) then tpt.set_shortcuts(1) tpt.unregister_step(choosecolor) end drawcolor = color drawingcolor = true draw = false end function findelement() -- searches the screen for whatever element is first in your favorites list -- and paints it red. Everyhing else is dimmed tpt.fillrect(0,0,612,384,0,0,0,230) -- You must register it for it to work, but it causes a lot of lag local findtype = changetonum(currentel) tpt.start_getPartIndex() while tpt.next_getPartIndex() do local index = tpt.getPartIndex() if tpt.get_property("type", index) == findtype then tpt.drawpixel(math.floor(tpt.get_property("x",index)+.5),math.floor(tpt.get_property("y",index)+.5),255,0,0,255) end end end displayinfo = false function info() -- draws statistics on the screen local function timestring(currtime) local years = currtime/31557600 currtime = currtime%31557600 local days = currtime/86400 currtime = currtime%86400 local hours = currtime/3600 currtime = currtime%3600 local minutes = currtime/60 currtime = currtime%60 local seconds = math.floor(currtime) local milliseconds = (currtime-seconds)*1000 return string.format("%i years, %i days, %i hours, %i minutes, %i seconds, %i milliseconds",years,days,hours,minutes,seconds,milliseconds) end tpt.drawtext(10,300,string.format("Time Played: %s",timestring(currenttime-totalafktime-afktime-startuptime))) tpt.drawtext(10,310,string.format("Total Time Played: %s ",timestring(totaltime+currenttime-totalafktime-afktime-startuptime))) local allafktime = string.format("Total AFK Time: %s",timestring(totalafktime+afktime+prevafktime)) tpt.drawtext(10,320,allafktime) local averagefps = string.format("Average FPS: %f",totalfps/frames) tpt.drawtext(10,330,averagefps) local maximumfps = string.format("Max FPS: %f",maxfps) tpt.drawtext(10,340,maximumfps) local timespl = string.format("Number of times played: %i",timesplayed) tpt.drawtext(10,350,timespl) local avstarttime = string.format("Startup Time: %f seconds",startuptime/timesplayed) tpt.drawtext(10,360,avstarttime) end function readelements() -- reads elements.txt local function readnext(f) contents = f:read() if contents == nil then error() end return contents end local f = io.open("elements.txt") locked = tonumber(readnext(f)) for i = 1, locked do updatemenu(readnext(f),true) end currentel = elements[1] local h = tonumber(readnext(f)) if h ~= 0 then tpt.register_step(hud) hudon = true debug = h - 1 end totaltime = tonumber(readnext(f)) totalfps = tonumber(readnext(f)) frames = tonumber(readnext(f)) totalfps = totalfps*frames maxfps = tonumber(readnext(f)) prevafktime = tonumber(readnext(f)) startuptime = os.clock() readnext(f) timesplayed = readnext(f) + 1 f:close() if hudon then tpt.hud(0) end end function writeelements() -- writes info to elements.txt every 60 seconds or when you move your mouse towards the top of the screen local f = io.open("elements.txt","w") f:write(locked,"\n") for i = 1, locked do f:write(elements[i],"\n") end local h = 0 if hudon then h = debug + 1 end f:write(h,"\n") f:write(currenttime+totaltime-totalafktime-afktime-startuptime,"\n") f:write(totalfps/frames,"\n") f:write(frames,"\n") f:write(maxfps,"\n") f:write(totalafktime+afktime+prevafktime,"\n") f:write(startuptime,"\n") f:write(timesplayed) f:close() end function updatemenu(el,lock) -- Makes el the first element in the favorites list local pos = maxoptions-2 local first = locked for i = 1, maxoptions-1 do if elements[i] == el then pos = i - 1 -- If el is alredy on list, don't put it there twice end end if pos < locked and locked ~= maxoptions - 1 then lock = true end if lock then first = 0 end while pos > first do elements[pos+1] = elements[pos] pos = pos - 1 end if first ~= maxoptions - 1 then elements[first + 1] = el end end function updatemenunum() -- Checks which active_menu you are in (Gasses, Electronics,...) if mousex > 609 and mousex < 628 and mousey > 407-nummenus*16 and mousey < 407 and mouseb == 0 then local y = 407-nummenus*16 local one = 0 for i = 1, nummenus do if activemenu == i then one = 1 else one = 0 end if mousey > y-one and mousey < y+16+one then activemenu = i end y = y + 16 end end end ---------------------------------------------------------------------------------------------------------------------- -- HUD -- draws a HUD like tpt does with most of the same info plus more ---------------------------------------------------------------------------------------------------------------------- time = 11 oldtime = 0 fpswait = 7 fpswaitc = 0 debug = 2 hudon = false huddisable = false maxfps = 0 totalfps = 0 frames = 0 function hud() -- A different hud than the original. The only problem is that there is no get pressure/gravity functions if menugone then mousex = tpt.mousex mousey = tpt.mousey calculatefps() end if huddisable then return end local uitext = "" local coordtext = "" local heattext = "" local date = os.date("*t") if date["hour"] > 12 then date["hour"] = date["hour"] - 12 end local function getweekday(weekday) if weekday == 1 then return "Sun." elseif weekday == 2 then return "Mon." elseif weekday == 3 then return "Tue." elseif weekday == 4 then return "Wed." elseif weekday == 5 then return "Thur." elseif weekday == 6 then return "Fri." elseif weekday == 7 then return "Sat." end end local function getmonth(month) if month == 1 then return "Jan." elseif month == 2 then return "Feb." elseif month == 3 then return "March" elseif month == 4 then return "April." elseif month == 5 then return "May" elseif month == 6 then return "June" elseif month == 7 then return "July" elseif month == 8 then return "Aug." elseif month == 9 then return "Sept." elseif month == 10 then return "Oct." elseif month == 11 then return "Nov." elseif month == 12 then return "Dec." end end local datetext = string.format("%s %s %i, %i %i:%.2i:%.2i",getweekday(date["wday"]),getmonth(date["month"]),date["day"],date["year"],date["hour"],date["min"],date["sec"]) if debug >= 1 then uitext = string.format('%s FPS:%.2f Parts:%i',datetext,fpswait/(time-oldtime),tpt.get_numOfParts()) else uitext = string.format('%s FPS:%i',datetext,fpswait/(time-oldtime)) end drawrect(12, 13, tpt.textwidth(uitext)+8, 13, 0, 0, 0, 140, true) tpt.drawtext(16, 16, uitext, 32, 216, 255, 200) -- Draw HUD exactly like powder toy does if debug >= 1 then coordtext = string.format('X:%i Y:%i',mousex,mousey) if debug >= 2 then if mousex < 612 and mousey < 384 and tpt.get_property("type",mousex,mousey) ~= 0 then coordtext = string.format('#%i, %s',tpt.get_property("id",mousex,mousey),coordtext) end end drawrect(612-20-tpt.textwidth(coordtext), 27, tpt.textwidth(coordtext)+8, 9, 0, 0, 0, 140, true) tpt.drawtext(612-16-tpt.textwidth(coordtext), 27, coordtext, 255, 255, 255, 200) end local type = 0 if mousex < 612 and mousey < 384 then type = tpt.get_property("type",mousex,mousey) end if type == 78 then type = changetonamegol(tpt.get_property("ctype",mousex,mousey)) ctype = "" else type = changetoname(type) end if type == "X" or type == 0 then heattext = string.format('Empty, Pressure: NA') else if debug >= 1 then local ctype = changetoname(tpt.get_property("ctype",mousex,mousey)) if ctype == "X" or ctype == "x" then ctype = "" end if debug < 3 then heattext = string.format('%s (%s), Temp: %.4f C %.4f F, Life: %i, Tmp: %i',type,ctype,tpt.get_property("temp",mousex,mousey) - 273.15,((tpt.get_property("temp",mousex,mousey)-273.15)*9/5)+32,tpt.get_property("life",mousex,mousey),tpt.get_property("tmp",mousex,mousey)) else heattext = string.format('%s (%s), Temp: %.4f C %.4f F, Life: %i, Tmp: %i, Color: %i',type,ctype,tpt.get_property("temp",mousex,mousey) - 273.15,((tpt.get_property("temp",mousex,mousey)-273.15)*9/5)+32,tpt.get_property("life",mousex,mousey),tpt.get_property("tmp",mousex,mousey),tpt.get_property("dcolour",mousex,mousey)) end else heattext = string.format('%s, Temp: %.2f C',type,tpt.get_property("temp",mousex,mousey) - 273.15) end end drawrect(612-20-tpt.textwidth(heattext), 13, tpt.textwidth(heattext)+8, 13, 0, 0, 0, 140, true) tpt.drawtext(612-16-tpt.textwidth(heattext), 16, heattext, 255, 255, 255, 200) end ---------------------------------------------------------------------------------------------------------------------- -- M M A IIIIIII N N -- MM MM A A I NN N -- M M M M AAAAA I N N N -- M M M A A I N N N -- M M A A I N NN -- M M A A IIIIIII N N ---------------------------------------------------------------------------------------------------------------------- drawmenu = true draw = false wait = false flood = false lastx = 0 lasty = 0 menunum = 1 activemenu = 1 scriptver = 3 scriptver2 = 0 lightningwait = 0 currentel = elements[1] function main() -- called every frame, gets and draws elements that you use and calls other functions drawdebug() debugset = false -- sets mouse/keyboard variables, makes keys do stuff dokeystuff() domousestuff() drawmenuicon(drawmenu) updatemenunum() if activemenu == displaymenu then drawmenu = true else drawmenu = false end if wait then -- get element that was placed wait = false currentel = tpt.get_property("type",lastx,lasty) if currentel == 0 then currentel = tpt.selectedl if currentel%256 == 78 then currentel = changetonamegol(math.floor(currentel/78)) end end if currentel == 78 then currentel = tpt.get_property("ctype",lastx,lasty) currentel = changetonamegol(currentel) else currentel = changetoname(currentel) end updatemenu(currentel,false) end if mouseb ~= 0 and mousex < 612 and mousey < 384 then if mouseb == 1 and mousebq == 0 and draw == false then wait = true -- Wait a frame to get placed element, it hasn't actually been drawn yet end if draw then -- Draw element using a line or floodfill if mouseb %2 == 1 and currentel ~= "X"then if flood then floodfill(mousex,mousey,currentel,0,0) else if currentel == "LIGH" or currentel == 87 then if lightningwait == 0 and tpt.get_property("type",mousex,mousey) == 0 then lightningwait = 10 tpt.create(mousex, mousey, 87) tpt.set_property("tmp2",4,x,y) tpt.set_property("tmp",270,x,y) local rd = radius * 2 if rd > 55 then rd = 55 end tpt.set_property("life",rd,x,y) elseif lightningwait > 0 then lightningwait = lightningwait - 1 end else create_line(lastx,lasty,mousex,mousey,radius,currentel) end end else if flood == false then create_line(lastx,lasty,mousex,mousey,radius,0) elseif tpt.get_property("type",mousex,mousey) ~= 0 then floodfill(mousex,mousey,0,tpt.get_property("type",mousex,mousey),0) end end elseif drawingcolor then if mouseb == 1 then create_line(lastx,lasty,mousex,mousey,radius,-1) elseif mouseb == 4 then create_line(lastx,lasty,mousex,mousey,radius,-2) end end end if draw or drawingcolor then -- draw circle or x for floodfill if flood then drawx(mousex,mousey,5,0,255,0,255) else drawcircle(mousex,mousey,radius,0,255,0,255,false,true) end end if mousey > 384 and mousey < 400 and mouseb == 1 and mousebq == 0 then if activemenu ~= displaymenu or mousex > 16 + maxoptions*31 then draw = false -- if you click anywhere on the bottom menu, stop drawing drawingcolor = false flood = false end end if drawmenu then tpt.active_menu(3) tpt.el.acel.menu = 0 tpt.el.dcel.menu = 0 tpt.el.fray.menu = 0 tpt.el.rpel.menu = 0 if menunum == 1 then menu1() else menu2() --else menu3() end else tpt.el.acel.menu = 1 tpt.el.dcel.menu = 1 tpt.el.fray.menu = 1 tpt.el.rpel.menu = 1 end calculatefps() if displayinfo then info() end end ---------------------------------------------------------------------------------------------------------------------- -- Menu Functions -- Draws the menus, similar to menu_ui_v3 ---------------------------------------------------------------------------------------------------------------------- locked = 0 hidden = false hiding = 0 hidex = 0 function menu1() numoptions = maxoptions if hiding == 1 then hidex = hidex + 5 end if hiding == 2 then hidex = hidex - 5 end if hidex >= numoptions*31 - 5 then hiding = 0 end if hidex == 0 then hiding = 0 end if hidden == false then tpt.drawtext(10+hidex,388,">") else tpt.drawtext(10+hidex,388,"<") end if mousex >= 10+hidex and mousex <= 15+hidex and mousey >= 390 and mousey <= 395 then if hidden == false then tpt.drawtext(10+hidex,388,">",255,0,0,255) else tpt.drawtext(10+hidex,388,"<",255,0,0,255) end if mouseb == 1 and mousebq == 0 and hidden == false then hiding = 1 hidden = true elseif mouseb == 1 and mousebq == 0 then hiding = 2 hidden = false end end local x = 20+hidex for i = 1, numoptions do -- draw menu boxes, colors, and text if x < numoptions*31 - 10 then local r = 0 local g = 0 local b = 0 if i==numoptions then r = 127 b = 127 else local particle = tpt.el[string.lower(elements[i])] local col if particle then col = particle.color else if elements[i] == "GOL" then col = tpt.el.life.color else col = 0 end end r = col/65536 g = (col/256)%256 b = col%256 end drawrect(x,386,25,13,r,g,b,255,true) local textcol = b+3*g+2*r if textcol < 544 then textcol = 255 else textcol = 0 end if i <= locked then drawrect(x,386,25,13,0,0,255,200,true) end local width = tpt.textwidth(elements[i]) tpt.drawtext(x+(27-width)/2, 389, elements[i], textcol, textcol, textcol, 255) x = x + 31 end end if draw then -- draw rectangle around selected element in menu if currentel == elements[1] and 48+hidex < numoptions*31 then drawrect(18+hidex,384,29,17,255,55,55,255,false) elseif 48+hidex < numoptions*31 - locked*31 then drawrect(18+locked*31+hidex,384,29,17,255,55,55,255,false) end end if mousey > 384 and mousey < 400 then if mousex < 15 + maxoptions*31 and mouseb == 0 then drawrect(594-tpt.textwidth("Force Creating"),373,tpt.textwidth("Force Creating")+2,10,255,255,255,255,true) end local x = 19+hidex for i = 1, numoptions do -- Make stuff happen when you click buttons if mousex > x and mousex < x+27 and x < numoptions*31-11 then if (mouseb == 1 or mouseb == 4) and mousebq == 0 then if i < numoptions then if mouseb == 1 then currentel = elements[i] draw = true drawing = false updatemenu(currentel,false) else if i > locked then locked = locked + 1 updatemenu(elements[i],true) else local temp = elements[i] for j = i + 1, locked do elements[j-1] = elements[j] end elements[locked] = temp locked = locked - 1 end writeelements() end end if i == numoptions and mouseb ~= 4 then menunum = 2 end else if mouseb == 0 then drawrect(x-1,384,29,17,255,55,55,255,false) local particle = tpt.el[string.lower(elements[i])] local desc = "Error getting description" if particle then desc = particle.description elseif elements[i] == "GOL" then desc = tpt.el.life.description end tpt.drawtext(587-tpt.textwidth("Force Creating")-tpt.textwidth(desc),375,desc,255,255,255,255) end end end x = x + 31 end else canreset = true end end canreset = false menugone = false extra2 = 1 if tpt.get_name() == "jacob1" then extra2 = 0 end function menu2() local numoptions = 10 local xoff = 0 if numoptions - extra2 > maxoptions then local fwidth = (numoptions-extra2) * 31 local maxwidth = maxoptions*31 local overflow = fwidth-maxwidth local mx = mousex if mx > maxoptions*31 then mx = maxoptions*31 end local location = maxwidth/(mx-maxwidth) xoff = math.floor((overflow / location)) end local x = 20 + maxoptions*31 - numoptions*31 + extra2*31 - xoff local text = {"cstm1","cstm2","cstm3","hud","info","find","paint","reset","hide","back"} local info = {"Edit the lua file to change what these three buttons do" ,"Left click to activate once and unregister the function. Right click to register the function" ,"If a function is registered, it will be activated every frame" ,"Left click to activate a different HUD. Press H to get rid of the original. Right click to deactivate" ,"Displays extra info. Left click to activate, Right click to deactivate" ,"Finds the first element in your list and colors it red. Everything else is dimmed. Right click deactivates" ,"Lets you draw color on top of the elements" ,"Resets menu, changes to autorun.lua take effect." ,"Hides this menu and the HUD until the powdertoy is restarted. Dosen't unresgister custom functions" ,"Goes back to the favorite elements menu"} for i = 1, numoptions do -- draw menu text if i ~= 8 or extra2 == 0 then if x > 0 and x <= maxoptions*31 - 11 then local r = 0 local g = 0 local b = 0 if i%3 == 0 then r = 255 g = 127 end if i%3 == 1 then b = 255 g = 127 end if i%3 == 2 then g = 255 r = 127 end drawrect(x,386,25,13,r,g,b,255,true) local textcol = b+3*g+2*r if textcol < 544 then textcol = 255 else textcol = 0 end local width = tpt.textwidth(text[i]) tpt.drawtext(x+(27-width)/2, 389, text[i], textcol, textcol, textcol, 255) end x = x + 31 end end if mousey > 384 and mousey < 400 then if mousex < 15 + maxoptions*31 and mouseb == 0 then drawrect(594-tpt.textwidth("Force Creating"),373,tpt.textwidth("Force Creating")+2,10,255,255,255,255,true) end local x = 19 + maxoptions*31 - numoptions*31 + extra2*31 - xoff for i = 1, numoptions do -- make buttons do stuff if i ~= 8 or extra2 == 0 then if x > 1 and x <= maxoptions*31 - 12 and mousex > x and mousex < x+27 then if (mouseb == 1 or mouseb == 4) and mousebq == 0 then if i == numoptions and mouseb == 1 then menunum = 1 elseif i == 1 then if mouseb == 1 then tpt.unregister_step(custom1) custom1() else tpt.register_step(custom1) end elseif i == 2 then if mouseb == 1 then tpt.unregister_step(custom2) custom2() else tpt.register_step(custom2) end elseif i == 3 then if mouseb == 1 then tpt.unregister_step(custom3) custom3() else tpt.register_step(custom3) end elseif i == 4 then if mouseb == 1 then if debug == 0 then debug = 1 elseif debug == 1 then debug = 2 elseif debug == 2 and extra2 == 0 then debug = 3 else debug = 0 end if hudon == false then tpt.register_step(hud) end hudon = true tpt.hud(0) else tpt.unregister_step(hud) tpt.hud(1) debug = 2 hudon = false end writeelements() huddisable = false elseif i == 5 then if mouseb == 1 then displayinfo = true else displayinfo = false end elseif i == 6 then if mouseb == 1 then tpt.register_step(findelement) else tpt.unregister_step(findelement) end elseif i == 7 then if mouseb == 1 then drawingcolor = true pcall(tpt.register_step,choosecolor) else drawingcolor = false pcall(tpt.unregister_step,choosecolor) end --elseif i == 8 then -- menunum = 3 elseif i == 8 and canreset then if mouseb == 1 then tpt.delete(0,0) tpt.create(0,0,"dmnd") if hudon then tpt.set_property("life",debug+1,0,0) end if draw then tpt.set_property("tmp",1,0,0) tpt.set_property("ctype",currentel,0,0) end tpt.set_property("vx",menunum,0,0) end tpt.unregister_step(main) tpt.unregister_step(hud) tpt.unregister_step(custom1) tpt.unregister_step(custom2) tpt.unregister_step(custom3) tpt.unregister_mouseclick(getmouseclick) tpt.unregister_keypress(getkeypress) writeelements() dofile("autorun.lua") elseif i == 9 and mouseb == 1 then menugone = true tpt.unregister_step(main) if extra2 ~= 0 then tpt.unregister_step(hud) end end else if mouseb == 0 then tpt.drawtext(587-tpt.textwidth("Force Creating")-tpt.textwidth(info[i]),375,info[i],255,255,255,255) drawrect(x-1,384,29,17,255,55,55,255,false) end end end x = x + 31 end end else canreset = true end end showslider = 0 function menu3() --removed for now, may finish later end -- draws a slider, mostly finished, but unused sliderx = 0 function drawslider(x,y,length,min,max) if mouseb == 1 and mousey < y+2 then sliderx = mousey - y + length + 9 if sliderx < 0 then sliderx = 0 end if sliderx > length then sliderx = length end end local value = (length-sliderx)/length*(max-min)+min tpt.drawrect(x,y-length-33,50,length+33,255,255,255,255) tpt.fillrect(x,y-length-33,50,length+33,0,0,127,127) value = textbox(x+8,y-length-30,34,value,true,false,false) sliderx = length-(value-min)*length/(max-min) tpt.drawrect(x+20,y-length-10,10,length+3,255,255,255,255) tpt.fillrect(x+20,y-length-10,10,length+3,0,0,255,127) tpt.drawrect(x+18,y-length-12+sliderx,14,6,255,255,255,255) tpt.fillrect(x+18,y-length-12+sliderx,14,6,0,0,255,255) return value end ---------------------------------------------------------------------------------------------------------------------- -- Registering -- Registers all script functions and gets values from diamond that is created when I hit reset (only I can) ---------------------------------------------------------------------------------------------------------------------- tpt.register_step(main) tpt.register_mouseclick(getmouseclick) tpt.register_keypress(getkeypress) tpt.active_menu(displaymenu) activemenu = displaymenu tpt.set_console(0) readelements() if tpt.get_property("type",0,0) == 28 then --if tpt.get_property("life",0,0) ~= 0 then if hudon == false then tpt.register_step(hud) end debug = tpt.get_property("life",0,0) - 1 hudon = true end if tpt.get_property("tmp",0,0) == 1 then draw = true currentel = changetoname(tpt.get_property("ctype",0,0)) updatemenu(currentel,false) end if tpt.get_property("vx",0,0) ~= 0 then menunum = tpt.get_property("vx",0,0) end end --836166