Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
Voros

Need help with reloading function

Question


ACTOR PerkShotgun : Shotgun replaces Shotgun
{
+WEAPON.NOALERT
decal bulletchip
Weapon.AmmoUse1 0
Weapon.AmmoUse2 0
Weapon.AmmoType1 "Shell"
Weapon.AmmoType2 "ShotgunAmmo"
States
{
Ready:
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",1,"M3")
TNT1 A 0 A_GiveInventory("FullEmptyShotgun",1)
M3:PKSG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
Loop
Fire:
TNT1 A 0 A_JumpIfInventory("Reloading",1,"ReloadFinish")
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",1,1)
Goto NoAmmo
TNT1 A 0 A_JumpIfInventory("ShotgunPump",1,1)
Goto NoAmmo
PKSG A 3
PKSG A 1 Offset(0,40) A_FireBullets (5.6, 0, 7, 5, "BulletPuff")
PKSG A 2 Offset(0,36) A_PlaySound("ShotgunFire", CHAN_WEAPON)
TNT1 A 0 A_AlertMonsters
PKSG A 4 Offset(0,33) A_GunFlash
TNT1 A 0 A_TakeInventory("ShotgunPump",1)
TNT1 A 0 A_JumpIfInventory("Reloading",1,"ReloadFinish")
TNT1 A 0 A_JumpIfInventory("ShotgunPump",1,"Ready")
PKSG B 2
PKSG C 1
PKSG D 2
PKSG E 3
TNT1 A 0 A_PlaySound("ShotgunPump")
PKSG F 4
PKSG G 1
//Goto Reload
PKSG H 3
PKSG GFEDCB 2
PKSG A 1
Goto Ready
Reload:
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",1,"NotFullEmpty")
TNT1 A 0 A_GiveInventory("FullEmptyShotgun",1)
TNT1 A 0 A_GiveInventory("ShotgunPump",1)
Goto AltFire
NotFullEmpty:
TNT1 A 0 A_JumpIfInventory("FullEmptyShotgun",1,"skip")
TNT1 A 0 A_TakeInventory("ShotgunAmmo",1)
skip:TNT1 A 0 A_GiveInventory("ShotgunPump",1)
TNT1 A 0 A_TakeInventory("FullEmptyShotgun",1)
PKSG H 3
PKSG GFEDCB 2
PKSG A 1
PKSG A 7
Goto Ready
NoAmmo:
PKSG A 15 A_PlaySound("weapons/empty")
Goto Ready
AltFire:
//Reload:
TNT1 A 0 A_JumpIfInventory("Shell",1,1)
Goto Ready
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",8,"Ready")
PKSG ABCDEF 2
TNT1 A 0 A_GiveInventory("Reloading",1)
ReloadRepeat:
TNT1 A 0 A_JumpIfInventory("FullEmptyShotgun",1,"7Shells")
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo", 8, "ReloadFinish")
TNT1 A 0 A_JumpIfInventory("Shell", 1, "Skip7")
Goto ReloadFinish
7Shells:
TNT1 A 0 A_JumpIfInventory("ShotgunAmmo", 7, "ReloadFinish")
TNT1 A 0 A_JumpIfInventory("Shell", 1, 1)
Goto ReloadFinish
Skip7:
TNT1 A 0 A_GiveInventory("ShotgunAmmo", 1)
TNT1 A 0 A_Takeinventory("Shell",1)
TNT1 A 0 A_JumpIfInventory("FullEmptyShotgun",1,"M2")
SGRE ABCDE 1
SGRE F 2 A_PlaySound("insertshell")
SGRE GHIJ 1
PKSG F 5 A_WeaponReady(WRF_NOBOB)
Goto ReloadRepeat
M2:TNT1 A 0 A_TakeInventory("ShotgunPump",1)
SGRE ABCDE 1
SGRE F 2 A_PlaySound("insertshell")
SGRE GHIJ 1
PKSG F 5 A_WeaponReady(WRF_NOBOB)
Goto ReloadRepeat
ReloadFinish:
PKSG FEDCBA 2
TNT1 A 0 A_TakeInventory("Reloading",1)
Goto Ready
Flash:
SHTF B 3 Bright A_Light2
SHTF A 2 Bright A_Light1
Goto LightDone
Deselect:
TNT1 A 0 A_JumpIfInventory("Reloading",1,"Deselect2")
D:SHTG A 1 A_Lower
Goto D
Deselect2:
TNT1 A 0 A_Takeinventory("Reloading",1)
PKSG FEDCBA 2
D2:SHTG A 1 A_Lower
Goto D2
}
}


This is a modified portion of DECORATE, showing only the shotgun. It doesn't work as intended.

I want to set the altfire state to be the reload, which means it'll show the shell inserting sprites first then the pumping sprites always. In the fire state, it automatically pumps the shotgun until it's 0, but the code is buggy.

I'm not that familiar with reloading mechanisms in DECORATE, so I'm asking what should I change to get what I want?

