I'm trying to decipher some code here in order to modify it to do what I want. I'll refrain from saying what I want right now because I believe I can figure out how to do it if I can just get some help figuring out what everything means. I got a little bit of it figured out I think which I will note in the code.
The code is used to auto-reload the shotgun and grenade launcher that have been modified to have semi-automatic fire. Each weapon has a magazine of a limited amount of ammo it can hold. Once the player fires off a single round and stops firing, the gun automatically begins to reload, but stops if the player fires again.
Thanks to anyone who can provide some help.
Code:
============
W_WeaponFrame
Called every frame so impulse events can be handled as well as possible
============
*/
void() W_WeaponFrame = [COLOR="DarkOrange"] // Not sure about below, but I believe it is a countdown mechanism which prevents the player from firing before the weapon has been reloaded.[/COLOR]
{
if (time < self.attack_finished)
{
if (self.weapon == IT_GRENADE_LAUNCHER && !self.button0 && self.ammo_rockets > 0)
self.attack_finished = time;
else if (self.weapon == IT_SHOTGUN && !self.button0 && self.ammo_shells > 0)
self.attack_finished = time;
return;
}
ImpulseCommands ();
// check for attack [COLOR="DarkOrange"]// No idea about this one[/COLOR]
if (self.button0)
{
SuperDamageSound ();
W_Attack ();
}
else if (self.weapon == IT_GRENADE_LAUNCHER)
{ // autoload nade launcher
if (self.currentammo < 3 && self.currentammo < self.ammo_rockets) [COLOR="DarkOrange"] // the player may have a maximum of 3 rockets loaded and if there are ever less than three, and the weapon is not being fired, then it loads one rocket[/COLOR]
{
if (self.currentammo < 1 && self.cnt != 1)[COLOR="DarkOrange"] // check to see if ammo is 0 and self.cnt = 1?[/COLOR]
{
self.currentammo = 0;
self.cnt = 1; [COLOR="DarkOrange"] // Not sure[/COLOR]
sound (self, CHAN_ITEM, "weapons/grenade_open.wav", 1, ATTN_NORM);
}
if ((time > self.attack_finished + 0.41 && self.currentammo > 0) || time > self.attack_finished + 0.56) [COLOR="DarkOrange"] // this one is confusing me a bit though I know it must be related to the lines towards the top[/COLOR]
{
self.currentammo = self.currentammo + 1;
self.attack_finished = time;
sound (self, CHAN_ITEM, "weapons/grenade_load.wav", 1, ATTN_NORM);
}
}
else if (self.cnt == 1 && time > self.attack_finished + 0.41)
{
sound (self, CHAN_ITEM, "weapons/grenade_close.wav", 1, ATTN_NORM);
self.cnt = 0;
}
}
else if (self.weapon == IT_SHOTGUN)
{ // autoload shotgun
if (self.currentammo < 6 && self.currentammo < self.ammo_shells)
{
if (self.currentammo < 1 && self.cnt != 1)
{
self.currentammo = 0;
self.cnt = 1;
}
if ((time > self.attack_finished + 0.41 && self.currentammo > 0) || time > self.attack_finished + 0.56)
{
self.enemy = world; [COLOR="DarkOrange"] // I really want to know what this means[/COLOR]
self.currentammo = self.currentammo + 1; [COLOR="DarkOrange"] // Add 1 shell. not sure what dictates it though[/COLOR]
self.attack_finished = time; [COLOR="DarkOrange"] // Not sure[/COLOR]
sound (self, CHAN_ITEM, "weapons/sgload.wav", 1, ATTN_NORM);
}
}
else if (self.cnt == 1 && time > self.attack_finished + 0.41)
{
sound (self, CHAN_ITEM, "weapons/sgpump.wav", 1, ATTN_NORM);
self.cnt = 0;
}
}
};
Thanks to anyone who can provide some help.
Comment