Author |
Topic: Killstreak Count |
|
Category: CoD2 Scripting Posted: Thursday, May. 20, 2010 03:12 pm |
|
Hello,
I am new on this forum. I know some stuff about modding but i never worked with hud.
So my question is:
How to make a counter that shows ur current killstreak?
This is the script
Code: Messages(sMeansOfDeath, attacker)
{
if(!isDefined(attacker.pers["kill_spree"]))
attacker.pers["kill_spree"] = 0;
self.pers["kill_spree"] = 0;
attacker.pers["kill_spree"]++;
self.killcount = attacker.pers["kill_spree"];
if(self.killcount == 3)
{
attacker iprintlnbold("You have a 3 KillStreak!");
}
if(self.killcount == 5)
{
attacker iprintlnbold("You have a 5 KillStreak!");
}
if(self.killcount == 7)
{
attacker iprintlnbold("You have a 7 KillStreak!");
}
if(self.killcount == 10)
{
attacker iprintlnbold("You have a 10 KillStreak!");
}
if(self.killcount == 20)
{
attacker iprintlnbold("You have a 20 KillStreak!");
}
} |
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
|
Xylozi |
General Member Since: Jul 12, 2008 Posts: 218 Last: Mar 1, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Thursday, May. 20, 2010 10:52 pm |
|
This little modification should create a Killstreak HUD element (two) for the attacker on their first kill, and will update everytime they get a kill. If you want a better system, I'd recommend add the HUD generation code on the spawnPlayer() function in one of the gametype .GSCs and then also destroying the HUD elements on spawn too.
Code:
Messages( sMeansOfDeath, attacker )
{
if(!isDefined(attacker.pers["kill_spree"]))
attacker.pers["kill_spree"] = 0;
if( !isDefined( attacker.killstreakText )
attacker thread CreateKillstreakHUD();
self.pers["kill_spree"] = 0;
attacker.pers["kill_spree"]++;
self.killcount = attacker.pers["kill_spree"];
attacker UpdateKillstreakHUD( attacker.pers["kill_spree"] );
if(self.killcount == 3)
attacker iprintlnbold("You have a 3 KillStreak!");
if(self.killcount == 5)
attacker iprintlnbold("You have a 5 KillStreak!");
if(self.killcount == 7)
attacker iprintlnbold("You have a 7 KillStreak!");
if(self.killcount == 10)
attacker iprintlnbold("You have a 10 KillStreak!");
if(self.killcount == 20)
attacker iprintlnbold("You have a 20 KillStreak!");
}
CreateKillstreakHUD()
{
self.killstreakText = newClientHudElem(self);
self.killstreakText.x = 100;
self.killstreakText.y = 40;
self.killstreakText.sort = 99;
self.killstreakText SetText( "Killstreak Count:" );
self.killstreakValue = newClientHudElem(self);
self.killstreakValue.x = 100;
self.killstreakValue.y = 40;
self.killstreakValue.sort = 99;
self.killstreakValue SetValue( 0 );
}
UpdateKillstreakHUD( value )
{
if( isDefined( self.killstreakValue ) )
self.killstreakValue SetValue( value );
}
edited on May. 20, 2010 06:52 pm by Xylozi |
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 01:22 am |
|
Xylozi how is ur method supose to work? i see u set the value to 0. how is that gona update? i see u have
Code: UpdateKillstreakHUD( value )
{
if( isDefined( self.killstreakValue ) )
self.killstreakValue SetValue( value );
}
to update but if he puts 1 for value theres no way that will update every time, say he got 2 kills it would still say 1... i recommend you use what i put because what i said will update every time because it has a loop on the value, but u did have a good idea here
Code: self.killstreakText SetText( "Killstreak Count:" );
wich is a very nice idea matter of fact. you could try something like this.
Code:
self endon("disconnect");
self endon("joined_spectators");
if(!isDefined(self.killstreakhud))
{
self.killstreakhud = newClientHudElem(self);
self.killstreakhud.x = 565;
self.killstreakhud.y = 315;
self.killstreakhud.sort = 3;
}
self.killstreakhud setvalue(self.killcount);
while(1)
{
wait (1.1);
self.killstreakhud setvalue(self.killcount);
}
if(!isDefined(self.killstreakhudText))
{
self.killstreakhudText = newClientHudElem(self);
self.killstreakhudText.x = 100;
self.killstreakhudText.y = 40;
self.killstreakhudText.sort = 99;
self.killstreakhudText SetText( "Killstreak Count:" );
}
and in the spawnplayer() in 1 of the gametypes add
Code:
if(isDefined(self.pers["kill_spree"]))
self.pers["kill_spree"] = 0;
i think the code above this should work fine havnt tested it but u can post back and see how everything goes. |
|
|
|
Xylozi |
General Member Since: Jul 12, 2008 Posts: 218 Last: Mar 1, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 06:59 am |
|
The UpdateKillstreakHUD() function, when threaded (which is everytime he kills) will carry the new value for his killstreak, therefore removing an unneeded loop and working as intended.
This is the line that will thread for every kill:
Code: attacker UpdateKillstreakHUD( attacker.pers["kill_spree"] );
Which happenes after this:
Code: attacker.pers["kill_spree"]++;
Therefore it will keep the HUD value updated correctly. |
|
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 07:10 am |
|
Now i get an bad syntax error at line 7
Code: if( !isDefined( attacker.killstreakText )
attacker thread CreateKillstreakHUD();
Completer script. I hope I understand you well.
Code: Messages(sMeansOfDeath, attacker)
{
if(!isDefined(attacker.pers["kill_spree"]))
attacker.pers["kill_spree"] = 0;
if( !isDefined( attacker.killstreakText )
attacker thread CreateKillstreakHUD();
self.pers["kill_spree"] = 0;
attacker.pers["kill_spree"]++;
self.killcount = attacker.pers["kill_spree"];
if(self.killcount == 3)
{
attacker iprintlnbold("You have a 3 KillStreak!");
}
if(self.killcount == 5)
{
attacker iprintlnbold("You have a 5 KillStreak!\nYou have earned the NadeLauncher");
}
if(self.killcount == 7)
{
attacker iprintlnbold("You have a 7 KillStreak!\nYou get your Pistol back");
}
if(self.killcount == 10)
{
attacker iprintlnbold("You have a 10 KillStreak!\nYou have earned the MG42");
}
if(self.killcount == 20)
{
attacker iprintlnbold("You have a 20 KillStreak!\nAirstrike Ready!");
}
}
CreateKillstreakHUD()
{
self endon("disconnect");
self endon("joined_spectators");
if(!isDefined(self.killstreakhud))
{
self.killstreakhud = newClientHudElem(self);
self.killstreakhud.x = 565;
self.killstreakhud.y = 315;
self.killstreakhud.sort = 3;
}
self.killstreakhud setvalue(self.killcount);
while(1)
{
wait (1.1);
self.killstreakhud setvalue(self.killcount);
}
if(!isDefined(self.killstreakhudText))
{
self.killstreakhudText = newClientHudElem(self);
self.killstreakhudText.x = 100;
self.killstreakhudText.y = 40;
self.killstreakhudText.sort = 99;
self.killstreakhudText SetText( "Killstreak Count:" );
}
} |
|
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 10:48 am |
|
Code: if( !isDefined( attacker.killstreakText )
This line is missing a )
Code: if( !isDefined( attacker.killstreakText ) )
|
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 03:57 pm |
|
Now i got an error.
First one is the error with liltc64 script
And this error with Xylozi script
Must i prechache them or something? |
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Friday, May. 21, 2010 04:55 pm |
|
for xylozi's script just add Code: game["killstreak"] = &"Killstreak Count :";
before u thread anything so in main() or init() what ever u named it lol. and for setText do Code: self.killstreakText setText(game["killstreak"]);
and for mine... no clue what happend there haha i would have to run tests my self to get that working. but just use xylozi's. |
|
|
|