Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Foxhead

[QUESTION] Limit number of weapons.

Recommended Posts

It's kinda weird but in a basic way it goes like this:

 

Make an inventory item, that has the max amount of weapons you want the player to have. (I mean, if you want 3 max weapons, set Inventory.MaxAmount to 3)

For the purposes of this guide, Let's assume the inventory item i told you above is called WeaponLimitCount, and it's max amount is 3.


Now make a CustomInventory item for each weapon. This CustomInventory item is the actual pickup and works like this:

Actor insertsomenamehere : CustomInventory replaces insertreplacedweaponnamehere

{

states

{

Spawn:

//show a sprite here or something

 

Pickup:

TNT1 A 0 A_JumpIfInventory("WeaponLimitCount", 3, "DontPickup") //if the limit has been reached, don't do anything

TNT1 A 0 A_GiveInventory("WeaponLimitCount", 1) //if not, just give the weapon and add to the counter

TNT1 A 0 A_GiveInventory("ActualWeaponNameHere")

Stop

 

DontPickup:

TNT1 A 0 A_RailWait //does nothing, just stays there

Fail

}

}

Share this post


Link to post
On 9/8/2019 at 5:40 PM, -TDRR- said:

It's kinda weird but in a basic way it goes like this:

 

Make an inventory item, that has the max amount of weapons you want the player to have. (I mean, if you want 3 max weapons, set Inventory.MaxAmount to 3)

For the purposes of this guide, Let's assume the inventory item i told you above is called WeaponLimitCount, and it's max amount is 3.


Now make a CustomInventory item for each weapon. This CustomInventory item is the actual pickup and works like this:

Actor insertsomenamehere : CustomInventory replaces insertreplacedweaponnamehere

{

states

{

Spawn:

//show a sprite here or something

 

Pickup:

TNT1 A 0 A_JumpIfInventory("WeaponLimitCount", 3, "DontPickup") //if the limit has been reached, don't do anything

TNT1 A 0 A_GiveInventory("WeaponLimitCount", 1) //if not, just give the weapon and add to the counter

TNT1 A 0 A_GiveInventory("ActualWeaponNameHere")

Stop

 

DontPickup:

TNT1 A 0 A_RailWait //does nothing, just stays there

Fail

}

}

thanks alot!

btw do you know any way that i can make the weapon pickup not instant? like a need to press E on them to pick it up?

Share this post


Link to post
56 minutes ago, Thfpjct said:

thanks alot!

btw do you know any way that i can make the weapon pickup not instant? like a need to press E on them to pick it up?

You can do this by expanding on the method i gave you above. You will need an ACS script for this, but i'm going to write it for you. Though, you will need to compile it and put it into your mod.

 

//=====CODE STARTS HERE========

#library "PUTTHENAMEOFTHISFILEWITHOUTEXTENSIONHERE"

#include "zcommon.acs"

 

Script "Use_Button_Stuff" ENTER

{

int use; = GetPlayerInput(-1, INPUT_BUTTONS);

while(GetActorProperty(0, APROP_HEALTH) > 0)

{

delay(2);

use = GetPlayerInput(-1, INPUT_BUTTONS);

TakeInventory("PickupWeapons",1);

if(use & BT_USE) {GiveInventory("PickupWeapons",1);}

}

}

 

Script "Use_Button_Stuff2" RESPAWN {ACS_NamedExecuteAlways("Use_Button_Stuff", 0);}

//=====CODE ENDS HERE========

 

Make a new item called "PickupWeapons" (You can name it whatever you want, but change the name above too)

 

And on the code of the CustomInventory item do this:

//=====CODE STARTS HERE========

Actor insertsomenamehere : CustomInventory replaces insertreplacedweaponnamehere

{

states

{

Spawn:

//show a sprite here or something

 

Pickup: //New state, old pickup state was moved to DoPickup

TNT1 A 0 A_JumpIfInventory("PickupWeapons", 1, "DoPickup")

Fail

 

DoPickup:

TNT1 A 0 A_JumpIfInventory("WeaponLimitCount", 3, "DontPickup") //if the limit has been reached, don't do anything

TNT1 A 0 A_GiveInventory("WeaponLimitCount", 1) //if not, just give the weapon and add to the counter

TNT1 A 0 A_GiveInventory("ActualWeaponNameHere")

Stop

 

DontPickup:

TNT1 A 0 A_RailWait //does nothing, just stays there

Fail

}

}

//=====CODE ENDS HERE========

Share this post


Link to post
1 hour ago, -TDRR- said:

You can do this by expanding on the method i gave you above. You will need an ACS script for this, but i'm going to write it for you. Though, you will need to compile it and put it into your mod.

 

//=====CODE STARTS HERE========

#library "PUTTHENAMEOFTHISFILEWITHOUTEXTENSIONHERE"

