Wednesday, October 15, 2014

Backend started

Got a few functions out today

function JumpPackCheck(ply)
if SERVER then
return ply:GetInfoNum("surf_jump_pack", 1) == 1
elseif CLIENT then
return cvars.Number("surf_jump_pack") == 1
end
end

Checks if the player has the jump pack enabled.

function SURF:LetsDetectJP( x, y, text, desc, cvar, p )
surface.SetFont("SURF_MAIN_BUTTON_TITLE")
local _w, _h = surface.GetTextSize(text)
surface.SetFont("SURF_MAIN_BUTTON_DESC")
local __w, __h = surface.GetTextSize(desc)
local c = SURF.MainColors
local w, h = __w > _w and __w+30 or _w+30, _h+__h+10
local butt = surfui.Button( SURF.MainUI, x, y, w, h, p, function( s, w, h )
s.state = GetConVarNumber(cvar)
draw.RoundedBox( 0, 0, h/2-10, 20, 20, c.side )
draw.RoundedBox( 0, 2, h/2-8, 16, 16, c.main )
draw.RoundedBox( 0, 3, h/2-7, 14, 14, s.state == 1 and c.side or c.main )
draw.SimpleText( text, "SURF_MAIN_BUTTON_TITLE", 25, 5, Color( 0, 0, 0, 210 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM )
draw.SimpleText( desc, "SURF_MAIN_BUTTON_DESC", 25, 5+_h, Color( 0, 0, 0, 210 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM )
end)
butt.DoClick = function(s)
if CurTime() > NextAllowedClick then
if GetConVarNumber("surf_jump_pack") == 1 then
RunConsoleCommand("surf_jump_pack", 0)
RunConsoleCommand("say", "/r")
else
RunConsoleCommand("surf_jump_pack", 1)
RunConsoleCommand("say", "/r")
end
NextAllowedClick = CurTime() + 1
end
end
end

Menu Check box. Resets player if it detects a change.

Basically sets the cvar surf_jump_pack to 0 or 1 
and puts a 1s delay between button clicks because Garrysmod has a ConVar Speed restriction, so spamming the button would allow you to set a value, without being a reset.

Lastly, little easter egg I made today

if (GetConVarNumber("surf_velocity_color_r") == 1 and GetConVarNumber("surf_velocity_color_g") == 33 and GetConVarNumber("surf_velocity_color_b") == 7) or GetConVarNumber("surf_mlg_hud") == 1 then
color = Color( 255*math.abs(math.sin(CurTime())), 255*math.abs(math.sin(CurTime()+1.8)),255*math.abs(math.sin(CurTime()+2.6)), 255)
else
color = Color( GetConVarNumber("surf_velocity_color_r"), GetConVarNumber("surf_velocity_color_g"), GetConVarNumber("surf_velocity_color_b") )
end

Basically a hud check to see if your colors are 1337 and if they are make them rainbow.

Color( 255*math.abs(math.sin(CurTime())), 255*math.abs(math.sin(CurTime()+1.8)),255*math.abs(math.sin(CurTime()+2.6)), 255)

This is similar to what you probably know as HSVToColor

No comments:

Post a Comment