Results 1 to 7 of 7

Thread: +1 standalone script

  1. #1
    ... connecting
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    2
    Thanked 1 Time in 1 Post

    +1 standalone script

    Hi everyone. It's the first time i'm writing a script for COD2 but i've some experience in programming: basically what i'm trying to add to my mod is the +1 indicator like Extreme mod when you kill a player. I've looked at Extreme mod but i have no idea how it does such a thing (i cannot find anything about it ). Can you give me some suggestion? My idea is to integrate some stuff into PAM mod to make it a little bit more fun.

    Thank you

  2. The Following User Says Thank You to idan For This Useful Post:

    kung foo man (20th April 2020)

  3. #2
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    In the maps/mp/gametypes/_callbacksetup.gsc call the init():

    PHP Code:
    CodeCallback_StartGameType()
    {
        
    // If the gametype has not beed started, run the startup
        
    if(!isDefined(level.gametypestarted) || !level.gametypestarted)
        {
            [[
    level.callbackStartGameType]]();

            
    level.gametypestarted true// so we know that the gametype has been started up
        
    }

        
    setcvar("scr_testclients" );
        
    thread maps\mp\gametypes\_teams::addTestClients(); // bots for testing only

        
    maps\mp\gametypes\_scorepopup::init(); // <-------------------------

    Create a file in maps/mp/gametypes called _scorepopup.gsc and add IzNoGod's code (https://killtube.org/showthread.php?1208-plusscore):

    PHP Code:
    // See: https://killtube.org/showthread.php?1208-plusscore

    init()
    {
        
    precachestring(&"");
        
    precachestring(&"+");
        
    game["precached_plusscore_strings"] = true;
    }

    OnPlayerKilledattacker victim sMeansOfDeath sHitLoc )
    {
        
    score 10;

        if( !
    isDefinedattacker ) || !isDefinedvictim ) )
            return;
        else if( !
    isPlayerattacker ) || !isPlayervictim ) )
            return;
        else if( 
    attacker == victim )
            return;

        if( 
    isDefinedsMeansOfDeath ) && isDefinedsHitLoc ) )
        {
            if( 
    sHitLoc == "head" && sMeansOfDeath != "MOD_MELEE" )
                
    sMeansOfDeath "MOD_HEAD_SHOT";

            if( 
    sMeansOfDeath == "MOD_HEAD_SHOT" )
                
    score 50;
            else if( 
    sMeansOfDeath == "MOD_MELEE" )
                
    score 25;
        }

        if( 
    isDefinedattacker.pers"team" ] ) &&
            
    isDefinedvictim.pers"team" ] ) &&
            
    attacker.pers"team" ] == victim.pers"team" ] &&
            
    getcvar"g_gametype" ) != "dm" )
        {
            
    score *= -1;
        }

        if( 
    score score += 1;
        else                 
    score -= 1;

        
    attacker.score += score;

        
    attacker thread plusscorescore );
    }


    plusscore(score)
    {
        if(!
    isdefined(game["precached_plusscore_strings"]))
        {
            
    iprintln("Plusscore strings not precached. Call init() on startgametype...");
            return;
        }
        if(!
    isplayer(self))
        {
            
    iprintln("Plusscore not called on a player. Go fix this before you try anything else!");
            return;
        }
        if(!
    isdefined(self.izno_plusscore)) //first run
        
    {
            
    self.izno_plusscore newclienthudelem(self);
            
    self.izno_plusscore.instance 0;
            
    self.izno_plusscore.score score;
            
    self.izno_plusscore.horzAlign "center";
            
    self.izno_plusscore.vertAlign "middle";
            
    self.izno_plusscore.alignX "center";
            
    self.izno_plusscore.alignY "middle";
            
    self.izno_plusscore.0//middle of screen
            
    self.izno_plusscore.= -40//just above middle of screen
            
    self.izno_plusscore.alpha 0.3;
            
    self.izno_plusscore.fontscale 0.5;
        }
        else 
    //not first-run
        
    {
            if(
    self.izno_plusscore.alpha 0.3 || self.izno_plusscore.score == 0)
                
    self.izno_plusscore.alpha 0.3;
            if(
    self.izno_plusscore.fontscale 0.5 || self.izno_plusscore.score == 0)
                
    self.izno_plusscore.fontscale 0.5;
            
    self.izno_plusscore.instance++;
            
    self.izno_plusscore.score += score;
        }
        if(
    self.izno_plusscore.score 0)
        {
            
    self.izno_plusscore.color = (235/255,10/255,10/255); //negative scores are red
            
    self.izno_plusscore.label = &"";
        }
        else
        {
            
    self.izno_plusscore.color = (1,230/255,125/255); //yellow-ish
            
    self.izno_plusscore.label = &"+";
        }
        
    self.izno_plusscore setvalue(self.izno_plusscore.score);    

        
    current_instance self.izno_plusscore.instance;
        
    make_bigger true;
        
    more_opaque true;
        
    steady_opaque_timer 0;
        
    alpha_done false;
        
    size_done false;
        while(
    isdefined(self) && current_instance == self.izno_plusscore.instance && !(alpha_done && size_done))
        {
            if(
    make_bigger && self.izno_plusscore.fontscale 2)
                
    self.izno_plusscore.fontscale += 0.35;
            else if(
    make_bigger)
                
    make_bigger false;
            else if(
    self.izno_plusscore.fontscale 2)
                
    self.izno_plusscore.fontscale -= 0.2;
            else
            {
                
    size_done true;
                
    self.izno_plusscore.fontscale 1.5;
            }

            if(
    more_opaque && self.izno_plusscore.alpha <= 0.9//dont overflow this
                
    self.izno_plusscore.alpha += 0.1;
            else if(
    more_opaque && steady_opaque_timer == 20)
                
    more_opaque false;
            else if(
    more_opaque)
                
    steady_opaque_timer++;
            else if(
    self.izno_plusscore.alpha >= 0.1//dont underflow this
                
    self.izno_plusscore.alpha -= 0.1;
            else
            {
                
    alpha_done true;
                
    self.izno_plusscore.alpha 0;
            }
            
    wait 0.05;
        }
        if(!
    isdefined(self))
            return;
        if(
    current_instance == self.izno_plusscore.instance)
        {
            
    wait 0.5;
            if(
    isdefined(self) && self.izno_plusscore.instance == current_instance)
                
    self.izno_plusscore.score 0;
        }

    Call the scorepopup on every kill in the _callbacksetup::CallBack_OnPlayerKilled() (insert this function call as the last line):

    PHP Code:
    level thread maps\mp\gametypes\_scorepopup::OnPlayerKilledeAttacker self sMeansOfDeath sHitLoc ); 
    Here is how you setup CoD2 for your own mod: https://youtu.be/9-n75APn81g or just edit the Pam mod yourself
    Last edited by serthy; 14th April 2020 at 13:31.

  4. The Following 2 Users Say Thank You to serthy For This Useful Post:

    idan (14th April 2020),kung foo man (20th April 2020)

  5. #3
    ... connecting
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    2
    Thanked 1 Time in 1 Post

    Cool

    Quote Originally Posted by serthy View Post
    In the maps/mp/gametypes/_callbacksetup.gsc call the init():

    PHP Code:
    CodeCallback_StartGameType()
    {
        
    // If the gametype has not beed started, run the startup
        
    if(!isDefined(level.gametypestarted) || !level.gametypestarted)
        {
            [[
    level.callbackStartGameType]]();

            
    level.gametypestarted true// so we know that the gametype has been started up
        
    }

        
    setcvar("scr_testclients" );
        
    thread maps\mp\gametypes\_teams::addTestClients(); // bots for testing only

        
    maps\mp\gametypes\_scorepopup::init(); // <-------------------------

    Create a file in maps/mp/gametypes called _scorepopup.gsc and add IzNoGod's code (https://killtube.org/showthread.php?1208-plusscore):

    PHP Code:
    // See: https://killtube.org/showthread.php?1208-plusscore

    init()
    {
        
    precachestring(&"");
        
    precachestring(&"+");
        
    game["precached_plusscore_strings"] = true;
    }

    OnPlayerKilledattacker victim sMeansOfDeath sHitLoc )
    {
        
    score 10;

        if( !
    isDefinedattacker ) || !isDefinedvictim ) )
            return;
        else if( !
    isPlayerattacker ) || !isPlayervictim ) )
            return;
        else if( 
    attacker == victim )
            return;

        if( 
    isDefinedsMeansOfDeath ) && isDefinedsHitLoc ) )
        {
            if( 
    sHitLoc == "head" && sMeansOfDeath != "MOD_MELEE" )
                
    sMeansOfDeath "MOD_HEAD_SHOT";

            if( 
    sMeansOfDeath == "MOD_HEAD_SHOT" )
                
    score 50;
            else if( 
    sMeansOfDeath == "MOD_MELEE" )
                
    score 25;
        }

        if( 
    isDefinedattacker.pers"team" ] ) &&
            
    isDefinedvictim.pers"team" ] ) &&
            
    attacker.pers"team" ] == victim.pers"team" ] &&
            
    getcvar"g_gametype" ) != "dm" )
        {
            
    score *= -1;
        }

        if( 
    score score += 1;
        else                 
    score -= 1;

        
    attacker.score += score;

        
    attacker thread plusscorescore );
    }


    plusscore(score)
    {
        if(!
    isdefined(game["precached_plusscore_strings"]))
        {
            
    iprintln("Plusscore strings not precached. Call init() on startgametype...");
            return;
        }
        if(!
    isplayer(self))
        {
            
    iprintln("Plusscore not called on a player. Go fix this before you try anything else!");
            return;
        }
        if(!
    isdefined(self.izno_plusscore)) //first run
        
    {
            
    self.izno_plusscore newclienthudelem(self);
            
    self.izno_plusscore.instance 0;
            
    self.izno_plusscore.score score;
            
    self.izno_plusscore.horzAlign "center";
            
    self.izno_plusscore.vertAlign "middle";
            
    self.izno_plusscore.alignX "center";
            
    self.izno_plusscore.alignY "middle";
            
    self.izno_plusscore.0//middle of screen
            
    self.izno_plusscore.= -40//just above middle of screen
            
    self.izno_plusscore.alpha 0.3;
            
    self.izno_plusscore.fontscale 0.5;
        }
        else 
    //not first-run
        
    {
            if(
    self.izno_plusscore.alpha 0.3 || self.izno_plusscore.score == 0)
                
    self.izno_plusscore.alpha 0.3;
            if(
    self.izno_plusscore.fontscale 0.5 || self.izno_plusscore.score == 0)
                
    self.izno_plusscore.fontscale 0.5;
            
    self.izno_plusscore.instance++;
            
    self.izno_plusscore.score += score;
        }
        if(
    self.izno_plusscore.score 0)
        {
            
    self.izno_plusscore.color = (235/255,10/255,10/255); //negative scores are red
            
    self.izno_plusscore.label = &"";
        }
        else
        {
            
    self.izno_plusscore.color = (1,230/255,125/255); //yellow-ish
            
    self.izno_plusscore.label = &"+";
        }
        
    self.izno_plusscore setvalue(self.izno_plusscore.score);    

        
    current_instance self.izno_plusscore.instance;
        
    make_bigger true;
        
    more_opaque true;
        
    steady_opaque_timer 0;
        
    alpha_done false;
        
    size_done false;
        while(
    isdefined(self) && current_instance == self.izno_plusscore.instance && !(alpha_done && size_done))
        {
            if(
    make_bigger && self.izno_plusscore.fontscale 2)
                
    self.izno_plusscore.fontscale += 0.35;
            else if(
    make_bigger)
                
    make_bigger false;
            else if(
    self.izno_plusscore.fontscale 2)
                
    self.izno_plusscore.fontscale -= 0.2;
            else
            {
                
    size_done true;
                
    self.izno_plusscore.fontscale 1.5;
            }

            if(
    more_opaque && self.izno_plusscore.alpha <= 0.9//dont overflow this
                
    self.izno_plusscore.alpha += 0.1;
            else if(
    more_opaque && steady_opaque_timer == 20)
                
    more_opaque false;
            else if(
    more_opaque)
                
    steady_opaque_timer++;
            else if(
    self.izno_plusscore.alpha >= 0.1//dont underflow this
                
    self.izno_plusscore.alpha -= 0.1;
            else
            {
                
    alpha_done true;
                
    self.izno_plusscore.alpha 0;
            }
            
    wait 0.05;
        }
        if(!
    isdefined(self))
            return;
        if(
    current_instance == self.izno_plusscore.instance)
        {
            
    wait 0.5;
            if(
    isdefined(self) && self.izno_plusscore.instance == current_instance)
                
    self.izno_plusscore.score 0;
        }

    Call the scorepopup on every kill in the _callbacksetup::CallBack_OnPlayerKilled() (insert this function call as the last line):

    PHP Code:
    level thread maps\mp\gametypes\_scorepopup::OnPlayerKilledeAttacker self sMeansOfDeath sHitLoc ); 
    Here is how you setup CoD2 for your own mod: https://youtu.be/9-n75APn81g or just edit the Pam mod yourself

    Many thanks you made my day!! now it's working i also added the code to recognize if it's a self kill or not!!

    Just another question i think for you its really simple. I also added some sound that i want to play but i found a pack with all killingspree etc sound but it doesnt work even if i edit the file in soundaliases by adding in the csv with the same format as other files!

    Thanks a lot

  6. #4
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    I don't know what mod that 'killingspree' sound is from, but usually you have to call the sound via script somehow, otherwise it is not playing.
    If you have a mod, you need to merge the *.gsc files, such that it is a single mod, otherwise the mod gets overwritten in alphabetical order.
    When you already took care of this and there is still no sound, I remember I had similar issues with the soundaliases back in the day and tried until everything worked.
    Your sound files and the soundalias need to be in a .iwd file that gets downloaded by the client (iirc).

  7. #5
    ... connecting
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    2
    Thanked 1 Time in 1 Post
    Sorry for my bad english. What i wanted to say is that i'm able to play sound that i found in a killingspree mod via script but whenever i add some new sounds to the sound folder then to soundaliases i edit the csv file and add the reference to the .mp3, calling it from the script doesnt work.. but only for the new sounds added

  8. #6
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Yeah, okay. Unfortunately I cant help you with that, as I dont remember this part.
    In the past I had similar trouble getting sound to work, sometimes it was a faulty soundalias or a different audio format/encoding altogether that didnt work.
    Maybe go step by step until it breaks down: change an existing soundfiles name etc.
    If custom sounds arent loaded, maybe your soundalias isnt read in the first place?
    You could place it inside an iwd with 'zzz_' prefix, as these getting loaded last and should override the stock ones.

  9. The Following User Says Thank You to serthy For This Useful Post:

    idan (25th April 2020)

  10. #7
    ... connecting
    Join Date
    Dec 2018
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I CAN'T implement it, can you give me a hand?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •