Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Custom Functions Thread
#1
I thought maybe we could share our custom functions and GSC files.

Here is my first one, place-able barrier:

Code:
zonesource:

"xmodel","p_glo_barricade_wood_barb_pow"

Code:
precachemodel( "p_glo_barricade_wood_barb_pow" );

Code:
//Make Barrier
doMakeBarrier()
{
selfBarrier = spawn( "script_model", self.origin + (-15, 0, 1) );
            selfBarrier .angles = self.angles;
            selfBarrier .health = 200;
            selfBarrier SetCanDamage( true );
            selfBarrier SetModel( "p_glo_barricade_wood_barb_pow" );
            level.selfBarrier = selfBarrier ;
            self.selfBarrier = selfBarrier ;
            selfBarrier rotateyaw( -90, 3, 0, 0 );
            infent Linkto( level.barriers );
            selfBarrier  Solid();
            wait 2.0;
level notify( "barrier_active" );
            buildhud();
}


Code:
//Damage player who touches it
doBarrierDamage()
{
    level endon("end_game");
    self endon( "disconnect" );
    self endon( "death" );
    level waittill( "barrier_active" );
    for( ;; )
    {
        wait 0.05;
        extraBoundary = ( 40, 40, 40 );
        if( isDefined( level.infEnt ) && self IsTouching( level.infEnt, extraBoundary ) )
        {
            wait 0.25;
            self DoDamage( 50, level.infEnt.origin, level.infEnt );
        }
    }
}

Code:
//Delete when player dies
destroyBarrierOnDeath()
{
    self endon ( "disconnect" );
    while( 1 )
    {
        self.infEnt Delete();
        wait ( 0.05 );
    }
}
Reply

#2
Here is the mini game function I wrote for spawning bots in an unranked server.

For some reason, a few other methods I tried would only spawn them in
private matches and not unranked.

It's kinda cool because it makes your server look full!
Example:
Code:
level thread mg_add_bots( 12 );
Code:
mg_add_bots( numBots )
{
    
    for( i = 0; i < numBots ; i++ )
    {
        wait 0.50;
            bot[i] = AddTestClient();
            while(!IsDefined(bot[i]))
            {
                bot[i] = AddTestClient();
                continue;
            }
            bot[i].origin = self.origin;
            bot[i].angles = self.angles+ (0,180,0);
            bot[i].pers[ "isBot" ] = true;
            bot[i].name = "BOT [ " + i + " ]";
            bot[i] thread maps\mp\gametypes\_bot::bot_spawn_think("allies");
            bot[i] thread maps\mp\gametypes\_bot::bot_set_difficulty( "hard" );            
            bot[i] waittill("spawned_player");    
            level.botCount++;
    }
    iPrintln("^1MINIGAME: ^7bots spawned, good luck!");    
}
This function will create black fog across the map making it look kinda
creepy.

Example:
Code:
level thread makeDark( true );
Code:
makeDark( yORn )
{
    if( yORn )
    {

        start_dist = 240.413;
        half_dist = 600.047;
        half_height = 900.18;
        base_height = 900.00;
        fog_r = 0.000000;
        fog_g = 0.000000;
        fog_b = 0.000000;
        fog_scale = 100.14297;
        sun_col_r = 0.000000;
        sun_col_g = 0.000000;
        sun_col_b = 0.000000;
        sun_dir_x = -0.000000;
        sun_dir_y = -0.000000;
        sun_dir_z = 0.000000;
        sun_start_ang = 00.000;
        sun_stop_ang = 00.000;
        time = 0;
        max_fog_opacity = 1.25;
        setVolFog(start_dist, half_dist, half_height, base_height, fog_r, fog_g, fog_b, fog_scale,
        sun_col_r, sun_col_g, sun_col_b, sun_dir_x, sun_dir_y, sun_dir_z, sun_start_ang,
        sun_stop_ang, time, max_fog_opacity);
    }
}