#include "zcommon.acs"

 

Script "Use_Button_Stuff" ENTER

{

int use; = GetPlayerInput(-1, INPUT_BUTTONS);

while(GetActorProperty(0, APROP_HEALTH) > 0)

{

delay(2);

use = GetPlayerInput(-1, INPUT_BUTTONS);

TakeInventory("PickupWeapons",1);

if(use & BT_USE) {GiveInventory("PickupWeapons",1);}

}

}

 

Script "Use_Button_Stuff2" RESPAWN {ACS_NamedExecuteAlways("Use_Button_Stuff", 0);}

//=====CODE ENDS HERE========

 

Make a new item called "PickupWeapons" (You can name it whatever you want, but change the name above too)

 

And on the code of the CustomInventory item do this:

//=====CODE STARTS HERE========

Actor insertsomenamehere : CustomInventory replaces insertreplacedweaponnamehere

{

states

{

Spawn:

//show a sprite here or something

 

Pickup: //New state, old pickup state was moved to DoPickup

TNT1 A 0 A_JumpIfInventory("PickupWeapons", 1, "DoPickup")

Fail

 

DoPickup:

TNT1 A 0 A_JumpIfInventory("WeaponLimitCount", 3, "DontPickup") //if the limit has been reached, don't do anything

TNT1 A 0 A_GiveInventory("WeaponLimitCount", 1) //if not, just give the weapon and add to the counter

TNT1 A 0 A_GiveInventory("ActualWeaponNameHere")

Stop

 

DontPickup:

TNT1 A 0 A_RailWait //does nothing, just stays there

Fail

}

}

//=====CODE ENDS HERE========

Thanks man!

This ACS code it's kinda confusing to me now but i will try to learn it, thx again!

Share this post


Link to post
21 hours ago, Thfpjct said:

Ok for some reason when i Summon the Weapon pickup the game just crashes, maybe i did something wrong?

Here the "pk3" file to take less time.

COLT EXPERIMENTATION GUN.zip

Well, looking at the zip, you organized everything wrong. Make your project a .pk3 instead, and organize it like this:
Sprites go in a directory of the .pk3 called "sprites", Make sure to not include SS_XXXX markers in this folder.

Compiled ACS goes in "acs" (Not LOADACS, only the compiled file, which in this case is named "PICKUP")

 

After doing this, i got no crashes at all in ZDoom LE or LZDoom, so you just organized everything incorrectly and that was the cause of the crash.

Share this post


Link to post
22 hours ago, -TDRR- said:

Well, looking at the zip, you organized everything wrong. Make your project a .pk3 instead, and organize it like this:
Sprites go in a directory of the .pk3 called "sprites", Make sure to not include SS_XXXX markers in this folder.

Compiled ACS goes in "acs" (Not LOADACS, only the compiled file, which in this case is named "PICKUP")

 

After doing this, i got no crashes at all in ZDoom LE or LZDoom, so you just organized everything incorrectly and that was the cause of the crash.

thank you man, i didn't know the organization was really necessary.

Share this post


Link to post

Man this is given me fricking a headache, i did everything you said, but it keeps crashing, even in those source ports you mention.

every time i type "Summon Colt" to summon the pickup to test, the game just crashes, i even tried to begin from zero but it still crashing.

and sometimes when i am compiling the ACS he says that is something is wrong, something about with this that one character in bold, when i delete it it compiles, and other times it don't.

i losing my mind over this.

 

int use;= GetPlayerInput(-1, INPUT_BUTTONS);

 

Share this post


Link to post

Could you show the whole ACS source code? I can't tell you what's wrong with it if you only show me that one line. No reason to keep it private anyways.

 

Also, here's how the .pk3 file should be:

ColtExperiment.zip

Share this post


Link to post

#library "PICKUP"

#include "zcommon.acs"

 

Script "Use_Button_Stuff" ENTER

{

int use = GetPlayerInput(-1, INPUT_BUTTONS);

while(GetActorProperty(0, APROP_HEALTH) > 0)

{

delay(2);

use = GetPlayerInput(-1, INPUT_BUTTONS);

TakeInventory("PickupWeapons",1);

if(use & BT_USE) {GiveInventory("PickupWeapons",1);}

}

}

 

Script "Use_Button_Stuff2" RESPAWN{ACS_NamedExecuteAlways("Use_Button_Stuff", 0);}

 

 

I also tested the pk3 that you send, and it crashes for me. so i think the problem is something else.

Edited by Thfpjct

Share this post


Link to post
5 hours ago, Thfpjct said:

I also tested the pk3 that you send, and it crashes for me. so i think the problem is something else.

It's definitely your PC then. Not getting such crash even with GZD 4.2.1.

Share this post


Link to post
13 hours ago, -TDRR- said:

