CoD modding, reloads and movement

Have a question you need to ask? Need help? Ask here!

Moderator: Core Staff

Post Reply
mebloscian
CJ Wannabe
CJ Wannabe
Posts: 6
Joined: September 10th, 2012, 1:02 am

CoD modding, reloads and movement

Post by mebloscian » September 10th, 2012, 1:23 am

Hope there are some active modders here. Anyone have any idea how to change weapon reloading system in CoD? By that I mean the reloads will be based on clip count rather than on rounds. For example if you reload mp44 mid-clip, when having 13/150 (clip/supply) ammo count the result would be 30/120, so each reload takes a full clip ammo, not just the difference between clip size and actual clip load. There is also one more case, when supply is less than clip size, so if you have 13/8 ammo count, after reload it would be 8/0 (you're loosing those 13 bullets), or the reload is just simply impossible.

The one more little thing that I would implement is open and closed bolt system weapons. When you're reloading mid-clip a closed bolt system weapon, one round is in chamber, so after reload you will have clipSize+1 amount of ammo in clip, eg. mp44 would have 30 rounds per clip, but max "clip" (max ammo that can fit into gun with full clip) ammo would be 31, considering that mp44 fires from closed bolt, so it's closed bolt system weapon.

I've tested how some settings of these values works:

Code: Select all

noPartialReload
segmentedReload
reloadAmmoAdd
reloadStartAdd
but reloadStartAdd which I think might solve problem seems to don't affect anything.


I'm also wondering if there is a way to import 1.1 movement mechanics into 1.5 version. I'd like to import 1.1 experience into 1.5 to give 1.1 players access to functional punkbuster and game fixes. Hope it is possible just by scripting, since the major changes to movement was speed drop after landing and prevention going prone while in air, which actually are quite simple.

and other things:
How to prevent weapon being ADS while changing stance from prone? when going prone you can't ads, but reverse you can
How to add more spread and also ADS sway/spread to weapon while changing stance and leaning (reduce accuracy for some period)?
How to prevent shooting while going prone and getting up from prone?
What setting of the weapon from setting files affects accuracy when ADS and moving? I guess 'adsBobFactor' just affects weapon model behavior, not the accuracy itself and the adsSpread is constant. How reduce accuracy or add more sway to weapon ADS while moving?
How adsVievErrorMax and adsVievErrorMin will affect non-scoped guns, and guns with sway reduced to 0?
Is bob or sway affects accuracy?
What are exact differences between 1.1 and 1.5 version in game mechanics? Changelogs aren't specific about that.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: CoD modding, reloads and movement

Post by megazor » September 10th, 2012, 4:48 am

1. Reloading system. I think the only way to implement what you described is .gsc scripting.

I know 6 functions about ammo:

getWeaponSlotAmmo(slot)
getWeaponSlotClipAmmo(slot)
getWeaponSlotWeapon(slot)

setWeaponSlotAmmo(slot)
setWeaponSlotClipAmmo(slot)
setWeaponSlotWeapon(slot)

where slot can be "primary", "primaryb", "pistol", and "grenade".

After a weapon has been reloaded, its clip ammo is more than it was before reloading. So you should check (every server frame) an amount of clip ammo, and once it increases, you should change the ammo with the "set" functions.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: CoD modding, reloads and movement

Post by megazor » September 10th, 2012, 12:25 pm

Hope it is possible just by scripting, since the major changes to movement was speed drop after landing and prevention going prone while in air, which actually are quite simple.
Unfortunately it is impossible by scripting.

mebloscian
CJ Wannabe
CJ Wannabe
Posts: 6
Joined: September 10th, 2012, 1:02 am

Re: CoD modding, reloads and movement

Post by mebloscian » September 18th, 2012, 3:03 am

Every time I'm trying to add this or any other simple function to the dm.gsc the "scrip compile error: bad syntax" occurs, and I'm not able to even test if it works.

eg.:

Code: Select all

clip_count()
{
	slot="primary";
	weap=self GetWeaponSlotWeapon("primary")
	clips=self getWeaponSlotAmmo("primary")) / self WeaponClipSize("mosin_nagant_sniper")
	while(true)
	{
		clips()
		{
			slot_check()
			{
				if(self GetCurrentWeapon()==self getweaponslotweapon("primary"))
					return "primary";
				else if(self GetCurrentWeapon()==self getweaponslotweapon("primaryb"))
					return "primaryb";
				else if(self GetCurrentWeapon()==self getweaponslotweapon("pistol"))
					return "pistol";
			}
			slot = slot_check();
			weap = self GetWeaponSlotWeapon(slot);
			(int)clips = self getWeaponSlotAmmo(slot)) / self WeaponClipSize("weap");
			return clips;
			return self.clips;
			self iPrintlnBold("loop");
			wait 0.2;
			self iPrintlnBold("clips");
			wait 0.2;
			self iPrintlnBold("self.clips");
			wait 0.2;
			self iPrintlnBold("self.clips");
			wait 0.2;
		}
		self iPrintlnBold(clips());
	}
}
What do?
also somebody have scripting reference for cod1, i'm now using this:
http://wiki.modsrepository.com/index.ph ... _Reference
but it also include COD4 functions which can be sometimes confusing

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: CoD modding, reloads and movement

