Help: Call of Duty-style weapon switching?
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.
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.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
Help: Call of Duty-style weapon switching?
Okay, for an unannounced project of mine, I'm going to want to give the player a very large selection of weapons, but to prevent overflow and general unbalance, I'm opting to use a Call of Duty style weapon switching system.
The system works thusly: the player has 7 weapon slots, much like the original Doom. Slot 1 is for melee weapons, slot 2 is for sidearms, 3 for shotguns and rifles, 4 for rapid-fire weapons, 5 for explosives, 6 for energy weapons, and 7 for super weapons. The catch is, the player can only carry one weapon in each slot. If he wishes to use a different weapon in the same slot, he must switch his current weapon with the one on the ground.
As this is a weapon mod that includes no maps, I would imagine LOADACS would be necessary. However, I know absolutely nothing of ACS aside from how to compile things and work with the player's inventory, so I'm going to need all the help I can get with this one. I don't know where to begin.
The system works thusly: the player has 7 weapon slots, much like the original Doom. Slot 1 is for melee weapons, slot 2 is for sidearms, 3 for shotguns and rifles, 4 for rapid-fire weapons, 5 for explosives, 6 for energy weapons, and 7 for super weapons. The catch is, the player can only carry one weapon in each slot. If he wishes to use a different weapon in the same slot, he must switch his current weapon with the one on the ground.
As this is a weapon mod that includes no maps, I would imagine LOADACS would be necessary. However, I know absolutely nothing of ACS aside from how to compile things and work with the player's inventory, so I'm going to need all the help I can get with this one. I don't know where to begin.
Well... I guess some of that depends on how exactly you want to set it up. I think what I would do is use [wiki]KEYCONF[/wiki] to make a new key for dropping your current weapon. When the user wants to swap weapons out, they need to manually drop the weapon they want to lose to pick up the new one. I personally think this is better than Rise of the Triad's walkover switch method. The downside, in this case with the specific slots for weapons, is that a new player has to get familiar with which weapons go in which slots (otherwise when they come across a weapon they can't pick up, they have to trial and error their way through which weapon they need to drop to pick up the new one.)
To conveniently drop the weapon, I would do something like this (as an example):This should basically be a gravity affected projectile that looks like a shotgun, but it doesn't do any damage and merely spawns a real weapon pickup when it hits something. Thus, the end effect is when the player drops a weapon, it looks like they toss it away. The drop script itself should take removing the appropriate weapon/ammo via [wiki]CheckWeapon[/wiki], [wiki]GiveInventory[/wiki], and [wiki]TakeInventory[/wiki].
After that, all that would be left would be the pick up actors, which you can just use CustomInventory for. If the player already has a specific slot full, the pick up should just fail.
To conveniently drop the weapon, I would do something like this (as an example):
Code: Select all
ACTOR DroppedShotgun
{
Radius 6
Height 8
Speed 24
PROJECTILE
-NOBLOCKMAP
-NOGRAVITY
States
{
Spawn:
SHOT A 1
Loop
Death:
TNT1 A 1 A_SpawnItem("Shotgun",0,0,0,0)
Stop
}
}
After that, all that would be left would be the pick up actors, which you can just use CustomInventory for. If the player already has a specific slot full, the pick up should just fail.
- 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:
I don't think you need ACS to determine what you can put in the slots. Create a custom inventory item that replaces the weapon as it appears on the map, then create a new inventory flag for each slot. In the pickup's pickup state, use A_JumpIfInventory to either give the weapon plus it respective slot flag if the player doesn't have the flag, or fail (or pickup but give the ammo only) if the player does have the flag.
I'm not too concerned with the which weapon goes where issue, since the breakdown in this case is exactly parallel with vanilla Doom. Just make sure the weapons look like what they're supposed to be...
As for the dropped item itself, I'd use A_SpawnItem(Ex) and a pickup that starts off noclipped and then changes its flag after a second or so...
I'm not too concerned with the which weapon goes where issue, since the breakdown in this case is exactly parallel with vanilla Doom. Just make sure the weapons look like what they're supposed to be...
As for the dropped item itself, I'd use A_SpawnItem(Ex) and a pickup that starts off noclipped and then changes its flag after a second or so...
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
For the "which weapon goes where" issue, there are a couple solutions I can think of:
- Like most of my other mods, I'd print the slot number in the weapon's pickup message ("Shotgun (slot 3)").
- On weapons lying on the ground, there are two ways I can think of to handle it...the first is more CoD-style, in that walking near the weapon will display a message on screen of the weapon's name and what slot number it is ("Super Shotgun (slot 3)"), but I imagine this would be difficult to code.
- The second way would be to have a tiny number float above every weapon pickup, designating the weapon's slot, but this would be rather tacky.
For Vaecrius' idea, would I need to make a seperate "fake" pickup for each weapon, inherit from CustomInventory and have it give the real weapon when it's picked up? Or can I use Pickup/Drop states on Weapon-type actors as well?
- Like most of my other mods, I'd print the slot number in the weapon's pickup message ("Shotgun (slot 3)").
- On weapons lying on the ground, there are two ways I can think of to handle it...the first is more CoD-style, in that walking near the weapon will display a message on screen of the weapon's name and what slot number it is ("Super Shotgun (slot 3)"), but I imagine this would be difficult to code.
- The second way would be to have a tiny number float above every weapon pickup, designating the weapon's slot, but this would be rather tacky.
For Vaecrius' idea, would I need to make a seperate "fake" pickup for each weapon, inherit from CustomInventory and have it give the real weapon when it's picked up? Or can I use Pickup/Drop states on Weapon-type actors as well?
- 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:
I've only ever tried using a separate pickup actor, and when I did that it was impossible to create a pickup state for the weapon directly... I'm not sure if that's changed in the SVN since then.
If you use that idea, though, you could have the "failed pickup" state also print a message saying what the weapon is and which slot it goes into, whether with A_Print or ACS.
If you use that idea, though, you could have the "failed pickup" state also print a message saying what the weapon is and which slot it goes into, whether with A_Print or ACS.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
As far as I can tell, there is no way to actually drop the weapon aside from doing it in the console. The only "drop" key is to drop the current inventory item. What I need is a way the player can simply hit a key, and have the current weapon be thrown forward. I attempted to do this with Decorate, using an inventory flag and a check for that flag in the weapon's Ready state. Unfortunately, there is no way in Decorate to force the player to change weapons, at least not as far as I can tell.
- 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:
[wiki]A_DropInventory[/wiki]
EDIT: Though it does have one issue... posted in Bugs since I'm pretty sure this isn't intended.
EDIT: Though it does have one issue... posted in Bugs since I'm pretty sure this isn't intended.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
I think I've nailed it! Demo wad attached...see if you can find any bugs in it.
Here's how it works:
- Start a new game
- Go to the console and type 'give action_dropweapon'
- Make sure a key is bound to drop weapon in the menu system!
- Either find a shotgun, or go to the console and summon "fakeshotgun"
- Pick it up. (ignore the "you got a pickup" message)
- Select the shotgun. Drop it and pick it back up again.
- Summon another fakeshotgun and try picking both up. (Under normal circumstances, this should give the player extra ammo and make the other shotgun disappear, but since the shotgun is the only weapon implemented, I modified the code so that it would prompt the player to drop their weapon instead)
- No, the shotgun is not supposed to fire!
Note: This might only work in SVN versions that support custom state labels
Here's how it works:
- Start a new game
- Go to the console and type 'give action_dropweapon'
- Make sure a key is bound to drop weapon in the menu system!
- Either find a shotgun, or go to the console and summon "fakeshotgun"
- Pick it up. (ignore the "you got a pickup" message)
- Select the shotgun. Drop it and pick it back up again.
- Summon another fakeshotgun and try picking both up. (Under normal circumstances, this should give the player extra ammo and make the other shotgun disappear, but since the shotgun is the only weapon implemented, I modified the code so that it would prompt the player to drop their weapon instead)
- No, the shotgun is not supposed to fire!
Note: This might only work in SVN versions that support custom state labels
- 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:
Hm... I think this is where ACS would come in handy. I can't think of anything in DECORATE* that would be able to print the "error" message without constantly printing it over and over as long as you're in contact with the pickup...
Besides that, everything seems to work as intended.
*EDIT: Besides another inventory flag and a function to remove it after certain frames, but it's a bit unpolished to do it like that and you'd either have to put it in every weapon or in the player pawn's see state.
Besides that, everything seems to work as intended.
*EDIT: Besides another inventory flag and a function to remove it after certain frames, but it's a bit unpolished to do it like that and you'd either have to put it in every weapon or in the player pawn's see state.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
At this point, having the Print message spammed over and over is a necessary evil, because it's really not worth the trouble to make some messy code to fix it. Doesn't ZDoom actually limit how much is stored in the console buffer anyway? Because if it doesn't, it should.
The only real hazard is playing the mod if you've got console logging turned on, which will result in ridiculously large log files.
The only real hazard is playing the mod if you've got console logging turned on, which will result in ridiculously large log files.
- wildweasel
- Posts: 21706
- Joined: Tue Jul 15, 2003 7:33 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): A lot of them
- Graphics Processor: Not Listed
- Contact:
Here's your "messy code" to fix it.wildweasel wrote:At this point, having the Print message spammed over and over is a necessary evil, because it's really not worth the trouble to make some messy code to fix it. Doesn't ZDoom actually limit how much is stored in the console buffer anyway? Because if it doesn't, it should.

Code: Select all
script 666 (int WepID) {
switch (WepID) {
case WEP_PISTOL:
HudMessage(s:"Pistol (Slot 2)"; HUDMSG_PLAIN, 69, CR_UNTRANSLATED, 1.5, 0.5, 1.0);
break;
case WEP_SHOTGUN:
HudMessage(s:"Shotgun (Slot 3)"; HUDMSG_PLAIN, 69, CR_UNTRANSLATED, 1.5, 0.5, 1.0);
break;
case WEP_SUPERSHOTGUN:
HudMessage(s:"Super Shotgun (Slot 3)"; HUDMSG_PLAIN, 69, CR_UNTRANSLATED, 1.5, 0.5, 1.0);
break;
// ... etc ...
}