It's definitely your PC then. Not getting such crash even with GZD 4.2.1.

yeah, but anyway, thanks for the patience and help, at least i can make the "Weapon limit".

Share this post


Link to post

I stumbled upon this topic while searching for a method to add per slot weapon limits to my WIP mod. Interestingly, I am also getting crashes when trying to use the linked files. More specifically, when I execute the "summon coltpickup" command, the instant I close the console, GZDoom freezes and has to have the process closed. The regular "colt" works fine, but doesn't have the pickup limit. Any idea why this might be happening? I'm going to mess about with the coltpickup actor and see if I can get different results. 

 

A couple minutes later: Discovered that changing the COLP A 1 to COLP A -1 fixed the freeze, but picking up the weapon doesn't work. Even giving myself PickupWeapons in the console doesn't do anything. 

 

A bit later: Functional fixed DECORATE.

 


ACTOR WeaponLimitCount : Inventory
{
inventory.maxamount 1
}
ACTOR PickupWeapons : Inventory
{
inventory.maxamount 1
}

ACTOR Colt : Weapon 5001
{
Weapon.Ammotype "clip"
Weapon.Ammouse 1
Weapon.Ammogive 10
Weapon.Selectionorder 1
Weapon.Slotnumber 2
Weapon.BobSpeed 1.5
Weapon.BobRangeX 0.5
Weapon.BobRangey 0.5
Weapon.BobStyle Inverse
+Weapon.Noautofire
inventory.pickupsound "misc/w_pkup"
AttackSound "Weapons/REVOFIR"
Inventory.Pickupmessage "You got a BigRevolver"

States
    {
    Spawn:
    COLP A -1
    loop
        
    Ready:
    COLT A 1 A_WeaponReady
    loop
        
    Select:
    COLT A 1 A_RAISE
    Loop
        
    Deselect:
    COLT A 1 A_Lower
    Loop
        
    Fire:
    TNT1 A 0 A_Gunflash
    COLT B 1 Bright A_FireBullets(0,0,1,3,"BulletPuff")
    TNT1 AAA 0 A_SetPitch (pitch-0.2)
    TNT1 A 0 A_SetPitch (pitch-0.1)
    COLT CB 2 
    Goto ready
        
    Flash:
    COLF A 1 Bright A_Light0
    Goto LightDone
        
    }
}

Actor Coltpickup : CustomInventory 
{
+INVENTORY.NOSCREENFLASH
Inventory.PickupMessage ""
Inventory.Icon ""
Inventory.Pickupsound ""
+THRUACTORS

    States
    {
        Spawn:
            COLP A 30
            TNT1 A 0 A_ChangeFlag("THRUACTORS", 0)
            COLP A -1
            Stop
            
        Pickup: //New state, old pickup state was moved to DoPickup
            TNT1 A 0 A_JumpIfInventory("PickupWeapons", 1, "DoPickup")
            Stop
            
        DoPickup:
            TNT1 A 0 A_JumpIfInventory("WeaponLimitCount", 1, "DontPickup") //if the limit has been reached, don't do anything
            TNT1 A 0 A_Print("You picked up a colt.")
            TNT1 A 0 A_GiveInventory("WeaponLimitCount", 1) //if not, just give the weapon and add to the counter
            TNT1 A 0 A_GiveInventory("Colt")
            Stop
            
        DontPickup:
            TNT1 A 35
            TNT1 A 0 A_Print("You can't carry that much!")
            TNT1 A 0 A_SpawnItem("ColtPickup")
            Stop
    }

}

Edited by Sykriss

Share this post


Link to post

A while ago I was interested in this same kind of idea. Instead of limiting the player to just X amount of any weapons though, what I did was come up with a way to do the following:

 

  • Weapon limits are on a per-slot basis. For example, slot 4 is for automatic weapons, so the player can only have one of the Machinegun, Chaingun, or Nailgun at a time, and it has no bearing on what weapons can be held in slot 3 (shotguns) or slot 5 (explosives), etc.
  • The player would switch their weapons out by using the native "Drop Weapon" action in (G)ZDoom, rather than using ACS or other more involved methods to do so.
  • Picking up a weapon for the first time gives ammo, and picking up the same weapon again while already in possession of it gives ammo, but dropping and re-picking up a weapon (or repeatedly swapping weapons) doesn't generate limitless ammo.

The DECORATE code I came up with looks like the following:

 

Spoiler

