[Resource] Showing my gsc mod to help beginners

Topic created · 1 Posts · 51 Views
  • Hey, I've gone through the trouble of learning some gsc. It's fun to see when things are working ingame, but it's tedious to figure out what functions exist and how they are used. So I'm going to release this mod to the public so the next person after me has more simple examples to lead them. I think my code is helpful for someone who already understands gsc keywords and basic programming and is now searching for simple code examples.

    The mod was used on Aspire ffa sniping server. You can take whatever parts you find useful and put it in your mod.

    The mod contains code that:

    • Puts a simple text on the screen which is useful for showing a discord link.
    • Displays the players' current killstreak at the bottom.
    • Calculates the time and accuracy of the FFA winner, then displays this at the end of the game. Was used for keeping track of the fastest FFA wins.
    /*
    * Author: ColouRz
    * Version: 1.2
    * Last updated: 6 October 2021
    * Game: Modern Warfare 3
    *
    * Displays the playtime and accuracy of the winner. Made for FFA.
    * Displays currently best time.
    * Displays website and discord links.
    * Displays current killstreak as a text in the bottom of each player's screen.
    *
    * Changelog:
    *
    * 1.2: Added killstreak text at bottom of screen.
    *
    * 1.1: Added accuracy of winner at end of game.
    * Fixed bug of playtimer not starting if player connected after game started.
    * Notes: Currently hardcoded for a kill limit of 100.
    * Known bugs: Hitmarkers counts as misses. If the player connected after the game started, but no one has made a kill yet, the playtimer does not start.
    *
    */
    
    #include maps\mp\gametypes\_hud_util; // For createFontString
    
    init()
    {
        level thread onplayerconnect();
    	highscore_text();
    	info_text();
    	thread winner_text();
    	level waittill("prematch_over");
    	level.callbackPlayerKilled = ::Callback_PlayerKilled;
    }
    
    onplayerconnect()
    {
        for(;;)
        {
            level waittill("connected", player);
    		player thread playtimer();
    		player thread wait_start1();
    		player thread wait_start2();
    		player thread wait_start3();
    		player thread shots_counter();
    		killstreak_text = player createFontString("Objective",1);
    		killstreak_text setPoint("CENTER","BOTTOM",0,-10);
    		player thread onplayerspawned(killstreak_text);
        }
    }
    
    onplayerspawned(killstreak_text)
    {
        self endon("disconnect");
        for(;;)
        {
            self waittill("spawned_player");
    		self thread killstreak_counter(killstreak_text);
    	}
    }
    
    wait_start1() // starts timer if spawned in before countdown
    {
    	self endon("disconnect");
    	self endon("game_ended");
    	self endon("started_playing");
    	
    	self waittill( "spawned_player");
    	level waittill("prematch_over");
    	self notify("started_playing");
    }
    
    wait_start2() // starts timer if spawned in after countdown 
    {
    	self endon("disconnect");
    	self endon("game_ended");
    	self endon("started_playing");
    	
    	level waittill( "prematch_over");
    	self waittill( "spawned_player");
    	self notify("started_playing");
    }
    
    wait_start3() // starts timer if joined server after game started
    {
    	self endon("disconnect");
    	self endon("game_ended");
    	self endon("started_playing");
    	
    	leader = maps\mp\gametypes\_gamescore::getHighestScoringPlayer();
    	if(isDefined(leader.kills) && leader.kills > 0)
    	{
    		self waittill("spawned_player");
    		self notify("started_playing");
    	}
    }
    
    playtimer()
    {
    	self endon("disconnect");
    	
    	self waittill("started_playing");
    	self.starttime = gettime();
    	
    	level waittill("game_ended");
    	self.endtime = gettime();
    	self.playtime = self.endtime - self.starttime;
    	
    	totalseconds = floor(self.playtime / 1000);
    	self.minutes = floor(totalseconds / 60);
    	self.seconds = totalseconds - self.minutes*60;
    	
    }
    
    shots_counter()
    {
    	self endon("disconnect");
    	level endon("game_ended");
    	
    	self.shots = 0;
    	while(true)
    	{
    		self waittill("weapon_fired");
    		self.shots++;
    	}
    }
    
    killstreak_counter(killstreak_text)
    {
    	self endon("death");
    	self endon("disconnect");
    	level endon("game_ended");
    	
    	killstreak_text setText("Killstreak: 0");
    	while(true)
    	{
    		self waittill("kill");
    		killstreak_text setText("Killstreak: " + self.pers["cur_kill_streak"]);
    	}
    	
    }
    
    
    winner_text()
    {
    	level waittill("game_ended");
    	wait 0.05;
    	
    	winner = maps\mp\gametypes\_gamescore::getHighestScoringPlayer();
    	killlimit = 100;
    	winner_name = level createServerFontString( "Objective", 1 );
    	winner_name setPoint( "LEFT", "LEFT", 0, 0 );
    	winner_name setText("^2WINNER: " + winner.name + " won in " + winner.minutes + " min "+winner.seconds+" sec\n"
    						+ winner.name + "'s accuracy was " + floor((killlimit / winner.shots)*1000)/10 + " percent");
    }
    
    highscore_text()
    {
    	highscore = level createServerFontString( "Objective", 0.5 );
    	highscore setPoint( "RIGHT", "RIGHT", 0, -100 );
    	highscore.hideWhenInMenu = true;
    	
    	mapname = getDvar("mapname");
    
    	if(mapname == "mp_rust")
    	{
    		highscore setText("^2FASTEST WIN RUST\nEoJz: 5:13");
    	}
    	else if(mapname == "mp_dome")
    	{
    		highscore setText("^2FASTEST WIN DOME\nEoJz: 6:24");
    	}
    	
    }
    
    info_text()
    {
    	discord = level createServerFontString( "Objective", 0.5 );
    	discord setPoint( "RIGHT", "RIGHT", 0, -110 );
    	discord setText("^5discord: link here");
    	website = level createServerFontString( "Objective", 0.5 );
    	website setPoint( "RIGHT", "RIGHT", 0, -120 );
    	website setText("^5stats: iw4madmin webfront here");
    }
    
    Callback_PlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
    {
    	attacker notify("kill");
    	self maps\mp\gametypes\_damage::Callback_PlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration );
    }
    
    
    debug(text)
    {
    	self iPrintLnBold(text);
    	wait 1;
    }
    
Log in to reply