Custom Backpack "Class" based

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
swimmingpaul01
Posts: 2
Joined: Fri Jul 11, 2025 8:20 pm
Preferred Pronouns: He/Him

Custom Backpack "Class" based

Post by swimmingpaul01 »

So this is the main code in question:

Code: Select all

Actor CXBackpack : CustomInventory
{
  +CountItem
  +Inventory.AlwaysPickup
  Height 26
  Inventory.PickupMessage "$GOTBACKPACK" // "Picked up a backpack!"
  States
  {
  Spawn:
    BPAK A -1
    Loop
  Pickup:
	TNT1 A 0 A_JumpIfInTargetInventory("CXRocketLauncher", 1, "PackRG")
	TNT1 A 0 A_JumpIfInTargetInventory("Pistol", 1, "PackMG")
  PackRG:
    TNT1 A 0 A_GiveInventory("CXMinigun")
    TNT1 A 0 A_GiveInventory("CXGrenadeAmmo", 2)
    Stop
  PackMG:
    TNT1 A 0 A_GiveInventory("Shotgun")
    TNT1 A 0 A_GiveInventory("Shell",8)
    TNT1 A 0 A_GiveInventory("CXGrenadeAmmo", 2)
	Stop
  }
}
I'm doing a thing where certain weapons are reserved for specific player classes (so If you the "RocketLauncherGuy, you never acquire the pistol, if you're PistolGuy, no Rocket Launcher for you) and so I'm creating a custom Backpack that, when collected, gives you certain things included an additional weapon based on your "class," (or really, just the weapon that is unique to your class). No matter what I do, however, the player always acquires the Minigun, and I cannot get PistolGuy to acquire the Shotgun. I've been trying different things but if anyone could save me some time, I would appreciate it!
swimmingpaul01
Posts: 2
Joined: Fri Jul 11, 2025 8:20 pm
Preferred Pronouns: He/Him

Re: Custom Backpack "Class" based

Post by swimmingpaul01 »

This worked:

Code: Select all

Actor CXBackpack : CustomInventory
{
  +CountItem
  +Inventory.AlwaysPickup
  Height 26
  Inventory.PickupMessage "$GOTBACKPACK" // "Picked up a backpack!"
  States
  {
  Spawn:
    BPAK A -1
    Loop
  Pickup:
	TNT1 A 0 A_JumpIfInventory("RocketGuyToken",1, "PackRG")
	TNT1 A 0 A_JumpIfInventory("RifleGuyToken", 1, "PackMG")
  PackRG:
    TNT1 A 0 A_GiveInventory("CXMinigun")
    TNT1 A 0 A_GiveInventory("CXGrenadeAmmo", 2)
    Stop
  PackMG:
    TNT1 A 0 A_GiveInventory("Shotgun")
    TNT1 A 0 A_GiveInventory("Shell",8)
    TNT1 A 0 A_GiveInventory("CXGrenadeAmmo", 2)
	Stop
  }
}
And I simply created the RocketGuyToken & RifleGuyToken and gave it to their respective classes. Weird, cause I thought I tried that earlier but I guess I missed something.
Post Reply

Return to “Scripting”