blanco\_progress.gsc
PHP Code:
////////////////////////
// Scripted by BlancO //
// For killtube.org //
// 23.09.2013 //
////////////////////////
main()
{
// Image of progress background
level.progressBar_back = "gfx/hud/hud@health_back.tga";
// Image of progress
level.progressBar = "gfx/hud/hud@health_bar.tga";
// Show time left (0 = no timer, 1 = timer, 2 tenthsTimer)
level.progressShowTime = 2;
// Progress passed "time", "melee" (when holding melee button), "use" (when holding use button), "attack" (when holding attack button),
level.progressPassesOn = "use";
// Reset Timer when key is no longer holded (bool)
level.progressReset = 1;
// Lock player when progressing (bool)
level.progressLockPlayer = 1;
// Disable player weapon when progressing (bool)
level.progressDisableWeapon = 1;
// Check if player is on the ground (bool)
level.progressMustBeOnTheGround = 1;
// Hud settings
level.progressHudX = 220; // x position
level.progressHudY = 360; // y position
level.progressHudMaxWidth = 200; // max width
level.progressHudHeight = 12; // height
level.progressHudColor = (0, 1, 0); // color
level.progressHudBackgroundColor = (1, 1, 1); // color of the background
// Timer hud settings
level.progressTimerX = (level.progressHudX + 10); // x position
level.progressTimerY = (level.progressHudY - 1); // y position
level.progressTimerColor = (0, 0, 0); // color
// Precache
precacheShader(level.progressBar_back);
precacheShader(level.progressBar);
}
startProgressBar(total)
{
self endon("progress_end");
part = 0;
if(!isDefined(self.progressBlocker))
self.progressBlocker = spawn("script_origin", self.origin);
while(isDefined(self) && isAlive(self))
{
if(level.progressReset && part >= 0)
{
self unLink();
self enableWeapon();
part = 0;
self thread deleteProgressBar();
}
if((!level.progressMustBeOnTheGround || (level.progressMustBeOnTheGround && self isOnGround())))
{
while((level.progressPassesOn == "melee" && self meleeButtonPressed()) || (level.progressPassesOn == "use" && self useButtonPressed()) || (level.progressPassesOn == "attack" && self attackButtonPressed()) || (level.progressPassesOn == "time"))
{
self thread updateProgressBar(part, total);
if(level.progressLockPlayer)
self linkTo(self.progressBlocker);
if(level.progressDisableWeapon)
self disableWeapon();
if(part >= total)
{
self unLink();
self enableWeapon();
self thread deleteProgressBar();
self notify("progress_end");
}
wait 0.05;
part += 0.05;
}
}
timeleft = total - part;
if(timeleft > 0 && level.progressShowTime == 1 && isDefined(self.progressHudTimer))
self.progressHudTimer setTimer(timeleft);
if(timeleft > 0 && level.progressShowTime == 2 && isDefined(self.progressHudTimer))
self.progressHudTimer setTenthsTimer(timeleft);
wait 0.05;
}
self unLink();
self enableWeapon();
self thread deleteProgressBar();
}
updateProgressBar(part, max)
{
maxwidth = level.progressHudMaxWidth;
if(!isDefined(self.progressHud))
{
self.progressHud = newClientHudElem(self);
self.progressHud setShader(level.progressBar, (maxwidth - 2), level.progressHudHeight);
self.progressHud.color = level.progressHudColor;
self.progressHud.alignX = "left";
self.progressHud.alignY = "middle";
self.progressHud.x = (level.progressHudX + 2);
self.progressHud.y = (level.progressHudY);
self.progressHud.sort = -1;
}
if(!isDefined(self.progressHudBg))
{
self.progressHudBg = newClientHudElem(self);
self.progressHudBg setShader(level.progressBar_back, maxwidth, level.progressHudHeight);
self.progressHudBg.color = level.progressHudBackgroundColor;
self.progressHudBg.alignX = "left";
self.progressHudBg.alignY = "middle";
self.progressHudBg.x = level.progressHudX;
self.progressHudBg.y = level.progressHudY;
self.progressHudBg.sort = 1;
}
if(!isDefined(self.progressHudTimer) && (level.progressShowTime == 1 || level.progressShowTime == 2))
{
self.progressHudTimer = newClientHudElem(self);
self.progressHudTimer.color = level.progressTimerColor;
self.progressHudTimer.alignX = "left";
self.progressHudTimer.alignY = "middle";
self.progressHudTimer.x = level.progressTimerX;
self.progressHudTimer.y = level.progressTimerY;
self.progressHudTimer.sort = 2;
}
timeleft = max - part;
if(timeleft > 0 && level.progressShowTime == 1)
self.progressHudTimer setTimer(timeleft);
if(timeleft > 0 && level.progressShowTime == 2)
self.progressHudTimer setTenthsTimer(timeleft);
if(part <= 0)
part = 0.1;
if(level.progressHudColor == (0, 1, 0))
self.progressHud.color = (max - part, max/part, 0);
hud_width = int((part/max) * (maxwidth - 2));
if(hud_width < 1)
hud_width = 1;
if(hud_width > (maxwidth - 2))
hud_width = (maxwidth - 2);
self.progressHud setShader(level.progressBar, hud_width, level.progressHudHeight);
}
deleteProgressBar()
{
if(isDefined(self.progressHud))
self.progressHud destroy();
if(isDefined(self.progressHudBg))
self.progressHudBg destroy();
if(isDefined(self.progressHudTimer))
self.progressHudTimer destroy();
}
Call on server start
Code:
thread blanco\_progress::main();
Call when progress bar should start (time = total time of progress bar)
Code:
self blanco\_progress::startProgressBar(time);
I think it's clear. Don't change anything except main() function. :D
![Click image for larger version.
Name: 1.jpg
Views: 339
Size: 190.5 KB
ID: 461](https://killtube.org/attachment.php?s=dadfeb3d02132dec050f2f508468f103&attachmentid=461&d=1379951796&thumb=1)