actor Revolver : Weapon 
{
  radius 20
  height 16
  Weapon.SelectionOrder 1100
  weapon.ammotype "MagnumAmmo"
  weapon.ammouse 1
  weapon.ammogive 0
	Inventory.icon "RVLVA0"
  +WEAPON.NOAUTOAIM
  +WEAPON.CHEATNOTWEAPON
	Tag "Revolver"
	States
  {
  Ready:
    REVL A 1 A_WeaponReady
    Loop
  Deselect:
    REVL A 1 A_Lower(18)
    Loop
  Select:
	TNT1 A 0 A_StopSound(CHAN_7)
	REVL A 0 A_SetCrosshair(9)
    REVL A 1 A_Raise(18)
    Loop
  Fire:
    REVL A 2 
    REVL B 0 A_GunFlash
    REVL B 0 A_PlayWeaponSound("Weapons/revolver")
    REVL B 4 A_FireCustomMissile("RevolverBullet", frandom(-1.0, 0.8), 1, 0, 0, 0, frandom(-0.8, 1.0))
    REVL CDEF 3
    REVL A 6 
    REVL A 2 A_ReFire
    Goto Ready
  Flash:
    TNT1 A 2 bright A_Light1
    TNT1 B 2 bright A_Light2
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
	TNT1 A 1 
	TNT1 A 1 A_SpawnItemEx ("RevolverWait", 0,0,0,velx,vely, velx, angle, 32, 0)
	stop
  }
}

Actor RevolverWait
{
	Radius 16
	Height 20
	States
	{
	Spawn:
		RVLV A 48
		RVLV A 0 A_SpawnItem("RevolverPickup", 0)
		stop
	}
}

Actor RevolverPickup : AWeaponSpawn 20019
{
  //$Category Weapons
  //$NotAngled
  //$Title Revolver
//$Sprite RVLVA0
	Inventory.RespawnTics 350
  inventory.pickupmessage "You got the revolver!"
	states
	{
	Spawn:
		RVLV A -1
		loop
	Pickup:
		TNT1 A 0 A_JumpifInventory("NewBlaster", 1, 7)
		TNT1 A 0 A_JumpifInventory("Repeater", 1, 6)
		TNT1 A 0 A_JumpifInventory("NewPistol", 1, 5)
		TNT1 A 0 A_JumpifInventory("Revolver", 1, "Pickup3")
		TNT1 A 0 A_JumpifInventory("MachinePistol", 1, 3)
		TNT1 A 0 A_JumpifInventory("RevolverToken", 1, "Pickup2")
		TNT1 A 0 A_Jump(256, "Pickup1")
		TNT1 A 0 
		fail
	Pickup1:
		TNT1 A 0 A_GiveInventory("Revolver", 1)
		TNT1 A 0 A_GiveInventory("MagnumAmmo", 6)
		TNT1 A 0 A_GiveInventory("RevolverToken", 1)
		stop
	Pickup2:
		TNT1 A 0 A_GiveInventory("Revolver", 1)
		stop
	Pickup3:
		tnt1 A 0 A_GiveInventory("MagnumAmmo", 6)
		stop
	}
}

ACTOR RevolverToken  : Ammo 
{
  +INVENTORY.UNDROPPABLE
  Inventory.Amount 1
  Inventory.MaxAmount 1
  Ammo.BackpackAmount 0
  Ammo.BackpackMaxAmount 1
}

 

 

Four separate actors go into making each weapon:

 

  1. the actual weapon that is in the player's inventory
  2. a dummy item that can't be interacted with (in order to resolve issues with holding two weapons in the same slot when repeatedly dropping and picking up weapons)
  3. the actual weapon pickup
  4. a token that indicates whether the player has obtained the weapon before (I inherited from the "Ammo" actor instead of Inventory or CustomInventory for this because well, it just works™)

Most of the code should be fairly readable, though I'll note that the numerous "JumpIf" checks in the weapon pickup are arranged in a certain way to prevent weird conflicts.

Share this post


Link to post

Sounds like a solid system. I also kept the native drop system, with a simple but rudimentary method of replacing the dropped weapon with its pickup counterpart shortly after spawning. My first little project is merging the Brutal Doom WW2 weapons pack, VietDoom weapons pack and classic pack, which is all pretty much done; I just wanted to add a slot system so players don't end up with thirty guns in their inventory and came across this thread in my googling.

 

I expanded upon the basic system outlined in this post, with 9 counter tokens for each of the nine slots, although I'm likely to only use 1-5. I also decided to go with a slot limit of two, which opens up some interesting options regarding loadout choices. This then allows for access to ten weapons at a max of two keypresses. I broke it down as follows: Slot1 for melee, slot2 for pistols and sub machine guns, slot3 for shotguns and automatic rifles, slot4 for bolt action and semi automatic rifles, and slot5 for light machine guns and rocket launchers.

My other project which is also mostly done introduces the Project ReBlood, Wolfenstein and VietDoom enemies as occasionally spawned vanilla enemy replacers, complete with expected behaviors and minimal jank. I couldn't find any monsters only versions of those mods so decided to tackle it myself. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×