I Making a Pistol that Reloads, but something is very wrong

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!)
Post Reply
User avatar
Thfpjct
Posts: 15
Joined: Thu Jul 18, 2019 9:36 pm
Graphics Processor: ATI/AMD (Modern GZDoom)

I Making a Pistol that Reloads, but something is very wrong

Post by Thfpjct »

I don't know what is Happening with my game or with my Code.

It's a Pistol that Reload, but some flags don't work for some reason, and if i remove the flags from the code (the flags: Noautofire and Ammo_Optional) the weapon can't be hold in game, Like, i can summon the Pickup item, i can Pickup, but it won't let me choose it.



I still working on the reload. this problems had show up in the beginning of the codding but it wasn't bugging me of until now.



I am in the middle of the Gunlabs tutorial, and din't sayed anything about this kind problem happening.



Code:

Code: Select all

Actor Revolverd : weapon 
{
Obituary "%o Was Killed by %k Revolver'd"
Attacksound "SHOTTING/Pistolfire" //som do ataque/tiro
Inventory.pickupmessage "Pickup a Revolver"
Weapon.Slotnumber 2

Weapon.BobSpeed 1.3
Weapon.BobRangeX 1.0
Weapon.BobRangey 1.0
Weapon.BobStyle Inverse

Weapon.AmmoUse2 0
Weapon.AmmoType2 "6mm"
Weapon.AmmoGive2 20

Weapon.AmmoUse1 1
Weapon.AmmoType1 "REVReloaded"
Weapon.AmmoGive1 0

+Weapon.Noautofire
+Weapon.Ammo_Optional

	STATES
	
	{
	SPAWN:
	GMSP A -1
	STOP
	
	READY:
	GMPI A 1 A_Weaponready(WRF_ALLOWRELOAD)
	Loop
	
	SELECT:
	GMPI A 1 A_Raise
	Loop
	
	DESELECT:
	GMPI A 1 A_Lower
	Loop
	
	FIRE:
	GMPI B 1 A_FIREBULLETS(1,1,1,6,"BULLETPUFF")
	TNT1 A 0 A_SetPitch(pitch-1.3)
	TNT1 A 0 A_Gunflash ("FLASH")
	GMPI C 2
	GMPI A 5 A_REFIRE
	GOTO READY
	
	RELOAD:
	RELO A 1
	RELO B 1 A_Playsound ("DRYFIRE/Pistol")
	RELO C 4
	RELO D 4
	RELO E 4
	RELO F 4
	RELO G 1
	TNT1 A 0 A_GiveInventory("REVReloaded", 12)
	TNT1 A 0 A_TakeInventory("6mm", 1)
	GOTO Ready
	
	FLASH:
	MUZL A 1 BRIGHT A_Light(1)
	GOTO LightDone
	}
}

ACTOR 6mm : Ammo Replaces Clip
{
Inventory.PickupMessage "You Got ammo for Revolverd"
Inventory.Amount 5
Inventory.MaxAmount 100
Inventory.Pickupsound "BERETTA/drop"
Ammo.BackpackAmount 60
Ammo.BackpackMaxAmount 600
Inventory.Icon "CLIPA0"
STATES
	{
		
	SPAWN:
	CLIP A -1
	STOP
	}
}

ACTOR REVReloaded : Ammo
	{
	Inventory.MaxAmount 12
	+IGNORESKILL
	}

File:
https://www.doomworld.com/applications/ ... p?id=62600
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: I Making a Pistol that Reloads, but something is very wr

Post by Void Weaver »

The flags works as usual, nothing odd here.
You just should place check for ammo presence at the begining of 'Fire' state and similar check in the 'Reload', smth. like as:

Code: Select all

Fire:   
TNT1 A 0 A_JumpIf(CountInv("REVReloaded")<1,"Reload") //If have no [u]primary fire ammo[/u], then try to reload
<rest of code>

Code: Select all

Reload:
TNT1 A 0 A_JumpIf(CountInv("6mm")<1,"Deselect") //If have no [u]main ammo[/u] too, then we are totally empty, deselect it, otherwise just reload it.
<rest of code>
Btw, Weapon.SelectionOrder and Weapon.SlotPriority properties will be useful too for weaponsmithing.
Also I'd recomend you to set A_TakeInventory("6mm",12) instead of taking only 1 unit, OR just significantly reduce Inventory.MaxAmount and
Ammo.BackpackMaxAmount. Because now pistol can hold from 1200 (12*100) to 7200 (12*600) shots!
Post Reply

Return to “Scripting”