Release Useful GSC Functions (Checks, waits, etc)

The Dark Side

Former Staff Member
Messages
1,007
Points
568
I found this batch of GSC functions on pastebin by Duffman. This guy was obviously an extremely talented coder. I've never seen codes like his before. Either way, they should be shared with the community.

These can be used with any COD as long as it supports gsc. The syntax may have to be adjusted a tad bit though. If anybody else has some useful functions like these let me know, and i will add them. :smile:

Have a great day!
Dark side.
Code:
/*

////////Tools To Use\\\\\\\\\\
Cleanscreen(); Cleans the screen of iPrintlns and iPrintlnbolds.

showDelayText(text, delaytime); iPrints text after a delay.

playSoundOnAllPlayers(sound); Plays a sound on ALL players.

lockOrigin(); Locks your origin, you cannot move.

unlockOrigin(); Unlocks your origin, if you were previously locked you can now move.

SoundOnOrigin(sound,origin); Plays a sound on an origin.

isRealyAlive(); check for being alive, if the sessionstate is valid and you're playing, and if your health is defined.

fadeOut(time); fade to out on a HUD. time for how long it takes to fade it.

fadeIn(time); fade to in on a HUD. time for how long it takes to fade it.

DestroyOn(act1,act2,act3,act4); Destroy something on notify, 4 max.

DeleteOn(act1,act2,act3,act4); Delete something on notify, 4 max.

RemoveBots(); Kicks all bots from the game.(i edited this one a bit)

AddBlocker(origin,radius,height); Adds a blocker on the origin,radius,and height that are defined.

isHex(value); Check if a value is hex or not. (Dont know a use for this one, but its neato!)

setPlayerHealth(health); Sets the player health to what you want.

waitTillNotMoving(); Has a wait until you aren't moving.

waitForPlayers(); Has a wait until all players are spawned in and playing.

isWallbang(); Check for if you wallbang somebody (shoot them through a wall)

*/
Code:
CleanScreen()
{
    for(i=0;i<10;i++)
    {
        iPrintlnbold(" ");
        iPrintln(" ");
    }
}
Code:
showDelayText(text,delay)
{
    wait delay;
    iPrintln(text);
}
Code:
playSoundOnAllPlayers( soundAlias )
{
    foreach(player in level.players)
              player playLocalSound(soundAlias);
}
Code:
lockOrigin()
{
        if(isDefined(self.temp_linker))
                self.temp_linker delete();
        self.temp_linker = spawn( "script_model", self.origin );
        self linkTo(self.temp_linker);
}
unlockOrigin()
{
        self unlink();
        if(isDefined(self.temp_linker))
                self.temp_linker delete();
}
Code:
isHex(value) {
        if(isDefined(value) && value.size == 1)
                return (value == "a" || value == "b" || value == "c" || value == "d" || value == "e" || value == "f" || value == "0" || value == "1" || value == "2" || value == "3" || value == "4" || value == "5" || value == "6" || value == "7" || value == "8" || value == "9");
        else if(isDefined(value))
                for(i=0;i<value.size;i++)
                        if(!isHex(value[i]))
                                return false;
        return true;
}
Code:
SoundOnOrigin(alias,origin)
{
        soundPlayer = spawn( "script_origin", origin );
        soundPlayer playsound( alias );
        wait 10;
        soundPlayer delete();
}
Code:
isRealyAlive()
{
    return self.pers["team"] != "spectator" && self.health && self.sessionstate == "playing";
}
Code:
fadeOut(time) {
        if(!isDefined(self)) return;
        self fadeOverTime(time);
        self.alpha = 0;
        wait time;
        if(!isDefined(self)) return;
        self destroy();
}
fadeIn(time) {
        alpha = self.alpha;
        self.alpha = 0;
        self fadeOverTime(time);
        self.alpha = alpha;
}
Code:
DestroyOn(act1,act2,act3,act4)
{
        self endon("death");
        self endon("disconnect");
        self waittill_any(act1,act2,act3,act4);
        self destroy();
}
Code:
DeleteOn(act1,act2,act3,act4)
{
        self endon("death");
        self endon("disconnect");
        self waittill_any(act1,act2,act3,act4);
        self delete();
}
Code:
RemoveBots()
{
    foreach(player in level.players)
    {
        if(isDefined(player.pers["isBot"])&& player.pers["isBot"])
        kick(player getEntityNumber(),"EXE_PLAYERKICKED");
    }
    CleanScreen(); //uses cleanscreen, make sure you have this function!
}
Code:
AddBlocker(origin,radius,height) {
        blocker = spawn("trigger_radius", origin,0, radius,height);
        blocker setContents(1);
        return blocker;
}
Code:
setPlayerHealth(health)
{
        self notify("end_healthregen");
        self.maxhealth = health;
        self.health = self.maxhealth;
        self setnormalhealth(self.health);
        self thread playerHealthRegen();
}
Code:
waitTillNotMoving()
{
    prevorigin = self.origin;
    while( isDefined( self ) )
    {
        wait .15;
        if ( self.origin == prevorigin )
            break;
        prevorigin = self.origin;
    }
}
Code:
waitForPlayers( requiredPlayersCount )
{
    quit = false;
    while( !quit )
    {
        wait 0.5;
        count = 0;
        foreach(player in level.players)
        {
            if( player isPlaying() )
                count++;
        }

        if( count >= requiredPlayersCount )
            break;
    }
}
Code:
isWallBang( attacker, victim )
{
    return !bulletTracePassed( attacker getEye(), victim getEye(), false, attacker );
}

Changelog: 8/12/17 - Added isWallbang. Had to add it when i saw it.
 
Last edited:

vRice

Well-Known Member
Messages
57
Points
218
You got a link to his pastebin? I wanna see these talented codes :wink:

