[ create a new paste ] login | about

Link: http://codepad.org/SpFn2pCz    [ raw code | output | fork ]

C, pasted on Sep 20:
// IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! IMPORTANT ! //
// since closed_bolt_reload() is implementet that script requires modified files from weapons/mp - increased every closed bolt weapons clips by 1 //

initialize_reload_system()
{

	thread full_clip_ammo();
	/* thread propper_clip_on_spawn(); // DOESN'T WORK - HELP! */
}

// DOESN'T WORK - HELP! //
propper_clip_on_spawn()
{
	self waittill("end_respawn");
	self waittill("game_started");
	self waittill("spawned");
	wait 0.2;
	weap = self GetWeaponSlotWeapon("primary");
	self SetWeaponSlotClipAmmo("primary", clip_size_table(weap));
	wait 0.1;
	weap = self GetWeaponSlotWeapon("primaryb");
	self SetWeaponSlotClipAmmo("primaryb", clip_size_table(weap));
	wait 0.1;
	weap = self GetWeaponSlotWeapon("pistol");
	self SetWeaponSlotClipAmmo("pistol", clip_size_table(weap));
}
// to fix //


//add parametrs to clip_size_table(parametrs)? will it crash when no parametrs are defined?
clip_size_table(weap)
{
	weap = self GetCurrentWeapon();
	/*if(!isDefined(weap)) since propper clip don't work
	//{
	//	weap = self GetCurrentWeapon();
	//	return clip_size_table(weap);
	//} */
	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
		//clipsize = self GetWeaponSlotClipAmmo(slot);
		//return clipsize;
		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 "mp44_mp":
		case "mp44_semi_mp":
		case "colt_mp":
		case "luger_mp":
		case "m1carbine_mp":
		case "fg42_semi_mp": //funny fact about fg42 is that it was open when full-auto and closed when semi
			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":
		case "enfield_mp":
		case "kar98k_mp":
		case "kar98k_sniper_mp":
		case "mosin_nagant_mp":
		case "mosin_nagant_sniper_mp":
		case "springfield_mp":
		case "m1garand_mp": //it is closed bolt but can be reloaded only with empty clip
			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()
{
	while(true)
	{
		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 //if eg. fire-mode was changed
			wait 0.1;
	}
}

// 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(clip1, clip2, ammo1, ammo2, slot1, slot2)
{
	while(is_closed_bolt() && clip1 != clip_size_table())
	{
		//don't check it again while implemented under full_clip_ammo() and variables are defined before it
		//player.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 > 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(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;
		}
		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.1;
	weap2 = self GetCurrentWeapon();
	slot2 = slot_check();
	clip2 = self GetWeaponSlotClipAmmo(slot2);
	ammo2 = self GetWeaponSlotAmmo(slot2);
	//idk if make them global or not
	return weap1;
	return slot1;
	return clip1;
	return ammo1;
	return weap2;
	return slot2;
	return clip2;
	return ammo2;
	//multiple returns?
}


/* 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("spawned");
	self endon("death");
	self endon("disconnect");
    /* 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);
		clip1 = self GetWeaponSlotClipAmmo(slot1);
		wait 0.1;
		weap2 = self GetCurrentWeapon();
		slot2 = slot_check();
		ammo2 = self GetWeaponSlotAmmo(slot2);
		clip2 = self GetWeaponSlotClipAmmo(slot2);
		//or use ammo1 and ammo2 from detect_change() function
		if(self GetWeaponSlotAmmo(slot2) <= 0 || ammo1 == ammo2)
			continue;
		/* 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(clip1, clip2, ammo1, ammo2, slot1, slot2);
			ammo = clip_count() * clip_size_table(); /* ammo = ammo1 - clip_size_table(); */
			self SetWeaponSlotAmmo(slot2,ammo);
			continue;
		}
		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)
			{
				if(ammo2 > clip_size_table())
					return;
				else if(weap1 == weap2 && slot1 == slot2 && ammo2 < ammo1 && ammo1 <= clip_size_table())
				{
					/* reload occured */
					//ammo = 0;
					ammo = clip1;
					clip = ammo1;
					if(clip1 >= 0 && is_closed_bolt())
					{
						ammo--;
						clip++;
						self SetWeaponSlotAmmo(slot2,ammo);
						self SetWeaponSlotClipAmmo(slot2,clip);
					}
					else
					{
						self SetWeaponSlotAmmo(slot2,ammo);
						self SetWeaponSlotClipAmmo(slot2,clip);
					}
				}
				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);
			}
		}
		else
		{
			continue;
			//for sure it won't hang
		}
	}
}

