** I have included the new code at the bottom **
I'm making a replacement for the chaingun that recharges ammo overtime, but I'm running into an issue. The code for the most part works, but the way it recharges isn't right. When you finish shooting the weapon, it's supposed to have a ~2 second cooldown before it starts recharging again. The main problem though is that the weapon doesn't seem to process something to do with the JustFired bool, meaning the gun doesn't care if you've just shot (or even if you're still shooting!) and will still recharge ammo anyways.
I'm still fairly new to zscript, so I'm not quite sure what I've done wrong here.
Code: Select all
class NewChaingun : Chaingun
{
bool JustFired;
property JustFired: JustFired;
Default
{
Weapon.SelectionOrder 900;
Weapon.AmmoType "ChaingunBullets";
Weapon.AmmoUse 1;
Weapon.AmmoGive 20;
Weapon.SlotNumber 4;
Weapon.SlotPriority 5;
Weapon.Kickback 50;
Inventory.Pickupmessage "$UN_CHAIN_PICKUP";
Tag "Recharging Chaingun";
AttackSound "weapons/chngun";
NewChaingun.JustFired false;
}
States
{
Select:
CHGG A 1 A_Raise;
Loop;
Deselect:
CHGG A 1 A_Lower;
Loop;
Ready:
CHGG A 1 A_WeaponReady;
Loop;
Fire:
CHGG A 6 {
A_FireBullets(5.6, 3, -1, 7, "BulletPuff");
A_GunFlash();
invoker.JustFired = true;
}
CHGG B 6 A_FireBullets(5.6, 0, -1, 7, "BulletPuff");
CHGG B 0 A_ReFire;
Goto Ready;
Flash:
CHGF A 6 Bright A_Light1;
CHGF B 6 Bright A_Light2;
Stop;
Spawn:
MGUN A -1;
Stop;
}
override void DoEffect() {
int TicsToCharge = 0;
if (owner && GetAge() % TICRATE == 0 && JustFired == false) {
owner.A_GiveInventory("ChaingunBullets");
} else if (JustFired == true) {
while (TicsToCharge % 70 == 0) {
TicsToCharge += 1;
}
JustFired = false;
}
}
}Code: Select all
class NewChaingun : Chaingun
{
int TicsToCharge;
property TicsToCharge: TicsToCharge;
Default
{
*snip*
NewChaingun.TicsToCharge 70;
// starts TicsToCharge at 70 because the charging function
// requires it to be at 70 to charge
//$Category "Weapons"
}
States
{
*snip*
Fire:
CHGG A 6 {
A_FireBullets(5.6, 3, -1, 7, "BulletPuff");
A_GunFlash();
invoker.TicsToCharge = 0;
}
*snip*
}
override void DoEffect() {
if (owner && GetAge() % TICRATE == 0 && TicsToCharge == 70) {
owner.A_GiveInventory("ChaingunBullets");
} else if (TicsToCharge < 70) {
TicsToCharge++;
}
}
}