Post by Drofder2004 » September 18th, 2012, 3:42 am

You are trying to create a function within a function within a function.
There are many formatting errors.

I am not sure of your scripting background (what other languages you use) but you need to change the way you are writing script for CoD...

Firstly, you cannot create a function within a function. All functions are local to the file.
Secondly, all function calls, statements, definitions and probably a few other things requires a semicolon to end. No semicolon is used with conditionals (such as while, for, if, switch).
Thirdly, whe nusing "if" conditionals, I advise adding a default for the case of all being false.
Finally, make sure you enable developer mode (/developer 1) before running your script, and use the console to detect exactly where errors occur.

This should serve as a guide for fixing your syntax and not as a fix for your script, I have not tested it nor have I even taken thought into it doing as you want.

Code: Select all

clip_count()
{
   slot = "primary";
   weap = self GetWeaponSlotWeapon(slot); /* missing ';' */
   clips = self getWeaponSlotAmmo(slot) / self WeaponClipSize("mosin_nagant_sniper"); /* Too many ')' and missing ';' */
 
   while(true)
   {
      self iPrintlnBold( self clips() );
      wait 0.05; /* You must add a wait or waittill in loops that are potentially infinite */
   }
      
}
 
slot_check()
{
   if( self GetCurrentWeapon() == self getweaponslotweapon("primary") )
      return "primary";
   else if( self GetCurrentWeapon() == self getweaponslotweapon("primaryb") )
      return "primaryb";
   else if( self GetCurrentWeapon() == self getweaponslotweapon("pistol") )
      return "pistol";
   else
      return "error"; /* For the sake of potential errors where none of the above are true */
}
 
clips()
{
   slot = self slot_check(); /* function is to be called on the object that 'clips()' was called upon */
 
   if(slot == "error") /* Error message in the case of no weapon slot */
      return "Weapon slot not detected";
 
   weap = self GetWeaponSlotWeapon(slot);
   clips = int(self getWeaponSlotAmmo(slot) / self WeaponClipSize(weap)); /* Int is treated as a function. Also, make sure you do not use quotation marks when using variables else the variable name will simply be a string */
 
   return clips; /* Using a 'return' mid function will RETURN to the function that called this current function and the rest of this function will cease to exist */
   /* self.clips is not defined, unless you define it, don't bother trying to get information from it. */
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: CoD modding, reloads and movement

Post by megazor » September 18th, 2012, 9:02 am

CoD1:

Code: Select all

a = (int)b;
CoD2 and onwards:

Code: Select all

a = int(b);

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: CoD modding, reloads and movement

Post by <LT>YosemiteSam[NL] » September 18th, 2012, 11:43 am

Isn't it possible by just changing the .gsc files of the weapons itself ?
I mean you can change the splashdamage, damageradius, etc. so you can probably also change how many ammo you get.

mebloscian
CJ Wannabe
CJ Wannabe
Posts: 6
Joined: September 10th, 2012, 1:02 am

Re: CoD modding, reloads and movement

Post by mebloscian » September 18th, 2012, 4:02 pm

<LT>YosemiteSam[NL] - only ammo, not the whole reload system, the way the ammo is changed after reload

working code, need some improovements and testing, but it works and can be used on servers:

Code: Select all

initialize_reload_system()
{
        thread slot_check();
        thread clip_size_table();
        thread clip_count();
        thread is_clip_based();
        thread full_clip_ammo();
        thread clip_weapon_slot();
        //unavalible: thread closed_bolt();
        //unavalible: thread colsed_bolt_add();
}
        
/* return: "primary" or "primaryb" or "pistol" or "grenade" or "error" */
slot_check()
{
        if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("primary"))
                return "primary";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("primaryb"))
                return "primaryb";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("pistol"))
                return "pistol";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("grenade"))
                return "grenade";
        else
                return "error";
}
 