/* 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 */


Output:
In function 'initialize_reload_system':
Line 7: error: 'thread' undeclared (first use in this function)
Line 7: error: (Each undeclared identifier is reported only once
Line 7: error: for each function it appears in.)
Line 7: error: expected ';' before 'full_clip_ammo'
In function 'propper_clip_on_spawn':
Line 14: error: 'self' undeclared (first use in this function)
Line 14: error: expected ';' before 'waittill'
Line 15: error: expected ';' before 'waittill'
Line 16: error: expected ';' before 'waittill'
Line 17: error: 'wait' undeclared (first use in this function)
Line 17: error: expected ';' before numeric constant
Line 18: error: 'weap' undeclared (first use in this function)
Line 18: error: expected ';' before 'GetWeaponSlotWeapon'
Line 19: error: expected ';' before 'SetWeaponSlotClipAmmo'
Line 20: error: expected ';' before numeric constant
Line 21: error: expected ';' before 'GetWeaponSlotWeapon'
Line 22: error: expected ';' before 'SetWeaponSlotClipAmmo'
Line 23: error: expected ';' before numeric constant
Line 24: error: expected ';' before 'GetWeaponSlotWeapon'
Line 25: error: expected ';' before 'SetWeaponSlotClipAmmo'
In function 'clip_size_table':
Line 33: error: 'self' undeclared (first use in this function)
Line 33: error: expected ';' before 'GetCurrentWeapon'
Line 41: error: case label does not reduce to an integer constant
Line 42: error: case label does not reduce to an integer constant
Line 43: error: case label does not reduce to an integer constant
Line 44: error: case label does not reduce to an integer constant
Line 45: error: case label does not reduce to an integer constant
Line 46: error: case label does not reduce to an integer constant
Line 49: error: case label does not reduce to an integer constant
Line 50: error: case label does not reduce to an integer constant
Line 51: error: case label does not reduce to an integer constant
Line 52: error: case label does not reduce to an integer constant
Line 53: error: case label does not reduce to an integer constant
Line 54: error: case label does not reduce to an integer constant
Line 57: error: case label does not reduce to an integer constant
Line 60: error: case label does not reduce to an integer constant
Line 61: error: case label does not reduce to an integer constant
Line 64: error: case label does not reduce to an integer constant
Line 70: error: case label does not reduce to an integer constant
Line 71: error: case label does not reduce to an integer constant
Line 72: error: case label does not reduce to an integer constant
Line 73: error: case label does not reduce to an integer constant
Line 76: error: case label does not reduce to an integer constant
Line 77: error: case label does not reduce to an integer constant
Line 78: error: case label does not reduce to an integer constant
Line 79: error: case label does not reduce to an integer constant
Line 80: error: case label does not reduce to an integer constant
Line 83: error: case label does not reduce to an integer constant
Line 84: error: case label does not reduce to an integer constant
Line 87: error: case label does not reduce to an integer constant
Line 88: error: case label does not reduce to an integer constant
In function 'is_closed_bolt':
Line 101: error: 'weap' undeclared (first use in this function)
Line 101: error: 'self' undeclared (first use in this function)
Line 101: error: expected ';' before 'GetCurrentWeapon'
Line 114: error: 'true' undeclared (first use in this function)
Line 133: error: 'false' undeclared (first use in this function)
In function 'is_clip_based':
Line 143: error: 'weap' undeclared (first use in this function)
Line 143: error: 'self' undeclared (first use in this function)
Line 143: error: expected ';' before 'GetCurrentWeapon'
Line 157: error: 'false' undeclared (first use in this function)
Line 160: error: 'true' undeclared (first use in this function)
In function 'clip_count':
Line 167: error: 'slot' undeclared (first use in this function)
Line 168: error: 'weap' undeclared (first use in this function)
Line 168: error: 'self' undeclared (first use in this function)
Line 168: error: expected ';' before 'GetWeaponSlotWeapon'
Line 169: error: 'ratio' undeclared (first use in this function)
Line 169: error: expected ';' before 'GetWeaponSlotAmmo'
Line 172: error: 'clips' undeclared (first use in this function)
In function 'clip_weapon_slot':
Line 181: error: 'slot' undeclared (first use in this function)
Line 187: error: 'true' undeclared (first use in this function)
Line 190: error: 'false' undeclared (first use in this function)
In function 'slot_check':
Line 197: error: 'true' undeclared (first use in this function)
Line 199: error: 'self' undeclared (first use in this function)
Line 199: error: expected ')' before 'GetCurrentWeapon'
Line 200: warning: return makes integer from pointer without a cast
Line 201: error: expected ')' before 'GetCurrentWeapon'
Line 202: warning: return makes integer from pointer without a cast
Line 203: error: expected ')' before 'GetCurrentWeapon'
Line 204: warning: return makes integer from pointer without a cast
Line 205: error: expected ')' before 'GetCurrentWeapon'
Line 206: warning: return makes integer from pointer without a cast
Line 208: error: 'wait' undeclared (first use in this function)
Line 208: error: expected ';' before numeric constant
In function 'closed_bolt_reload':
Line 234: error: 'self' undeclared (first use in this function)
Line 234: error: expected ';' before 'setWeaponSlotAmmo'
Line 243: error: expected ';' before 'setWeaponSlotAmmo'
Line 244: error: expected ';' before 'setWeaponSlotClipAmmo'
In function 'detect_change':
Line 261: error: 'weap1' undeclared (first use in this function)
Line 261: error: 'self' undeclared (first use in this function)
Line 261: error: expected ';' before 'GetCurrentWeapon'
Line 262: error: 'slot1' undeclared (first use in this function)
Line 263: error: 'clip1' undeclared (first use in this function)
Line 263: error: expected ';' before 'GetWeaponSlotClipAmmo'
Line 264: error: 'ammo1' undeclared (first use in this function)
Line 264: error: expected ';' before 'GetWeaponSlotAmmo'
Line 265: error: 'wait' undeclared (first use in this function)
Line 265: error: expected ';' before numeric constant
Line 266: error: 'weap2' undeclared (first use in this function)
Line 266: error: expected ';' before 'GetCurrentWeapon'
Line 267: error: 'slot2' undeclared (first use in this function)
Line 268: error: 'clip2' undeclared (first use in this function)
Line 268: error: expected ';' before 'GetWeaponSlotClipAmmo'
Line 269: error: 'ammo2' undeclared (first use in this function)
Line 269: error: expected ';' before 'GetWeaponSlotAmmo'
In function 'full_clip_ammo':
Line 294: error: 'self' undeclared (first use in this function)
Line 294: error: expected ';' before 'endon'
Line 295: error: expected ';' before 'endon'
Line 296: error: expected ';' before 'endon'
Line 301: error: 'weap1' undeclared (first use in this function)
Line 301: error: expected ';' before 'GetCurrentWeapon'
Line 302: error: 'slot1' undeclared (first use in this function)
Line 303: error: 'ammo1' undeclared (first use in this function)
Line 303: error: expected ';' before 'GetWeaponSlotAmmo'
Line 304: error: 'clip1' undeclared (first use in this function)
Line 304: error: expected ';' before 'GetWeaponSlotClipAmmo'
Line 305: error: 'wait' undeclared (first use in this function)
Line 305: error: expected ';' before numeric constant
Line 306: error: 'weap2' undeclared (first use in this function)
Line 306: error: expected ';' before 'GetCurrentWeapon'
Line 307: error: 'slot2' undeclared (first use in this function)
Line 308: error: 'ammo2' undeclared (first use in this function)
Line 308: error: expected ';' before 'GetWeaponSlotAmmo'
Line 309: error: 'clip2' undeclared (first use in this function)
Line 309: error: expected ';' before 'GetWeaponSlotClipAmmo'
Line 311: error: expected ')' before 'GetWeaponSlotAmmo'
Line 318: error: expected ')' before 'GetWeaponSlotAmmo'
Line 321: error: 'ammo' undeclared (first use in this function)
Line 322: error: expected ';' before 'SetWeaponSlotAmmo'
Line 325: error: expected ')' before 'GetWeaponSlotAmmo'
Line 329: error: 'true' undeclared (first use in this function)
Line 338: error: 'clip' undeclared (first use in this function)
Line 343: error: expected ';' before 'SetWeaponSlotAmmo'
Line 344: error: expected ';' before 'SetWeaponSlotClipAmmo'
Line 348: error: expected ';' before 'SetWeaponSlotAmmo'
Line 349: error: expected ';' before 'SetWeaponSlotClipAmmo'
Line 352: error: expected ';' before 'GetCurrentWeapon'
Line 354: error: expected ';' before 'GetWeaponSlotAmmo'
Line 355: error: expected ';' before 'GetWeaponSlotClipAmmo'
Line 356: error: expected ';' before numeric constant
Line 357: error: expected ';' before 'GetCurrentWeapon'
Line 359: error: expected ';' before 'GetWeaponSlotAmmo'
Line 360: error: expected ';' before 'GetWeaponSlotClipAmmo'


Create a new paste based on this one


Comments: