Help for this M16A2/M203 code

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
YukesVonFaust
Posts: 1353
Joined: Mon Feb 09, 2015 9:00 am
Location: in an undisclosed location that is the philippines

Help for this M16A2/M203 code

Post by YukesVonFaust »

I was working on a mod which you can use the M16 with a M203 in it.
after i fire the single 40mm round, i press the zoom button and it still fires!
so i need help. 'cause i need tetriary fire that uses the M203...
here's the code:

Code: Select all

Actor M4A1 : FaustWeapon
{
	inventory.pickupmessage "Colt M16A2 assault rifle with M203 Grenade Launcher (5)"
	Weapon.SlotNumber 5
	weapon.kickback 100
	Weapon.AmmoType "M4A1Mag"
	Weapon.AmmoUse1 1
	weapon.ammotype2 "556Ammo"
	weapon.ammouse2 1
	weapon.ammogive2 30
	ConversationID 195
	Tag "Colt M16A2 w/ M203"
	+Weapon.NoAutofire
	States
	{
	Ready:
		M4A1 A 0 A_JumpIfInventory("M4A1Mag",0,2)
		M4A1 A 0 A_JumpIfInventory("556Ammo",1,2)
		M4A1 A 0 A_JumpIfInventory("M203Loaded",0,2)
		M4A1 A 0 A_JumpIfInventory("40mmAmmo",1,2)
		M4A1 A 1 A_WeaponReady(WRF_ALLOWZOOM)
		Loop
		M4A1 A 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWZOOM)
		Loop
	Deselect:
		M4A1 A 0 A_Lower
		M4A1 A 1 A_Lower
		Loop
	Select:
		M4A1 A 0 A_Raise
		M4A1 A 1 A_Raise
		Loop
	Fire:
		TNT1 A 0
	BurstMe:
		M4A1 A 0 A_JumpIfInventory("M4A1Mag",1,1)
		Goto Dryfire
		M4A1 A 0 A_JumpIfInventory ("BurstFireCapabilityStuffy",0,"DoneFiring")
		M4A1 A 0 A_Jump(250,2)
		M4A1 A 0 A_PlaySound("*taunt", CHAN_VOICE)
		M4A1 A 0 A_GunFlash
		M4A1 A 0 A_Jump(128, "BurstMe2", "BurstMe3")
		M4A1 A 0 A_PlayWeaponSound("m4a1/fire")
		M4A1 B 1 bright A_FireCustomMissile("556Tracer",frandom(-1.5,1.5),2,6,4.3,3.5,frandom(-1.5,1.5))
		M4A1 D 2 Offset(0,37) A_SetPitch(pitch - 0.5)
	DoneBursting:
		M4A1 A 0 A_GiveInventory("BurstFireCapabilityStuffy", 1)
		TNT1 A 0 A_ReFire("BurstMe")
		TNT1 A 0 A_CheckReload
		Goto DoneFiring
	BurstMe2:
		M4A1 A 0 A_JumpIfInventory("M4A1Mag",1,1)
		Goto Dryfire
		M4A1 A 0 A_PlayWeaponSound("m4a1/fire")
		M4A1 C 1 bright A_FireCustomMissile("556Tracer",frandom(-1.5,1.5),2,6,4.3,3.5,frandom(-1.5,1.5))
		M4A1 D 2 Offset(0,37) A_SetPitch(pitch - 0.5)
		Goto DoneBursting
	BurstMe3:
		M4A1 A 0 A_JumpIfInventory("M4A1Mag",1,1)
		Goto Dryfire
		M4A1 A 0 A_PlayWeaponSound("m4a1/fire")
		M4A1 B 1 bright A_FireCustomMissile("556Tracer",frandom(-1.5,1.5),2,6,4.3,3.5,frandom(-1.5,1.5))
		M4A1 D 2 Offset(0,37) A_SetPitch(pitch - 0.5)
		Goto DoneBursting
	DoneFiring:
		M4A1 D 1 Offset(0,36) A_TakeInventory ("BurstFireCapabilityStuffy")
		M4A1 E 1 Offset(0,34) A_AlertMonsters
		TNT1 A 0 A_CheckReload
		Goto Ready
	Zoom:
		M4A1 A 0 A_JumpIfInventory("M203Loaded",0,1)
		Goto Dryfire
		M1M2 AB 2
		M1M2 C 5
		M4A1 A 0 A_GunFlash
		M23F A 0 A_AlertMonsters
		M23F A 2 Bright A_PlayWeaponSound("MGL/Fire")
		M23F B 1 Bright A_FireCustomMissile("40mmGrenadeProjectile",0,0,4,2,0)
		M1M2 C 6
		M1M2 CBA 2
		TNT1 A 0 A_CheckReload
		Goto Ready
	Dryfire:
		M4A1 A 0 A_JumpIfInventory("M203Loaded",0,"Reload2")
		M4A1 A 1
		Goto Ready
	Reload:
		M4A1 A 1 Offset(0,35)
		TNT1 A 0 A_Jump(160,2)
		TNT1 A 0 A_PlaySound("*taunt", CHAN_VOICE)
		M4A1 A 1 Offset(0,38) A_PlaySound("m4a1/reload",CHAN_ITEM)
		M4A1 A 1 Offset(0,44)
		M4A1 A 1 Offset(-2,46)
		M4A1 A 1 Offset(-4,52)
		M4A1 A 1 Offset(-7,56)
		M4A1 A 1 Offset(-10,57)
		M4A1 A 8 Offset(-11,58)
		Goto ReloadLoop
	ReloadLoop:
		TNT1 A 0 A_TakeInventory("556Ammo",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_GiveInventory("M4A1Mag",1)
		TNT1 A 0 A_JumpIfInventory("M4A1Mag",30,"ReloadFinish")
		TNT1 A 0 A_JumpIfInventory("556Ammo",1,"ReloadLoop")
		Goto ReloadFinish
	ReloadFinish:
		M4A1 A 1 Offset(-10,58)
		M4A1 A 1 Offset(-10,61)
		M4A1 A 1 Offset(-10,65)
		M4A1 A 1 Offset(-10,71)
		M4A1 A 1 Offset(-10,82)
		M4A1 A 1 Offset(-10,103)
		M4A1 A 55 Offset(-10,127)
		M4A1 A 1 Offset(-10,103)
		M4A1 A 1 Offset(-10,82)
		M4A1 A 1 Offset(-10,71)
		M4A1 A 1 Offset(-10,65)
		M4A1 A 1 Offset(-10,60)
		M4A1 A 1 Offset(-10,55)
		M4A1 A 1 Offset(-10,53)
		M4A1 A 1 Offset(-10,51)
		M4A1 A 1 Offset(-9,50)
		M4A1 A 1 Offset(-8,46)
		M4A1 A 1 Offset(-7,43)
		M4A1 A 1 Offset(-5,40)
		M4A1 A 1 Offset(-3,37)
		M4A1 A 1 Offset(-1,34)
		M4A1 A 1 Offset(0,32)
		Goto Ready
	Reload2:
		TNT1 A 0 A_Jump(160,2)
		TNT1 A 0 A_PlaySound("*taunt", CHAN_VOICE)
		M1M2 B 2 Offset(1,33)
		M1M2 B 2 Offset(2,34)
		M1M2 B 2 Offset(3,35)
		M1M2 B 2 Offset(4,36)
		M1M2 B 2 Offset(4,43)
		M1M2 B 1 Offset(4,50)
		M1M2 B 1 Offset(5,58)
		M1M2 B 1 Offset(5,67)
		M1M2 B 1 Offset(5,71)
		M1M2 B 1 Offset(5,77)
		M1M2 B 1 Offset(4,83)
		M1M2 B 1 Offset(3,89)
		M1M2 B 1 Offset(3,94)
		M1M2 B 1 Offset(2,100)
		M1M2 B 1 Offset(2,102)
		M1M2 B 1 Offset(1,104)
		M1M2 B 1 Offset(1,106)
		M1M2 B 1 Offset(-1,108)
		M1M2 B 1 Offset(-3,112)
		M1M2 B 1 Offset(-5,116)
		M1M2 B 1 Offset(-7,120)
		M1M2 B 1 Offset(-10,124)
		M1M2 B 1 Offset(-14,126)
		M1M2 B 1 Offset(-18,128) A_PlaySound("RPG7/load1",CHAN_WEAPON)
		M1M2 A 1 Offset(-21,129)
		M1M2 A 1 Offset(-24,130)
		M1M2 A 1 Offset(-27,131)
		M1M2 A 1 Offset(-28,130)
		Goto ReloadLoop2
	ReloadLoop2:
		TNT1 C 0 A_TakeInventory("40mmAmmo",1,TIF_NOTAKEINFINITE)
		TNT1 C 0 A_GiveInventory("M203Loaded",1)
		TNT1 A 0 A_JumpIfInventory("M203Loaded",1,"ReloadFinish2")
		TNT1 A 0 A_JumpIfInventory("40mmAmmo",1,"ReloadLoop2")
		Goto ReloadFinish2
	ReloadFinish2:
		M1M2 A 1 Offset(-26,128)
		M1M2 A 1 Offset(-22,124)
		M1M2 A 1 Offset(-21,112) A_PlaySound("RPG7/load2",CHAN_WEAPON)
		M1M2 A 1 Offset(-20,108)
		M1M2 A 1 Offset(-19,98)
		M1M2 A 1 Offset(-18,88)
		M1M2 A 1 Offset(-17,78)
		M1M2 A 1 Offset(-16,68)
		M1M2 A 1 Offset(-15,57)
		M1M2 A 1 Offset(-14,46)
		M1M2 A 1 Offset(-12,42)
		M1M2 A 1 Offset(-11,38)
		M1M2 A 1 Offset(-8,35)
		M1M2 A 1 Offset(-6,32)
		M1M2 A 1 Offset(-2,28)
		M1M2 A 1 Offset(1,27)
		M1M2 A 1 Offset(-1,29)
		Goto Ready
	Flash:
		TNT1 A 2 A_Light2
		TNT1 A 2 A_Light1
		Goto LightDone
	Spawn:
		M4A1 P -1
		Stop
	}
}
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Help for this M16A2/M203 code