clip_size_table()
{
        weap = self GetCurrentWeapon();
        /* or use: */
        /* slot=Check_slot(); */
        /* weap = self GetWeaponSlotWeapon(slot) */
        switch(weap)
        {
        case "fraggrenade_mp":
        case "mk1britishfrag_mp":
        case "panzerfaust_mp":
        case "stielhandgranate_mp":
        case "rgd-33russianfrag_mp":
        case "PTRS41_Antitank_Rifle_mp":
                return 1;
                break;
        case "enfield_mp":
        case "kar98k_mp":
        case "kar98k_sniper_mp":
        case "mosin_nagant_mp":
        case "mosin_nagant_sniper_mp":
        case "springfield_mp":
                return 5;
                break;
        case "colt_mp":
                return 7;
                break;
        case "m1garand_mp":
        case "luger_mp":
                return 8;
                break;
        case "m1carbine_mp":
                return 15;
                break;
        //case "enfield_mp";
                return 10;
                break;
        case "bar_mp":
        case "bar_slow_mp":
        case "fg42_mp":
        case "fg42_semi_mp":
                return 20;
                break;
        case "bren_mp":
        case "mp44_mp":
        case "mp44_semi_mp":
        case "thompson_mp":
        case "thompson_semi_mp":
                return 30;
                break;
        case "mp40_mp":
        case "sten_mp":
                return 32;
                break;
        case "ppsh_mp":
        case "ppsh_semi_mp":
                return 71;
                break;
        default:
                clipsize = self GetWeaponSlotClipAmmo(slot);
                return clipsize;
                break;
        }
}
 
/* return: full clips left in stock OR (if there is less than one clip in stock) ammo/clip_size_table ratio */
clip_count()
{
        slot = slot_check();
        weap = self GetWeaponSlotWeapon(slot);
        ratio = self GetWeaponSlotAmmo(slot) / clip_size_table();
        if(ratio > 1)
        {
                clips = (int)ratio;
                return clips;
        }
        else
                return ratio;
}
 
/* return: true or false */
is_clip_based()
{
        weap = self GetCurrentWeapon();
        switch(weap)
        {
                case "fraggrenade_mp":
                case "kar98k_sniper_mp":
                case "mg42_bipod_duck_mp":
                case "mg42_bipod_prone_mp":
                case "mg42_bipod_stand_mp":
                case "mk1britishfrag_mp":
                case "panzerfaust_mp":
                case "PTRS41_Antitank_Rifle_mp":
                case "rgd-33russianfrag_mp":
                case "springfield_mp":
                case "stielhandgranate_mp":
                /* add other "case <non clip-based weapon>" here */
                        return false;
                        break;
                default:
                        return true;
                        break;
        }
}
 
/* return: true or false */
clip_weapon_slot()
{
        slot = slot_check();
        switch(slot)
        {
                case "primary":
                case "primaryb":
                case "pistol":
                        return true;
                        break;
                default:
                        return false;
                        break;
        }
}
 
/* nothing important here */
/* to add: */
/* dropping clip with remaining ammo */
/* not-allowADS shile going from prone to stand/crouch */
/* IsOnGround(); */
/* other comment */
/* other comment */
 
