Team Spartan Cookies & Milk Forums
Release Screensaver for starfall screens[level easy] - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: Release Screensaver for starfall screens[level easy] (/thread-1129.html)



Screensaver for starfall screens[level easy] - LocInt - 22-07-2015

Hello,

Im releasing my screensaver code for starfall screens.

Level of this tutorial is quite advanced.

It's purpose is to turn on screensaver if your quota is about to hit its limit.

Like if your quota percent suddenly pop from 1% to 95% it turns on the screensaver. Usually if you create something player related then more players->more quota which is why your screens hits the limit. It has also idle screensaver in case its not used for 60 seconds.

In case your screen is using use(ply) function for touchscreen you might want to write these lines inside that function therefore it does not turn on the idle screensaver if you're using the screen. It still will turn it on if your quota is about to hits it limit.
Code:
timer.remove("ScreenSaver") ScreenSaver=false timer.create( "ScreenSaver", 60, 1, function() ScreenSaver=true Keyboard=false end)

Next thing is to place these lines to the section you render your screen. We calculate if your quota is about to hits its limit.

Code:
if(math.round(cpuAverage()/cpuMax()*100, 2)>98 or cpuAverage()>5500) then hook.remove("net", "yournethook") hook.remove("render", "yourrenderhook") Hooks=false ScreenSaver=true end

Also if you want to make something else than a black screen when you turn on screensaver you might want to add these lines after that last statement. Im not deciding what text or background does your screensaver has therefore i let it up to you.

I would propably add buttons for all your tabs in case you want to see your tabs. You can disable the screensaver just by using the screen again as we stated before.
Code:
if(ScreenSaver) then end

We need a timer therefore we can return the hooks and you can begin rendering again.

Code:
timer.create( "ScreenSaverCheck", 1, 0, function() if(not ScreenSaver) then if(not Hooks) then hook( "net", "yournethook", receiveMessage) hook( "render", "yourrenderhook", renderScreen) Hooks=true end end end )

You might also wanna initialize the variables we used on this tutorial.

Code:
local Hooks=false local ScreenSaver=true

Thanks for reading!

Regards,

LocInt