daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Aug 13th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local PPI = require("ppi")
  2.  
  3. local LOCATION = 10
  4. --[[  The location on the screen to put the gauges.
  5.   4 = top left
  6.   5 = top
  7.   6 = top right
  8.   7 = right
  9.   8 = bottom right
  10.   9 = bottom
  11.   10 = bottom left
  12.   11 = left
  13. --]]
  14.  
  15.  
  16. local function WindowTextShadow(name, font, text,
  17.                                 left, top, right, bottom,
  18.                                 color,
  19.                                 shadow_left, shadow_top,
  20.                                 shadow_color)
  21.   -- draw shadow
  22.   WindowText(name, font, text,
  23.              left + shadow_left, top + shadow_top, right, bottom,
  24.              shadow_color)
  25.   -- draw text
  26.   WindowText(name, font, text,
  27.              left, top, right, bottom,
  28.              color)
  29. end
  30.  
  31. local function clamp(num, min, max)
  32.   return (num > max) and max or ((num < min) and min or num)
  33. end
  34.  
  35. gauges = {
  36.   name = GetPluginID(),
  37.  
  38.   stats = {
  39.     nl = {curr = 0,   max = 100, x = 56, y = 28},
  40.     hp = {curr = 100, max = 100, x = 56, y = 53},
  41.     mp = {curr = 100, max = 100, x = 56, y = 68},
  42.     ep = {curr = 100, max = 100, x = 56, y = 83},
  43.     wp = {curr = 100, max = 100, x = 56, y = 98},
  44.   },
  45.  
  46.   percent = function(stat)
  47.     return clamp(math.floor(stat.curr/stat.max * 100), 0, 100)
  48.   end,
  49.  
  50.   draw = function ()
  51.     local left, top, width
  52.    
  53.     -- Draw the base image
  54.     WindowDrawImage(gauges.name, "gauges", 0, 0, 0, 0, 1)
  55.    
  56.     -- Draw the individual bars
  57.     for name,stat in pairs(gauges.stats) do
  58.       left, top = stat.x, stat.y
  59.       width = math.floor(gauges.percent(stat)/2)
  60.      
  61.       if width > 0 then
  62.         WindowDrawImage(gauges.name, name,
  63.                         left, top, 0, 0,
  64.                         1,
  65.                         0, 0, width, 0)
  66.       end
  67.      
  68.       local txt = tostring(width*2) .. "%"
  69.       WindowTextShadow(gauges.name, "f", tostring(width*2) .. "%",
  70.                        stat.x + 52, top-2, 0, 0,
  71.                        0xAAFFCC,
  72.                        2, 2,
  73.                        0x000000)
  74.     end
  75.     WindowShow(gauges.name, true)
  76.   end,
  77. }
  78.  
  79. -- (ID, on_success, on_failure)
  80. PPI.OnLoad("29a4c0721bef6ae11c3e9a82", function(gmcp)
  81.   gmcp.Listen("Char.Vitals", function(message, content)
  82.     content.maxnl = 100
  83.    
  84.     for stat, data in pairs(gauges.stats) do
  85.       data.curr = tonumber(content[stat] + 0)
  86.       data.max  = tonumber(content["max" .. stat])
  87.     end
  88.      Execute("maxhm:"..gauges.stats.hp.max.." "..gauges.stats.mp.max)
  89.     gauges.draw()
  90.   end)
  91. end)
  92.  
  93. local atcp_stats = {H = "hp", M = "mp", E = "ep", W = "wp", NL = "nl"}
  94. PPI.OnLoad("7c08e2961c5e20e5bdbf7fc5", function(atcp)
  95.   atcp.Listen("Char.Vitals", function(message, content)
  96.     for stat, curr, max in string.gmatch(content, "(%w+):(%d+)/(%d+)") do
  97.       gauges.stats[atcp_stats[stat]].curr = curr
  98.       gauges.stats[atcp_stats[stat]].max = max
  99.     end
  100.  
  101.     gauges.draw()
  102.   end)
  103. end)
  104.  
  105. function TellXP()
  106.         ColourTell("lime", "black", "-", "white", "black", "(", "red", "black", gauges.stats.nl.curr.."%", "white", "black", ")", "lime", "black", "- ")
  107. end
  108.  
  109. function TellPromptBlackout()
  110.         ColourTell("#46813C", "black", gauges.stats.hp.curr.."h, "..gauges.stats.mp.curr.."m ")
  111.         Execute("hm:"..gauges.stats.hp.curr.." "..gauges.stats.mp.curr)
  112. end -- TellPrompt()
  113.  
  114.  
  115. OnPluginListChanged = function()
  116.   PPI.Refresh()
  117. end
  118.  
  119. OnPluginInstall = function()
  120.   local resources = plugger.path("resources")
  121.  
  122.   -- Set up the window
  123.   WindowCreate(gauges.name, 0, 0, 150, 139, LOCATION, 0, ColourNameToRGB("black"))
  124.  
  125.   -- Add a font
  126.   WindowFont(gauges.name, "f", "Arial", 7.5)
  127.  
  128.   -- Load the base image
  129.   WindowLoadImage(gauges.name, "gauges", resources .. "gauges.bmp")
  130.  
  131.   -- Load the image for each gauge
  132.   for stat,_ in pairs(gauges.stats) do
  133.     WindowLoadImage(gauges.name, stat, resources .. stat .. ".bmp")
  134.   end -- for
  135.  
  136.   -- Draw!
  137.   gauges.draw()
  138. end
  139.  
  140. OnPluginClose = function()
  141.   WindowDelete(gauges.name)
  142. end
  143.  
  144. OnPluginEnable = OnPluginInstall
  145. OnPluginDisable = OnPluginClose
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top