Having to choose between weapons?

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
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Having to choose between weapons?

Post by Hidden Hands »

How can I program this game I'm making to only allow you to carry two weapons at any one time? So say you had an axe and a knife, and you wanted to pick up a shotgun, you'd have to drop either the axe or knife in order to grab that gun? But of course, be able to switch back if you want to drop the gun and repick up the axe (like if you ran out of ammo and it became useless etc.) Similar to Condemned.

Thanks in advance.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Having to choose between weapons?

Post by Matt »

> can carry an axe and a shotgun
> can't fit a knife in there anywhere
https://youtu.be/aO2t6LO9oLI?t=1m3s

One way is to use Touch() or TryPickup() in ZScript to check if the player has at least 2 weapons, then abort the pickup if they do. One way to do the count is to adapt the probe method the backpack uses to get the player's ammo.


Without ZScript, what I would do would be:
1. create a custominventory actor that replaces each weapon

2. in that custominventory actor's pickup state, use countinv to find the total number of weapons the player is carrying, checking each weapon type explicitly, and fail if that number exceeds 2

3. in each weapon's spawn state, have it spawn its custominventory replacer before disappearing

This would only work in a "closed" weapon mod where all the canonical weapons have been replaced entirely (including the pistol, assuming you even want to treat it as a space-occupying weapon per my knife comment) and you don't have to worry about any other weapons appearing.
Locked

Return to “Editing (Archive)”