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

Members Online

»
0 Active | 85 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 subscribe
Author Topic: Fire Counter
csocsi96
General Member
Since: Aug 9, 2010
Posts: 75
Last: Aug 24, 2014
[view latest posts]
Level 3
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Sunday, Mar. 10, 2013 02:07 pm
Hi everybody,

I am trying to make a counter that counts how many shots you have given.

I can't get it work.

Acutally, I have no idea how could I count each shot. My current script:

Code:

shotCheck()
{

	while(isAlive(self) && self attackbuttonpressed())
	{
	currentweapon = self GetCurrentWeapon();


		weapon1 = self getweaponslotweapon("primary");
		weapon2 = self getweaponslotweapon("primaryb");

		if(currentweapon == weapon1)
			currentslot = "primary";
		else
		{
			assert(currentweapon == weapon2);
			currentslot = "primaryb";
		}

		maxammo = self getweaponslotclipammo(currentslot);
		ammoinclip = self getweaponslotammo(currentslot);
	
		if(maxammo - ammoinclip > 0)
		{
			self.shotsfired++;
		}
		wait .05;
	}
}


Could someone help?

Regards,
Csocsi96
Share |
csocsi96
General Member
Since: Aug 9, 2010
Posts: 75
Last: Aug 24, 2014
[view latest posts]
Level 3
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Sunday, Mar. 10, 2013 03:52 pm
Well, I got this code:

Code:
init() {
   
    level waittill("connected", player);
    player waittill("spawned");
    player thread monitorWeaponUsage();
}

monitorWeaponUsage() {
    //creating vars
    ammo_before_wait = 0;
    ammo_after_wait = 0;
    max_bullets = 5;
    
  
    while(isAlive(self)) {
        //If the person shoots set var true, else false
        if(self attackButtonPressed()) {
            fired = true;
        } else {
            fired = false;
        }
        
        //if fired is true
        if(fired) {
            //Get ammo
            ammo_before_wait = getCurrentWeaponClipAmmo(self);
            //Waits... duh
            wait 0.5;
           
            ammo_after_wait = getCurrentWeaponClipAmmo(self);
            
            //Checks if the guy actually shot something at all
            if(ammo_before_wait > ammo_after_wait) {
                //If amount of shot bullets is bigger than allowed max
                if((ammo_before_wait - ammo_after_wait) > max_bullets) {
                    //Do something... currently just a message but can be changed into warnings or a kick I suppose
                    self iPrintLnBold("You're a hacker! Imma kick u nao u fagguwt.");
                }
            }
        } else {
            //Avoid infinite loop
            wait 0.05;
        }
    }
}


getCurrentWeaponClipAmmo(currPlayer) {
   
    if(currPlayer getWeaponSlotWeapon("primary") == currPlayer getCurrentWeapon()) {
        weapon = "primary";
    } else {
        weapon = "primaryb";
    }
    
  
    ammo = currPlayer getWeaponSlotClipAmmo(weapon);

    //Returns
    return ammo;
}


How could I change this into a shooting counter script?
Originally it is an anti fast fire script.
Share |
ukdjaj
General Member
Since: Jun 1, 2008
Posts: 2726
Last: Nov 15, 2020
[view latest posts]
Level 9
Category: CoD2 Scripting
Posted: Sunday, Mar. 10, 2013 10:54 pm
Use 'attackButtonPressed' and then just Make each time it is pressed +1?

Thanks, Ukdjaj[thumbs_up]
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Monday, Mar. 11, 2013 12:41 pm
ukdjaj writes...
Quote:
Use 'attackButtonPressed' and then just Make each time it is pressed +1?

Thanks, Ukdjaj[thumbs_up]


No that's not good. Like a MP44 you can hold your Attackbutton, but shoots 30 bullets and it will count as 1;)

You need to check the currentclip. When the attackbutton is pressed, you need to check again the clip. The difference between these to values is the shotcount


Share |
csocsi96
General Member
Since: Aug 9, 2010
Posts: 75
Last: Aug 24, 2014
[view latest posts]
Level 3
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Monday, Mar. 11, 2013 07:55 pm
Quote:

You need to check the currentclip. When the attackbutton is pressed, you need to check again the clip. The difference between these to values is the shotcount


How to get the difference? What if i use :

Code:

if(ammo_before_shot - ammo_after_shot = 1)
{
self.fires++;
}


then get the current value in the clip after every shot and restart from the if statement?
Share |
Ni3ls
General Member
Since: Nov 7, 2008
Posts: 256
Last: Sep 9, 2017
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Monday, Mar. 11, 2013 08:52 pm
Code:
difference = ammo_before-ammo_after;
self.shotcount +difference;

something like that?
Share |
csocsi96
General Member
Since: Aug 9, 2010
Posts: 75
Last: Aug 24, 2014
[view latest posts]
Level 3
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Mar. 12, 2013 03:02 pm
Actually, I have this code now. Used the difference thingy what you said, but it counts only on the first mouseclick when I fire, and actually I shot from an mp44 around 7 or 8 bullets(by holding the mouse), and it counted 2.833.781 xDD

I wanted to shoot some more on, but it did not count anymore.

This is the actual code:

Code:
init() {
   
    level waittill("connected", player);
    player waittill("spawned");
    player thread monitorWeaponUsage();
}

monitorWeaponUsage() {
    ammo_before_wait = 0;
    ammo_after_wait = 0;
    
    while(isAlive(self)) {
        if(self attackButtonPressed()) {
            fired = true;
			ammo_after_wait = getCurrentWeaponClipAmmo(self);
        } else {
            fired = false;
			ammo_before_wait = getCurrentWeaponClipAmmo(self);
        }
        
        if(fired) {
			difference = ammo_before_wait - ammo_after_wait; 
					self.firecount += difference;
                  //  self iPrintLnBold("You Fired.");
        } else {
            //Avoid infinite loop
            wait 0.05;
        }
    }
}

getCurrentWeaponClipAmmo(currPlayer) {
   
    if(currPlayer getWeaponSlotWeapon("primary") == currPlayer getCurrentWeapon()) {
        weapon = "primary";
    } else {
        weapon = "primaryb";
    }

   ammo = currPlayer getWeaponSlotClipAmmo(weapon);

    //Returns with the current value in the clip.
    return ammo;
}
Share |
Restricted Access Topic is Locked 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

»