Example Scripts

*Due to the constant updates garrysmod gets, some of these may need tweaking to work.

Simple Health Bar:

require("g15")
 
-- bEmulator = false
g15.createLCD(false, "Gmod: Health bar sample")
 
-- ID: 1
-- Style: 2 -> Filled
g15.addpbar(1,2)
 
-- ID: 1
-- Width: 35
-- Height: 5
g15.setpbarsize(1,35,5)
 
-- ID: 1
-- X: 0
-- Y: 0
g15.setpbarorigin(1,0,0)
 
local client = LocalPlayer()
function onThink()
  if !client:Alive() then return end
 
  -- Set the percentage of the bar
  -- ID: 1
  g15.setpbarvalue( 1, client:Health() )
 
  -- Update the LCD to show changes
  g15.updateLCD()
end
hook.Add( "Think", "Some unique name", onThink )

Button polling:

local client = LocalPlayer()
require("g15")
 
g15.createLCD(false, "Gmod: Button input sample")
 
function onThink()
  if !client:Alive() then return end
 
  if (g15.isbuttonpressed(0)) then
	client:ConCommand("say I pressed button 1 on my g15!")
  end
 
  -- Update the LCD
  g15.updateLCD()
end
hook.Add( "Think", "updater", onThink )

Multiple Pages are supported:

local client = LocalPlayer()
require("g15")
 
g15.createLCD(true, "Gmod: Page example")
-- Look at the other samples to see how the text works
 
-- You begin with one page, We want another so we add one.
g15.addpage()
 
-- Showing how to get page count
Msg(g15.getpagecount())
 
-- We want to change controls on page 1
g15.modifypagenum(0)
 
-- Lets add some text, Look at the health_text sample to see how to do it, ID 1
g15.addtext( 1, false, 1, 1, 120, 1 )
g15.settextorigin( 1, 0, 0 )
g15.settexttext(1, "Page 1")
 
-- We want to change controls on page 2
g15.modifypagenum(1)
 
-- Lets add some text to page 2 now, ID 2
g15.addtext( 2, false, 1, 1, 120, 1 )
g15.settextorigin( 2, 0, 0 )
g15.settexttext(2, "Page 2")
 
function onThink()
  -- Make the buttons change pages
  if(g15.isbuttonpressed(0)) then
	g15.showpagenum(0)
  end
 
  if(g15.isbuttonpressed(1)) then
	g15.showpagenum(1)
  end
 
  -- Update the LCD
  g15.updateLCD()
end
hook.Add( "Think", "updater", onThink )

More examples are included in the Zip file.

No Comments

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>