/* sets propper ammo count */
full_clip_ammo()
{
        /* on a keypress, attackButton since reloadButton is not avalible in CoD */
        /* while(self AttackButtonPressed() && is_clip_based() && (slot_check() != "grenade" || slot_check != "error")) */
        while(is_clip_based() && clip_weapon_slot())
        {
                weap1 = self GetCurrentWeapon();
                slot1 = slot_check();
                /* if not on a keypress but constant loop: */
                /* clip1 = self GetWeaponSlotClipAmmo(slot1); */
                wait 0.1;
                weap2 = self GetCurrentWeapon();
                slot2 = slot_check();
                if(self GetWeaponSlotAmmo(slot2) <= 0)
                        continue;
                /* if not on a keypress but constant loop: */
                /* clip2 = self GetWeaponSlotClipAmmo(slot2); */
                /* if(slot1 == slot2 && weap1 == weap2 && clip2 > clip1) */
                /*  /* reload occured */
                /* use that above if() statement instead of one below */
                if(slot1 == slot2 && weap1 == weap2 && self GetWeaponSlotAmmo(slot2) > clip_size_table())
                {
                        clips = clip_count();
                        ammo = clips * clip_size_table();
                        self SetWeaponSlotAmmo(slot2,ammo);
                }
                else if(slot1 == slot2 && weap1 == weap2 && self GetWeaponSlotAmmo(slot2) <= clip_size_table())
                        /* begin constant looping if "stock ammo"<="clip size", break loop when "stock ammo" > "clip size" */
                        /* allow 1 reload after which "stock ammo" will equal 0 and "clip ammo" will be equal "stock ammo" before reload */
                        while(true)
                        {
                                weap1 = self GetCurrentWeapon();
                                slot1 = slot_check();
                                ammo1 = self GetWeaponSlotAmmo(slot1);
                                clip1 = self GetWeaponSlotClipAmmo(slot1);
                                wait 0.1;
                                weap2 = self GetCurrentWeapon();
                                slot2 = slot_check();
                                ammo2 = self GetWeaponSlotAmmo(slot2);
                                clip2 = self GetWeaponSlotClipAmmo(slot2);
                                if(ammo2 > clip_size_table())
                                        /* weapon changed or ammo was picked up */
                                        break;
                                else if(weap1 == weap2 && slot1 == slot2 && clip1 < clip2)
                                {
                                        /* reload occured */
                                        ammo = 0;
                                        clip = ammo1;
                                        self SetWeaponSlotAmmo(slot2,ammo);
                                        self SetWeaponSlotClipAmmo(slot2,clip);
                                        break;
                                }
                                else if(weap1 != weap2 || slot1 != slot2)
                                        /* weapon or slot changed, check again */
                                        continue;
                        }       
        }
}
 
/* waits should be less than half of the minimal "fireTime" from weapon files from weapons/mp/ to prevent bugging */
 
 
/////////////////////* below functions are actually impossible without changing weapon conifg files */////////////////////
/* additional feature: closed bolt weapon reload */
closed_bolt()
{
        weap = self GetCurrentWeapon();
        switch(weap)
        {
                case "mp44_mp":
                case "bar_fast_mp":
                /* add other "case <closed bolt weapon>" here */
                        return true;
                        break;
                default:
                        return false;
                        break;
        }
}
                
                
                
/* the wait times are huge here - to reduce resource requirements */
colsed_bolt_add()
{
        closed = closed_bolt();
        while(closed)
        {
                weap1 = self GetCurrentWeapon();
                slot1 = slot_check();
                clip1 = self GetWeaponSlotClipAmmo(slot1);
                wait 0.2;
                weap2 = self GetCurrentWeapon();
                slot2 = slot_check();
                clip2 = self GetWeaponSlotClipAmmo(slot2);
                /*  check if reload occured and if it was mid-clip reload */
                if(clip1 >= clip2)
                        continue;
                if(weap1 == weap2 && slot1 == slot2 && clip1 < clip2)
                {
                        /* reload occured - add 1 bullet to the clip */
                        clip2++;
                        self setWeaponSlotClipAmmo(slot2,clip2);
                        wait 0.5;
                        continue;
                }
                if(weap1 != weap2 || slot1 != slot2)
                {
                        /* weapon or something else changes, check again */
                        wait 0.5;
                        continue;
                }
                else
                {
                        /* nothing happen, wait */
                        wait 0.5;
                        continue;
                }
                wait 0.1;
        }
}
I do not know how to run loop on a keypress (eg. attack), everytime i'm trying to do that it doesn't load or create runtime errors. I've got some other concers, but you can read them in comments inside script.
Also how can I optimize it, to reduce code size, and resource consumption?

