Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 66 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: Killstreak Count
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
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!");
   }
}
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Thursday, May. 20, 2010 09:45 pm
make a hud and set the value as self.killcount something like this
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);
}

i recommend you have something in 1 of ur gametypes .gsc on spawnplayer() to reset self.killcount to 0 so your killstreaks work properly.
Share |
Xylozi
General Member
Since: Jul 12, 2008
Posts: 218
Last: Mar 1, 2012
[view latest posts]
Level 4
Im a fan of MODSonair
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
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
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.
Share |
Xylozi
General Member
Since: Jul 12, 2008
Posts: 218
Last: Mar 1, 2012
[view latest posts]
Level 4
Im a fan of MODSonair
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.
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
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:" );
}
}
Share |
Opel
General Member
Since: Dec 18, 2008
Posts: 21
Last: Sep 4, 2011
[view latest posts]
Level 1
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 ) ) 
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Friday, May. 21, 2010 12:41 pm
ah okay, i didnt know what u ment by ur code at first. very nice both ways should work fine.
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
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?
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
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.
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»