This should help a couple of people too which is nice
 

The Dark Side

Former Staff Member
Messages
1,007
Points
568
we have already a function isAlive( self )
The older cods do not. isRealyAlive was made for cod4.. the isHost() check didn't exist then either. You gotta do something like

Code:
isHost()
{
     return self getentititynumber() == 0;
}
Something like that lol
 

SCP

Moderator
Staff member
Donator
Messages
389
Points
273
I found this batch of GSC functions on pastebin by Duffman. This guy was obviously an extremely talented coder. I've never seen codes like his before. Either way, they should be shared with the community.

These can be used with any COD as long as it supports gsc. The syntax may have to be adjusted a tad bit though. If anybody else has some useful functions like these let me know, and i will add them. :smile:

Have a great day!
Dark side.
Code:
/*

////////Tools To Use\\\\\\\\\\
Cleanscreen(); Cleans the screen of iPrintlns and iPrintlnbolds.

showDelayText(text, delaytime); iPrints text after a delay.

playSoundOnAllPlayers(sound); Plays a sound on ALL players.

lockOrigin(); Locks your origin, you cannot move.

unlockOrigin(); Unlocks your origin, if you were previously locked you can now move.

SoundOnOrigin(sound,origin); Plays a sound on an origin.

isRealyAlive(); check for being alive, if the sessionstate is valid and you're playing, and if your health is defined.

fadeOut(time); fade to out on a HUD. time for how long it takes to fade it.

fadeIn(time); fade to in on a HUD. time for how long it takes to fade it.

DestroyOn(act1,act2,act3,act4); Destroy something on notify, 4 max.

DeleteOn(act1,act2,act3,act4); Delete something on notify, 4 max.

RemoveBots(); Kicks all bots from the game.(i edited this one a bit)

AddBlocker(origin,radius,height); Adds a blocker on the origin,radius,and height that are defined.

isHex(value); Check if a value is hex or not. (Dont know a use for this one, but its neato!)

setPlayerHealth(health); Sets the player health to what you want.

waitTillNotMoving(); Has a wait until you aren't moving.

waitForPlayers(); Has a wait until all players are spawned in and playing.

*/
Code:
CleanScreen()
{
    for(i=0;i<10;i++)
    {
        iPrintlnbold(" ");
        iPrintln(" ");
    }
}
Code:
showDelayText(text,delay)
{
    wait delay;
    iPrintln(text);
}
Code:
playSoundOnAllPlayers( soundAlias )
{
    foreach(player in level.players)
              player playLocalSound(soundAlias);
}
Code:
lockOrigin()
{
        if(isDefined(self.temp_linker))
                self.temp_linker delete();
        self.temp_linker = spawn( "script_model", self.origin );
        self linkTo(self.temp_linker);
}
unlockOrigin()
{
        self unlink();
        if(isDefined(self.temp_linker))
                self.temp_linker delete();
}
Code:
isHex(value) {
        if(isDefined(value) && value.size == 1)
                return (value == "a" || value == "b" || value == "c" || value == "d" || value == "e" || value == "f" || value == "0" || value == "1" || value == "2" || value == "3" || value == "4" || value == "5" || value == "6" || value == "7" || value == "8" || value == "9");
        else if(isDefined(value))
                for(i=0;i<value.size;i++)
                        if(!isHex(value[i]))
                                return false;
        return true;
}
Code:
SoundOnOrigin(alias,origin)
{
        soundPlayer = spawn( "script_origin", origin );
        soundPlayer playsound( alias );
        wait 10;
        soundPlayer delete();
}
Code:
isRealyAlive()
{
    return self.pers["team"] != "spectator" && self.health && self.sessionstate == "playing";
}
Code:
fadeOut(time) {
        if(!isDefined(self)) return;
        self fadeOverTime(time);
        self.alpha = 0;
        wait time;
        if(!isDefined(self)) return;
        self destroy();
}
fadeIn(time) {
        alpha = self.alpha;
        self.alpha = 0;
        self fadeOverTime(time);
        self.alpha = alpha;
}
Code:
DestroyOn(act1,act2,act3,act4)
{
        self endon("death");
        self endon("disconnect");
        self waittill_any(act1,act2,act3,act4);
        self destroy();
}
Code:
DeleteOn(act1,act2,act3,act4)
{
        self endon("death");
        self endon("disconnect");
        self waittill_any(act1,act2,act3,act4);
        self delete();
}
Code:
RemoveBots()
{
    foreach(player in level.players)
    {
        if(isDefined(player.pers["isBot"])&& player.pers["isBot"])
        kick(player getEntityNumber(),"EXE_PLAYERKICKED");
    }
    CleanScreen(); //uses cleanscreen, make sure you have this function!
}
Code:
AddBlocker(origin,radius,height) {
        blocker = spawn("trigger_radius", origin,0, radius,height);
        blocker setContents(1);
        return blocker;
}
Code:
setPlayerHealth(health)
{
        self notify("end_healthregen");
        self.maxhealth = health;
        self.health = self.maxhealth;
        self setnormalhealth(self.health);
        self thread playerHealthRegen();
}
Code:
waitTillNotMoving()
{
    prevorigin = self.origin;
    while( isDefined( self ) )
    {
        wait .15;
        if ( self.origin == prevorigin )
            break;
        prevorigin = self.origin;
    }
}
Code:
waitForPlayers( requiredPlayersCount )
{
    quit = false;
    while( !quit )
    {
        wait 0.5;
        count = 0;
        foreach(player in level.players)
        {
            if( player isPlaying() )
                count++;
        }

        if( count >= requiredPlayersCount )
            break;
    }
}
Nice thread! Quite useful functions. :y:
 
Top