Link to the mod I'm modifying

Share this post


Link to post

3 answers to this question

Recommended Posts

  • 1

I couldn't make sense from the flow logic in your code, so I ended up mostly remaking the code according to your description of intended functionality. Please look at the code closely and try to understand how and why it works by yourself. Everything I changed has a reason - notice for example the flash offsets or that I got rid of 2 inventory actors. Also, don't paste unformatted code next time, use the code box, not spoiler box alone. Finally, I feel that I've spent too many hours on this that you could have spent yourself instead, so again, try to learn from what I've done so it doesn't go in vain, and don't expect me to do too much work for you again.

 

Spoiler

ACTOR PerkShotgun : Shotgun replaces Shotgun
{
	+WEAPON.NOALERT
	decal bulletchip
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoType1 "Shell"
	Weapon.AmmoType2 "ShotgunAmmo"
	States
	{
	Ready:
		PKSG A 1 A_WeaponReady
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"PumpFinish")
		TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",1,"FireBegin")
		TNT1 A 0 A_PlaySound("weapons/empty")
		PKSG AAAAAAAAAAAAAAA 1 A_WeaponReady(WRF_NOPRIMARY)
		Goto Ready
	FireBegin:
		PKSG A 3
		TNT1 A 0 A_FireBullets (5.6,0,7,5,"BulletPuff")
		TNT1 A 0 A_TakeInventory("ShotgunAmmo",1)
		TNT1 A 0 A_PlaySound("ShotgunFire",CHAN_WEAPON)
		TNT1 A 0 A_AlertMonsters
		PKSG A 1 Offset(0,40) A_GunFlash
		PKSG A 2 Offset(0,36)
		PKSG A 4 Offset(0,33)
		TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",1,"FireFinish")
		Goto Ready
	FireFinish:
		PKSG B 2
		PKSG C 1
		PKSG D 2
		PKSG E 3
	PumpFinish:
		PKSG F 4 A_PlaySound("ShotgunPump")
		PKSG G 1
		PKSG H 3
		PKSG G 2
		PKSG FEDCB 2
		PKSG A 1 A_TakeInventory("Reloading",1)
		Goto Ready
	AltFire:
		TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",8,"Ready")
		TNT1 A 0 A_JumpIfInventory("Shell",1,"ReloadBegin")
		Goto Ready
	ReloadBegin:
		PKSG ABCDEF 2
		TNT1 A 0 A_GiveInventory("Reloading",1)
	ReloadRepeat:
		TNT1 A 0 A_GiveInventory("ShotgunAmmo",1)
		TNT1 A 0 A_Takeinventory("Shell",1)
		SGRE ABCDE 1
		SGRE F 2 A_PlaySound("insertshell")
		SGRE GHIJ 1
		TNT1 A 0 A_JumpIfInventory("ShotgunAmmo",8,"PumpFinish")
		PKSG F 5 A_WeaponReady(WRF_NOBOB|WRF_NOSECONDARY)
		TNT1 A 0 A_JumpIfInventory("Shell",1,"ReloadRepeat")
		Goto PumpFinish
	Flash:
		TNT1 A 0 A_Light2
		SHTF B 1 Bright Offset(0,40)
		SHTF B 2 Bright Offset(0,36)
		TNT1 A 0 A_Light1
		SHTF A 2 Bright Offset(0,33)
		Goto LightDone
	Deselect:
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Deselect2")
		Goto DeselectLoop
	Deselect2:
		TNT1 A 0 A_Takeinventory("Reloading",1)
		PKSG FEDCB 2
	DeselectLoop:
		SHTG A 1 A_Lower
		Loop
	}
}

 

 

Share this post


Link to post
  • 1

I don't understand what you want. Please describe exactly what's supposed to happen:

-When the player presses regular fire button.

-When the player keeps holding regular fire button.

-When the player presses alt fire button.

-When the player keeps holding alt fire button.

-When the player presses reload button.

-Whatever else important to your vision.

Share this post


Link to post
  • 0

When player presses regular fire, the gun fires, removes one shell from the chamber (out of 8) and the shotgun pumps to insert a new shell.

Holding regular fire just repeatedly does the same thing as firing once, but it'll keep doing this until the shells in the chamber becomes 0. It'll then enter an "empty gun" state, to imply that no shells are in the shotgun and new shells have to be inserted.

Altfire is the reloading action. I'm perfectly of the Reload state, but I need it in AltFire. When player presses altfire, the raises up, the shell inserting animation plays repeatedly (depending on the number shells present in chamber) and once the number shells present in the chamber is 8, it'll play the pumping animation and goto Ready.

Holding altfire is useless here though. Pressing once must insert shells until the number of shells in the chamber becomes 8.

I need the reloading to be in AltFire state rather than the Reload state, so no use of Reload here.

That's pretty much it. Basically how Brutal Doom does it. I can probably start fresh and write my own reload code, but since I already "fixed" the other weapons without doing so, I hope I can do the same with the shotgun.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×