To clarify:
My plan is to make a weapon base with predefined state sequences, including a predefined reload state.
I want to be able to inherit from this weapon base as to not have to constantly copy/paste identical states.
In the reload state, rather than having to specify the ammo itself, I'd rather reference the AmmoType1/AmmoType2 properties.
My initial guess was to do "A_TakeInventory(Weapon.AmmoType2, 1)" but that doesn't seem to work.
Would I have to create a function for this to work the way I'd like it to?
At first I expected to be able to use "A_TakeInventory(invoker.AmmoType1, 1);" but it seems I'm not able to directly read the value that I want to.
Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
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!)
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!)
-
- Posts: 27
- Joined: Tue Nov 21, 2023 10:30 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: Intel (Modern GZDoom)
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
-
- Posts: 27
- Joined: Tue Nov 21, 2023 10:30 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: Intel (Modern GZDoom)
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
Of course, the full script I was using is as follows:
Code: Select all
Class PistolVM : Weapon
{
protected name modelName, AmmoClip, AmmoReserve;
property modelFile : modelName; //used to append model files in subsequent weapons that inherit from this one
property AmmoClip : AmmoClip; //used to append AmmoType1
property AmmoReserve : AmmoReserve; //used to append AmmoType2
Default
{
PistolVM.modelFile 'vm_arms.iqm';
Weapon.SlotNumber 2;
+WEAPON.AMMO_OPTIONAL
+DECOUPLEDANIMATIONS
+WEAPON.CHEATNOTWEAPON
}
States
{
Spawn:
MSVN A 0 NoDelay
{
A_ChangeModel("", 1, "models/viewmodels", invoker.modelName);
A_SetAnimation("VMPistol_Idle", 25);
}
MSVN A 1;
Loop;
Ready:
MSVN A 0
{
A_SetAnimation("VMPistol_Idle", 25, flags:SAF_LOOP);
}
MSVN A 50 A_WeaponReady;
Loop;
Select:
MSVN A 0
{
A_ChangeModel("", 1, "models/viewmodels", invoker.modelName);
A_SetAnimation("VMPistol_Idle", 25);
}
MSVN A 1 A_Raise;
Loop;
Deselect:
MSVN A 0
{
A_SetAnimation("VMPistol_Idle", 25);
}
MSVN A 1 A_Lower;
Loop;
Fire:
TNT1 A 0 A_JumpIfNoAmmo("Reload");
MSVN A 1 A_SetAnimation("VMPistol_Fire", 25);
MSVN A 19
{
A_FireProjectile("BulletProjectile", angle:frandom(-1,2.5), spawnofs_xy:12, spawnheight:2, pitch:frandom(-1,1));
A_StartSound("GUNSHOT", CHAN_WEAPON);
}
MSVN A 0;
Goto Ready;
Reload: //the problem starts here, possibly in IsReloading aswell
TNT1 A 0 A_JumpIfInventory(invoker.AmmoType1, 8, 2);
TNT1 A 0 A_JumpIfInventory(invoker.AmmoType2, 1, "IsReloading");
GoTo Ready;
IsReloading:
MSVN A 45 A_SetAnimation("VMPistol_Reload", 25);
MSVN A 25
{
A_TakeInventory(invoker.AmmoType2, 1);
A_SetInventory(invoker.AmmoType1, 8);
}
MSVN A 0;
Goto Ready;
}
}
//Pistol Magazine class, unimportant, i think
Class PistolMag : Ammo
{
Default
{
Inventory.Amount 0;
Inventory.MaxAmount 0;
+INVENTORY.IGNORESKILL
}
States
{
Spawn:
MSVN A 1;
Loop;
}
}
https://drive.google.com/file/d/1K1skT ... p=sharing
Honestly, I was fully prepared to create an action function to use in the reloading sequence but that hasn't proved much more successful for me.
Also: please ignore "AmmoClip" and "AmmoReserve", they're left over from the action function I tried making
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
First of all, please note that I cannot debug this because the sprites are missing.
What I can see is that you don't have ammo types defined for your weapon (Weapon.AmmoType1 and Weapon.AmmoType2 respectively). Since you haven't done that, the corresponding fields are set to null, and of course A_TakeInventory et al. aren't going to work... because there is nothing to take or give.
If you do have a weapon where those properties are correctly set, and it still isn't working right - please provide the code, preferably one I can run out of the box. Your link doesn't work: it says I don't have access to the file.
P.S. You might also consider using this if you want reloadable weapons.
What I can see is that you don't have ammo types defined for your weapon (Weapon.AmmoType1 and Weapon.AmmoType2 respectively). Since you haven't done that, the corresponding fields are set to null, and of course A_TakeInventory et al. aren't going to work... because there is nothing to take or give.
If you do have a weapon where those properties are correctly set, and it still isn't working right - please provide the code, preferably one I can run out of the box. Your link doesn't work: it says I don't have access to the file.
P.S. You might also consider using this if you want reloadable weapons.
-
- Posts: 27
- Joined: Tue Nov 21, 2023 10:30 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: Intel (Modern GZDoom)
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
Thank you, I'll look into the reloading system provided and see if I can save myself a headache lolPlayer701 wrote: ↑Fri Nov 22, 2024 12:59 am First of all, please note that I cannot debug this because the sprites are missing.
What I can see is that you don't have ammo types defined for your weapon (Weapon.AmmoType1 and Weapon.AmmoType2 respectively). Since you haven't done that, the corresponding fields are set to null, and of course A_TakeInventory et al. aren't going to work... because there is nothing to take or give.
If you do have a weapon where those properties are correctly set, and it still isn't working right - please provide the code, preferably one I can run out of the box. Your link doesn't work: it says I don't have access to the file.
P.S. You might also consider using this if you want reloadable weapons.
Also, my apologies for the link, I forgot to open access. This should work now:
https://drive.google.com/file/d/1K1skT ... p=sharing
In the IPK3, the script in question is under "scripts/viewmodels/vm_pistolGuide.txt"
I'm trying to use the "PistolVM" weapon as a base for other weapons to use inheritance
Again, sorry for making this one a little harder than it needed to be, and I appreciate the guidance.
-
-
- Posts: 1693
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
Thank you for fixing the link.
I can see that you're calling DepleteAmmo(true, true), the first argument in this case means to use alternate ammo. But that won't work as your weapon does not have an alt-fire state, and furthermore, your AmmoUse2 is set to 0, so it wouldn't have had any effect anyway.
You should use A_TakeInventory(invoker.AmmoType2, 1) instead. I just tried this myself, and it worked. Or, you can simply subtract the amount directly, e.g. invoker.Ammo2.Amount--.
I can see that you're calling DepleteAmmo(true, true), the first argument in this case means to use alternate ammo. But that won't work as your weapon does not have an alt-fire state, and furthermore, your AmmoUse2 is set to 0, so it wouldn't have had any effect anyway.
You should use A_TakeInventory(invoker.AmmoType2, 1) instead. I just tried this myself, and it worked. Or, you can simply subtract the amount directly, e.g. invoker.Ammo2.Amount--.
-
- Posts: 27
- Joined: Tue Nov 21, 2023 10:30 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: Intel (Modern GZDoom)
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
Honestly, as well as the "clip" was working, I couldn't get past the infinite "reserve ammo" issue, so I ended up going with RRWM reloading system.Player701 wrote: ↑Fri Nov 22, 2024 3:33 am Thank you for fixing the link.
I can see that you're calling DepleteAmmo(true, true), the first argument in this case means to use alternate ammo. But that won't work as your weapon does not have an alt-fire state, and furthermore, your AmmoUse2 is set to 0, so it wouldn't have had any effect anyway.
You should use A_TakeInventory(invoker.AmmoType2, 1) instead. I just tried this myself, and it worked. Or, you can simply subtract the amount directly, e.g. invoker.Ammo2.Amount--.
The only thing is: gzdoom keeps telling me that I "Cannot use non-action function here" wherever I use A_ReloadableWeaponReady or A_ReloadFullClip in a state
I've tried inserting those functions into an anonymous function, but the error becomes "Function is incompatible with current context"
does it matter that I'm trying to call these functions in zscript and not a decorate script?
-
- Posts: 27
- Joined: Tue Nov 21, 2023 10:30 pm
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 11
- Graphics Processor: Intel (Modern GZDoom)
Re: Is there a way to reference AmmoType1/AmmoType2 when using A_TakeInventory/A_GiveInventory?
my bad, just found out about the states(weapon) solution in another thread