Thanks again for advices.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: CoD modding, reloads and movement

Post by megazor » September 19th, 2012, 6:23 am

An experienced modder has published a full clip reloading script. Read it through and make a note of it.

http://modsonline.com/Forums-top-163371.html

mebloscian
CJ Wannabe
CJ Wannabe
Posts: 6
Joined: September 10th, 2012, 1:02 am

Re: CoD modding, reloads and movement

Post by mebloscian » September 19th, 2012, 9:54 am

megazor - i did it already, partially I've based my script on it, but some functions work different in CoD2, and my script should be as it is now. The only thing to do is to make it active only on a keypress (like in line 163).

mebloscian
CJ Wannabe
CJ Wannabe
Posts: 6
Joined: September 10th, 2012, 1:02 am

Re: CoD modding, reloads and movement

Post by mebloscian » September 20th, 2012, 1:45 am

Reload system with closed bolt reload function:
/didn't tested yet/

Code: Select all

initialize_reload_system()
{
        thread clip_size_table();
        thread is_closed_bolt();
        thread is_clip_based();
        thread clip_count();
        thread clip_weapon_slot();
        thread slot_check();
        thread closed_bolt_reload();
        thread detect_change(); //help me
        thread full_clip_ammo();
}
 
clip_size_table()
{
        weap = self GetCurrentWeapon();
        /* or use: */
        /* slot=Check_slot(); */
        /* weap = self GetWeaponSlotWeapon(slot) */
        switch(weap)
        {
        case "fraggrenade_mp":
        case "mk1britishfrag_mp":
        case "panzerfaust_mp":
        case "stielhandgranate_mp":
        case "rgd-33russianfrag_mp":
        case "PTRS41_Antitank_Rifle_mp":
                return 1;
                break;
        case "enfield_mp":
        case "kar98k_mp":
        case "kar98k_sniper_mp":
        case "mosin_nagant_mp":
        case "mosin_nagant_sniper_mp":
        case "springfield_mp":
                return 5;
                break;
        case "colt_mp":
                return 7;
                break;
        case "m1garand_mp":
        case "luger_mp":
                return 8;
                break;
        case "m1carbine_mp":
                return 15;
                break;
        //case "enfield_mp";
                //return 10;
                //break;
        case "bar_mp":
        case "bar_slow_mp":
        case "fg42_mp":
        case "fg42_semi_mp":
                return 20;
                break;
        case "bren_mp":
        case "mp44_mp":
        case "mp44_semi_mp":
        case "thompson_mp":
        case "thompson_semi_mp":
                return 30;
                break;
        case "mp40_mp":
        case "sten_mp":
                return 32;
                break;
        case "ppsh_mp":
        case "ppsh_semi_mp":
                return 71;
                break;
        default:
                //commented since GetWeaponSlotClipAmmo result in wierd behaviour and common clipsize is 30
                //clipsize = self GetWeaponSlotClipAmmo(slot);
                //return clipsize;
                return 30;
                break;
        }
}
 
is_closed_bolt()
{
        weap = self GetCurrentWeapon();
        /* or use: */
        /* slot=Check_slot(); */
        /* weap = self GetWeaponSlotWeapon(slot) */
        switch(weap)
        {
                //i should sort cases from most frequent so less code would be processed
                case "colt_mp":
                case "fg42_semi_mp": //funny fact about fg42 is that it was open when full-auto and closed when semi
                case "luger_mp":
                case "m1carbine_mp":
                case "m1garand_mp":
                case "mp44_mp":
                case "mp44_semi_mp":
                        return true;
                        break;
                case "bar_mp":
                case "bar_slow_mp":
                case "bren_mp":
                case "fg42_mp": //funny fact about fg42 is that it was open when full-auto and closed when semi
                case "mp40_mp":
                case "ppsh_mp":
                case "ppsh_semi_mp":
                case "sten_mp":
                case "thompson_mp":
                case "thompson_semi_mp":
                        return false;
                        break;
                default:
                        return false;
                        break;
        }
}
 
