Didn't read the whole tutorial, how silly of me. Anyway, this is just a refined version of GunLab's Weapon Reload Tutorial.
I can understand why some mod makers went with the "count the shots and then inconvenience the player" method, I mean, just look at how complicated this code is:
Here's my code:
Code: Select all
Actor Pistol2 : Pistol //Note that you should use "Pistol2PickUp" for obtaining the weapon.
{
Weapon.SlotNumber 0 //To make it easier to differentiate it from the original pistol.
Weapon.AmmoType1 "PistolLoad"
Weapon.AmmoGive1 20
Weapon.AmmoUse1 1
Weapon.AmmoType2 "Clip"
AttackSound "weapons/pistol"
+WEAPON.AMMO_OPTIONAL //Prevent the weapon from deselecting when running out of ammo, allowing the player to reload it.
States
{
Ready:
PISG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
Loop
Fire:
PISG A 0 A_JumpIfNoAmmo("Reload")
PISG A 4
PISG B 0 A_FireBullets(5.6, 0, 1, 5, "BulletPuff")
PISG B 6 A_GunFlash
PISG C 4
PISG B 5 A_ReFire
Goto Ready
Reload:
TNT1 A 0 A_JumpIfInventory("PistolLoad", 20, "Full")
TNT1 A 0 A_JumpIfInventory("PowerInfiniteAmmo", 1, "InfiniteReload")
TNT1 A 0 A_JumpIfInventory("PistolLoad", 1, "TopUpReload")
TNT1 A 0 A_JumpIfInventory("Clip", 20, 1)
Goto IncompleteReload
TNT1 A 35 //Reload Animation
TNT1 A 0 A_TakeInventory("Clip", 20)
TNT1 A 0 A_GiveInventory("PistolLoad", 20)
Goto Ready
TopUpReload:
TNT1 A 0 A_JumpIfInventory("Clip", 20, 1)
Goto IncompleteTopUpReload
TNT1 A 35 //Reload Animation
UnitTopUpReload:
TNT1 A 0 A_TakeInventory("Clip", 1)
TNT1 A 0 A_GiveInventory("PistolLoad", 1)
TNT1 A 0 A_JumpIfInventory("PistolLoad", 20, "Ready")
Goto UnitTopUpReload
IncompleteTopUpReload:
TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
Goto NoAmmo
TNT1 A 35 //Reload Animation
UnitIncompleteTopUpReload:
TNT1 A 0 A_TakeInventory("Clip", 1)
TNT1 A 0 A_GiveInventory("PistolLoad", 1)
TNT1 A 0 A_JumpIfInventory("Clip", 1, "UnitIncompleteTopUpReload")
Goto Ready
IncompleteReload:
TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
Goto NoAmmo
TNT1 A 35 //Reload Animation
UnitIncompleteReload:
TNT1 A 0 A_TakeInventory("Clip", 1)
TNT1 A 0 A_GiveInventory("PistolLoad", 1)
TNT1 A 0 A_JumpIfInventory("Clip", 1, "UnitIncompleteReload")
Goto Ready
InfiniteReload:
TNT1 A 35 //Reload Animation
TNT1 A 0 A_GiveInventory("PistolLoad", 20)
Goto Ready
Full:
PISG A 1 A_Print("No need to reload.")
Goto Ready
NoAmmo:
PISG A 1 A_Print("No Ammo")
Goto Ready
}
}
Actor PistolLoad : Ammo
{
Inventory.MaxAmount 20
}
/*
The specialised pickup for "Pistol2". Will give you the gun's internal ammo when you don't have the
gun already, and will give you the main ammo when you already have the gun. Maybe I should rename
the gun to "Pistol2Weapon" and "Pistol2PickUp" to "Pistol2".
*/
Actor Pistol2PickUp : CustomInventory
{
Tag "Pistol"
Inventory.PickupSound "misc/w_pkup"
Inventory.PickupMessage "$PICKUP_PISTOL_DROPPED"
+INVENTORY.AUTOACTIVATE
States
{
Spawn:
PIST A 1
Loop
Pickup:
TNT1 A 0 A_JumpIfInventory("Pistol2", 1, 2) //You could use a state label instead.
TNT1 A 0 A_GiveInventory("Pistol2")
Stop
TNT1 A 0 A_GiveInventory("Clip", 20)
Stop
}
}
Code: Select all
Actor Pistol2 : Pistol //Note that you should use "Pistol2PickUp" for obtaining the weapon.
{
Weapon.SlotNumber 0 //To make it easier to differentiate it from the original pistol.
Weapon.AmmoType1 "PistolLoad"
Weapon.AmmoGive1 20
Weapon.AmmoUse1 1
Weapon.AmmoType2 "Clip"
AttackSound "weapons/pistol"
+WEAPON.AMMO_OPTIONAL //Prevent the weapon from deselecting when running out of ammo, allowing the player to reload it.
States
{
Ready:
PISG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
Loop
Fire:
PISG A 0 A_JumpIfNoAmmo("Reload")
PISG A 4
PISG B 0 A_FireBullets(5.6, 0, 1, 5, "BulletPuff")
PISG B 6 A_GunFlash
PISG C 4
PISG B 5 A_ReFire
Goto Ready
Reload:
TNT1 A 0 A_JumpIfInventory("PistolLoad", 20, "Full")
TNT1 A 35 //Reload Animation
UnitReload:
TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
Goto Ready
TNT1 A 0 A_JumpIfInventory("PistolLoad", 20, "Ready")
TNT1 A 0 A_TakeInventory("Clip", 1, TIF_NOTAKEINFINITE)
TNT1 A 0 A_GiveInventory("PistolLoad", 1)
Goto UnitReload
Full:
PISG A 1 A_Print("No need to reload.")
Goto Ready
NoAmmo:
PISG A 1 A_Print("No Ammo")
Goto Ready
}
}
Actor PistolLoad : Ammo
{
Inventory.MaxAmount 20
}
/*
The specialised pickup for "Pistol2". Will give you the gun's internal ammo when you don't have the
gun already, and will give you the main ammo when you already have the gun. Maybe I should rename
the gun to "Pistol2Weapon" and "Pistol2PickUp" to "Pistol2".
*/
Actor Pistol2PickUp : CustomInventory
{
Tag "Pistol"
Inventory.PickupSound "misc/w_pkup"
Inventory.PickupMessage "$PICKUP_PISTOL_DROPPED"
+INVENTORY.AUTOACTIVATE
States
{
Spawn:
PIST A 1
Loop
Pickup:
TNT1 A 0 A_JumpIfInventory("Pistol2", 1, 2) //You could use a state label instead.
TNT1 A 0 A_GiveInventory("Pistol2")
Stop
TNT1 A 0 A_GiveInventory("Clip", 20)
Stop
}
}
Let me know if I should add anything to the tutorial.