Post by wildweasel »

The problem is that A_JumpIfInventory interprets zero value differently than you might expect. If it is given an amount of 0, it will jump only if M203Loaded is at its MAXIMUM possible value. So when the M203 is loaded, the resulting fire state goes through its motions, but at no point actually takes M203Loaded from the player's inventory, so the checks for it to be 0 are still passing as True (your Dryfire state, for example, will only go to Reload2 if the weapon is already loaded).
User avatar
YukesVonFaust
Posts: 1353
Joined: Mon Feb 09, 2015 9:00 am
Location: in an undisclosed location that is the philippines

Re: Help for this M16A2/M203 code

Post by YukesVonFaust »

wildweasel wrote:The problem is that A_JumpIfInventory interprets zero value differently than you might expect. If it is given an amount of 0, it will jump only if M203Loaded is at its MAXIMUM possible value. So when the M203 is loaded, the resulting fire state goes through its motions, but at no point actually takes M203Loaded from the player's inventory, so the checks for it to be 0 are still passing as True (your Dryfire state, for example, will only go to Reload2 if the weapon is already loaded).
anything i can fix it?
like putting 1 on 0?
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Help for this M16A2/M203 code

Post by wildweasel »

Well, what you'll want to do is rearrange the way the Zoom and Reload2 states are doing their checking. Think backwards - you can't check for an absence of an item, only the presence of it. So your initial A_JumpIfInventory should check for 1 of M203Loaded, and then jump to a LaunchGrenade state if that check passes as True. If the check fails, then fall through to Dryfire, which should check if the player has any extra grenades, going to Reload2 if he does, and falling through to an extra failure state if he does not.
User avatar
YukesVonFaust
Posts: 1353
Joined: Mon Feb 09, 2015 9:00 am
Location: in an undisclosed location that is the philippines

Re: Help for this M16A2/M203 code

Post by YukesVonFaust »

Got it working now. Replaced the M203Loaded with GrenadeSequency actor! thanks!
Locked

Return to “Editing (Archive)”