is_clip_based()
{
        weap = self GetCurrentWeapon();
        switch(weap)
        {
                case "fraggrenade_mp":
                case "kar98k_sniper_mp":
                case "mg42_bipod_duck_mp":
                case "mg42_bipod_prone_mp":
                case "mg42_bipod_stand_mp":
                case "mk1britishfrag_mp":
                case "panzerfaust_mp":
                case "PTRS41_Antitank_Rifle_mp":
                case "rgd-33russianfrag_mp":
                case "springfield_mp":
                case "stielhandgranate_mp":
                        return false;
                        break;
                default:
                        return true;
                        break;
        }
}
 
clip_count()
{
        slot = slot_check();
        weap = self GetWeaponSlotWeapon(slot);
        ratio = self GetWeaponSlotAmmo(slot) / clip_size_table();
        if(ratio > 1)
        {
                clips = (int)ratio;
                return clips;
        }
        else
                return ratio;
}
 
clip_weapon_slot()
{
        slot = slot_check();
        switch(slot)
        {
                case "primary":
                case "primaryb":
                case "pistol":
                        return true;
                        break;
                default:
                        return false;
                        break;
        }
}
 
slot_check()
{
        if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("primary"))
                return "primary";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("primaryb"))
                return "primaryb";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("pistol"))
                return "pistol";
        else if(self GetCurrentWeapon() == self GetWeaponSlotWeapon("grenade"))
                return "grenade";
        else
                return "error";
}
 
// some "if" statements here won't be even used if it is meant to work inside full_clip_ammo() - but i leave them making it easy convert to stand-alone loop 
// added break instead of continue, so it will exit loop when work done (stand alone function should use continue)
// i've also removed waits since loop won't occur anyway (break; everywhere)
closed_bolt_reload()
{
        while(is_closed_bolt())
        {
                //don't check it again while implemented under full_clip_ammo() and variables are defined before it
                //weap1 = self GetCurrentWeapon();
                //slot1 = slot_check();
                //clip1 = self GetWeaponSlotClipAmmo(slot1);
                //ammo1 = self GetWeaponSlotAmmo(slot1);
                //wait 0.1;
                //weap2 = self GetCurrentWeapon();
                //slot2 = slot_check();
                //clip2 = self GetWeaponSlotClipAmmo(slot2);
                //ammo2 = self GetWeaponSlotAmmo(slot2);
                /*  check if reload occured and if it was mid-clip reload */
                if(clip1 >= clip2)
                        break;
                if(weap1 == weap2 && slot1 == slot2 && ammo1 > ammo2 && clip1 > 0)
                {
                        /* reload occured mid-clip - add 1 bullet to stock ammo (yes to stock ammo, not clip since clips size are increased) */
                        ammo2++;
                        self setWeaponSlotAmmo(slot2,ammo2);
                        //wait 0.5;
                        break;
                }
                if(weap1 == weap2 && slot1 == slot2 && ammo1 > ammo2 && clip1 <= 0)
                {
                        /* reload occured empty-clip - remove 1 bullet from clip add 1 to stock ammo AND then proceed full clip reload*/
                        clip2--;
                        ammo2++;
                        self setWeaponSlotAmmo(slot2,ammo2);
                        self setWeaponSlotClipAmmo(slot2,clip2);
                        //no need to wait anymore if implemented under another function (hope so)
                        //wait 0.5;
                        break;
                }
                if(weap1 != weap2 || slot1 != slot2)
                {
                        /* weapon or something else changes, check wait and again - yep wait is needed so it wont loop so often*/
                        //wait 0.5;
                        break;
                }
                else
                {
                        /* nothing or undefined case happen, wait */
                        //wait 0.5;
                        break;
                }
        }
}
 