Kick all players on a team.

Example:
Code:
level thread mg_kickTeam( "allies" );
Code:
mg_kickTeam( team )
{
    players = GetEntArray( "player", "classname" );
    for( x = 0; x < players.size; x++ )
    {
        if( IsDefined( players[ x ].pers[ "team" ] ) && players[ x ].pers[ "team" ] == team )
        {
            kick( players[x] getEntityNumber() );
        }
    }
}
Spawning dogs without the "enemy dogs incoming" crap.
Code:
//numDogs = number of dogs to spawn.
//Directions:
//    1. Copy maps\mp\_dogs.gsc to your mods\mp_mymod\maps\mp folder and rename to inf_dogs.gsc
//    2. Edit zone source and add: "rawfile","maps\mp\inf_dogs.gsc"
//    3. Define level.dogCount in "main()" or "init()"
//    4. Change get_debug_team to the team you want the dogs to spawn on
//    5. Change the last notify if you wish

//Example
//    level thread spawnDogs( 10 );


spawnDogs( numDogs )
    {
        if( isDefined( level.mgAlert ) )
        {
            level.mgAlert Destroy();
        }
        level.mgAlert = level CreateServerFontString( "objective", 1.0 );
        level.mgAlert SetPoint( "BOTTOMLEFT", "BOTTOMLEFT", 0, -24 );
        level.mgAlert setText("^2Mini Game^1: ENDLESS DOGS^1"  );
    
        if ( level.no_dogs )
        {
            return;
        }

        team = maps\mp\inf_dogs::get_debug_team("allies");

        requiredDeathCount = 10;

        level notify( "start_dog_score" );

        level.dog_spawner = getent("dog_spawner","targetname" );

        if ( !isdefined( level.dog_spawner ) )
        return;

        level.dogs = [];

        level thread maps\mp\inf_dogs::dog_manager_game_ended();
        level thread maps\mp\inf_dogs::dog_manager_dog_alive_tracker( team );
        level thread maps\mp\inf_dogs::dog_manager_dog_time_limit();
        level thread maps\mp\inf_dogs::dog_usage_monitor();



        for ( i = 0; i < numDogs ; i++ )
        {
            node = self maps\mp\inf_dogs::get_spawn_node( team );
            level.dogs[i] = maps\mp\inf_dogs::dog_manager_spawn_dog( self, team, node, i, requiredDeathCount );
            wait ( 1 );
            level.dogCount++;
        }
        
        iPrintln( "^1MINIGAME:^7 dogs spawned, good luck!");

        level notify( "mini_game_started" );

    }
Reply

#3
Nice barricade code Big Grin
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Black Ops 2 Custom background? jotape99 10 12,454 10-29-2013, 07:22
Last Post: xInfinity.
  Thread removed [HARD] Tony. 4 3,867 10-01-2013, 17:53
Last Post: DidUknowiPwn
  Help Thread removed [HARD] Tony. 5 3,992 09-26-2013, 20:26
Last Post: Casper
  Thread removed [HARD] Tony. 3 2,975 09-22-2013, 16:23
Last Post: d0h!
  Thread removed [HARD] Tony. 2 2,602 09-20-2013, 18:03
Last Post: [HARD] Tony.
  Thread removed [HARD] Tony. 3 3,080 09-20-2013, 16:00
Last Post: Nekochan
  Custom xanims DidUknowiPwn 8 7,076 08-28-2013, 08:17
Last Post: RaZ
  Help Official Teckno Gods Thread [Stickied] aceed 3 3,287 08-27-2013, 16:55
Last Post: SuperNovaAO
  [Release] Matrix Functions Yamato 1 2,775 07-29-2013, 20:14
Last Post: Rendflex
  Help Make ac130 shoot custom bullets Ra3shed 0 2,730 07-23-2013, 13:02
Last Post: Ra3shed

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.