Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Moderator:GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
6 posts
• Page 1 of 1
yum13241
Posts: 532
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Class ZSBattleRifle : ZMonstrousWeapon
{
Default
{
Obituary "$OB_BATTLERIFLE";
Tag "$TAG_BATTLERIFLE";
Weapon.SelectionOrder 650;
Weapon.SlotNumber 4;
Weapon.AmmoUse1 1;
Weapon.AmmoGive1 1;
Weapon.AmmoType1 "BRAmmo";
Weapon.AmmoType2 "Clip";
}
States
{
NoAmmo:
UACR A 1 A_CheckReload();
Goto Ready;
Select:
UACR A 1 A_Raise;
TNT1 A 0 A_Raise;
Loop;
Deselect:
UACR A 1 A_Lower;
TNT1 A 0 A_Lower;
Loop;
Ready:
TNT1 A 0 A_JumpIfNoAmmo("NoAmmo");
UACR A 1 A_WeaponReady(WRF_ALLOWRELOAD);
Loop;
Fire:
TNT1 A 0 A_JumpIfNoAmmo("NoAmmo");
TNT1 A 0 A_StartSound("weapons/battlerifleattack", CHAN_ITEM);
TNT1 A 0 A_GunFlash();
UACR Y 1 A_FireBullets(5, 0, 1, 10, "BulletPuff") ;
UACR A 1 A_Refire("Hold");
Hold:
TNT1 A 0 A_GunFlash();
UACR Z 1 A_FireBullets(5, 0, 1, 10, "BulletPuff") ;
UACR A 1 A_Refire("Fire");
Goto Ready;
ReloadFinish:
TNT1 A 0 A_JumpIfNoAmmo("Ready");
UACR N 2;
UACR O 2;
UACR P 2;
TNT1 A 0 A_StartSound("weapons/battlerifleunload", CHAN_ITEM);
UACR Q 2;
UACR R 8;
UACR S 2;
UACR T 2;
UACR U 2;
TNT1 A 0 A_StartSound("weapons/battlerifleload", CHAN_ITEM);
UACR K 3;
UACR L 5;
UACR M 3;
UACR A 6;
TNT1 A 0 A_StartSound("weapons/battleriflecock", CHAN_ITEM);
Goto Ready;
Flash:
TNT1 A 1 A_Light1;
TNT1 A 1 A_Light2;
Goto LightDone;
Spawn:
UACR X -1;
Stop;
}
}
ZMonstrousWeapon:
Spoiler:
Class ZMonstrousWeapon : Weapon //by phantombeta
{
Default
{
Weapon.BobStyle "Inverse";
}
States
{
Reload:
TNT1 A 0 {
if (CheckInventory (invoker.ammoType1, 0) || !CheckInventory (invoker.ammoType2, 1))
return ResolveState ("Ready");
int ammoAmount = min (FindInventory (invoker.ammoType1).maxAmount - CountInv (invoker.ammoType1), CountInv (invoker.ammoType2));
if (ammoAmount <= 0)
return ResolveState ("Ready");
GiveInventory (invoker.ammoType1, ammoAmount);
TakeInventory (invoker.ammoType2, ammoAmount);
return ResolveState ("ReloadFinish");
}
}
}
Here's how I want weapon switching to work:
1. If I have Clips, but NO BRAmmo, and if the player presses fire, reload the gun. Do NOT make the gun unselectable.
2. If I have BRAmmo, but NO Clips, then do not allow reloading and DO NOT make the gun unselectable (seems to be handled by ZMonstrousWeapon alr)
3. If I have NO BRAmmo AND Clips, then switch away and make the gun UNSELECTABLE.
4. If I have both, then just continue as normal. (I can reload as long as BRAmmo isn't at max and I have Clips)
Now obviously if the user has "Check Weapon Switch" OFF then I want to respect that and make the gun unconditionally selectable (just switch away when they try to fire)
How do I do this?
+WEAPON.AMMO_CHECKBOTH won't work here.
Last edited by yum13241 on Tue Dec 20, 2022 11:26 am, edited 2 times in total.
The best you can do is to add the +WEAPON.AMMO_OPTIONAL flag and make custom logic before firing/reloading.
But I don't know of any way to make a weapon not selectable with that flag.
Blue Shadow wrote: ↑Tue Dec 20, 2022 11:29 pm
Have you thought about trying a weapon reloading library, like this one?
Being the author of that library in question, I can confirm it works just like the OP wants it to - especially considering that I was aiming for the exact same behavior. The need for the AMMO_OPTIONAL flag is a known issue with many reloading systems out there - or at least it was, when I first started working on mine, so I specifically wanted to avoid using that flag. Please read the instructions carefully and study the provided examples, and if you're still having issues, don't hesitate to ask (but preferably in the library thread and not here).