//and need help in this function ;_; i don't want to create global variables cuz i'm afraid of eventual mess
detect_change()
{
        weap1 = self GetCurrentWeapon();
        slot1 = slot_check();
        clip1 = self GetWeaponSlotClipAmmo(slot1);
        ammo1 = self GetWeaponSlotAmmo(slot1);
        wait 0.2;
        weap2 = self GetCurrentWeapon();
        slot2 = slot_check();
        clip2 = self GetWeaponSlotClipAmmo(slot2);
        ammo2 = self GetWeaponSlotAmmo(slot2);
}
 
 
/* nothing important here */
/* to add: */
/* dropping clip with remaining ammo */
/* not-allowADS while going from prone to stand/crouch */
/* IsOnGround(); */
/* other comment */
/* other comment */
 
/* sets propper ammo count with implementation of closed_bolt_reload() */
full_clip_ammo()
{
    self endon("death");
    self endon("disconnect");
        self endon("spawned");
        /* on a keypress, attackButton since reloadButton is not avalible in CoD */
        /* while(self AttackButtonPressed() && is_clip_based() && (slot_check() != "grenade" || slot_check != "error")) */
        while(is_clip_based() && clip_weapon_slot())
        {
                weap1 = self GetCurrentWeapon();
                slot1 = slot_check();
                ammo1 = self GetWeaponSlotAmmo(slot1);
                /* if not on a keypress but constant loop: */
                /* clip1 = self GetWeaponSlotClipAmmo(slot1); */
                /* insead of  */
                wait 0.1;
                weap2 = self GetCurrentWeapon();
                slot2 = slot_check();
                ammo2 = self GetWeaponSlotAmmo(slot2);
                //or use ammo1 and ammo2 from detect_change() function
                if(self GetWeaponSlotAmmo(slot2) <= 0 || self GetWeaponSlotAmmo(slot2) = self GetWeaponSlotAmmo(slot1))
                        continue; /* nothing happen, continue loop */
                /* if not on a keypress but constant loop: */
                /* clip2 = self GetWeaponSlotClipAmmo(slot2); */
                /* if(slot1 == slot2 && weap1 == weap2 && ammo1 > ammo2) */
                /*  /* reload occured */
                /* use that above if() statement instead of one below */
                if(slot1 == slot2 && weap1 == weap2 && self GetWeaponSlotAmmo(slot2) > clip_size_table() && ammo2 < ammo1) /* if picked ammo should be loosed remove "ammo2 < ammo1" from if() */
                {
                        closed_bolt_reload();
                        clips = clip_count();
                        ammo = clips * clip_size_table();
                        self SetWeaponSlotAmmo(slot2,ammo);
                }
                else if(slot1 == slot2 && weap1 == weap2 && self GetWeaponSlotAmmo(slot2) <= clip_size_table())
                        /* begin constant looping if "stock ammo"<="clip size", break loop when "stock ammo" > "clip size" */
                        /* allow 1 reload after which "stock ammo" will equal 0 and "clip ammo" will be equal "stock ammo" before reload */
                        while(true)
                        {
                                weap1 = self GetCurrentWeapon();
                                slot1 = slot_check();
                                ammo1 = self GetWeaponSlotAmmo(slot1);
                                clip1 = self GetWeaponSlotClipAmmo(slot1);
                                wait 0.1;
                                weap2 = self GetCurrentWeapon();
                                slot2 = slot_check();
                                ammo2 = self GetWeaponSlotAmmo(slot2);
                                clip2 = self GetWeaponSlotClipAmmo(slot2);
                                if(ammo2 > clip_size_table())
                                        /* weapon changed or ammo was picked up */
                                        break;
                                else if(weap1 == weap2 && slot1 == slot2 && ammo2 < ammo1)
                                {
                                        /* reload occured */
                                        closed_bolt_reload();
                                        ammo = 0;
                                        clip = ammo1;
                                        self SetWeaponSlotAmmo(slot2,ammo);
                                        self SetWeaponSlotClipAmmo(slot2,clip);
                                        break;
                                }
                                else if(weap1 != weap2 || slot1 != slot2)
                                        /* weapon or slot changed, check again */
                                        continue;
                                else
                                        continue; //just for sure
                        }       
        }
}
 
/* i think some waits should be less than half of the minimal "fireTime" from weapon files from weapons/mp/ to prevent bugging (escpecially detect_change()), some other waits could be longer */
 

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 34 guests