Page 1 of 1

Weapons and Pickup state

Posted: Wed Mar 20, 2013 2:31 am
by RobbyPants
So I noticed that CustomInventory has a pickup state (and a drop state). Is there any way to hook that into a weapon to have it overwrite it's normal behavior?

I'm looking for a way to limit the number of guns a player can carry, and I was planning on giving them some custom items on pickup of the weapon, and having the pickup fail if they were already at maximum capacity.

Is this the right approach, or is there a better way to do it?

RE: Weapons and Pickup state

Posted: Wed Mar 20, 2013 3:17 am
by Xenaero
You could always run an index in a global script with a weird script number so you'd likely not run into conflicts. It would be less messy than running dummy inventory item checks.

RE: Weapons and Pickup state

Posted: Wed Mar 20, 2013 12:59 pm
by TheMisterCat
http://zdoom.org/wiki/Actor_properties#Player

Code: Select all

actor DoomPlayer : PlayerPawn 
{
Player.WeaponSlot 1, Gun1, Gun2, Gun3...
Player.WeaponSlot 2, Gun1, Gun2, Gun3...
}
Sorry if this is a bit messy, but I had a go at quickly writing how I think it should work. Here's the body of ACS

Code: Select all


	#include "zcommon.acs"
        #library "GunWeight"

	#define MaxWeight 100
	#define MaxPlayers 32

	#define ptidoffset 500

	#define PICKUP_WEAPON 100
	#define SWITCH_WEAPON 101
	#define DROP_WEAPON 102

	int PlayerWeight[MaxPlayers];

	#define MAX_WEAPONS 3
	int WeaponWeights[MAX_WEAPONS] = { 30, 45, 50 };
	str WeaponNames[MAX_WEAPONS] = { "Gun1", "Gun2", "Gun3" };
    str WeaponPickups[MAX_WEAPONS] = { "Gun1Pickup", "Gun2Pickup", "Gun3Pickup" };
	
//returns the index number of the currently held weapon
	function int CheckPlayerWeapon ( void )
	{
		for(int i = 0; i < MAX_WEAPONS; i++)
		{
			if(CheckWeapon(WeaponNames[i]))
				{ return i; }
		}
	return -1;
	}


	Script PICKUP_WEAPON (int GunType)
	{
		if(PlayerWeight[PlayerNumber()] + WeaponWeights[GunType] < MaxWeight)
			{
			PlayerWeight[PlayerNumber()] += WeaponWeights[GunType];
			GiveInventory(WeaponNames[GunType], 1);
			SetWeapon(WeaponNames[GunType]);
			}
		else
			{
				Print(s:"Too heavy!");
			}
	}


	Script SWITCH_WEAPON (int GunType)
	{
		if((PlayerWeight[PlayerNumber()] - WeaponWeights[CheckPlayerWeapon()]) + WeaponWeights[GunType] < MaxWeight)
			{
			PlayerWeight[PlayerNumber()] -= WeaponWeights[CheckPlayerWeapon()];
			PlayerWeight[PlayerNumber()] += WeaponWeights[GunType];
			Spawn(WeaponPickups[CheckPlayerWeapon()], GetActorX(0) + cos(GetActorAngle(0))*32, GetActorY(0) + sin(GetActorAngle(0))*32, GetActorZ(0)+24.0);
			TakeInventory(WeaponNames[CheckPlayerWeapon()], 1);
			GiveInventory(WeaponNames[GunType], 1);
			SetWeapon(WeaponNames[GunType]);
			}
		else
			{
				Print(s:"Too heavy!");
			}
	}

	Script DROP_WEAPON (VOID)
	{
	PlayerWeight[PlayerNumber()] -= WeaponWeights[CheckPlayerWeapon()];
	Spawn(WeaponPickups[CheckPlayerWeapon()], GetActorX(0) + cos(GetActorAngle(0))*32, GetActorY(0) + sin(GetActorAngle(0))*32, GetActorZ(0)+24.0);
	TakeInventory(WeaponNames[CheckPlayerWeapon()], 1);
	}
				
and just have 'fake' pickups which run the script (passing the array index of the weapon type)

Code: Select all

Actor Gun1Pickup : CustomInventory
{
States
{
Spawn:
GUN1 A -1
stop
Pickup:
GUN1 A 1 ACS_Execute(100, 0, 0)
stop
}}

Actor Gun2Pickup : Gun1Pickup
{ States {
Pickup:
GUN2 A 1 ACS_Execute(100, 0, 1)
stop
}}

et cetera
bind the drop_weapon script as a puke and disable weapon dropping flag

RE: Weapons and Pickup state

Posted: Mon Mar 25, 2013 2:47 am
by RobbyPants
Thanks for that. I'm working on a modified version to try and get all the kinks out. That being said, I'm looking to replace all of the normal weapons on the map with the "pickup" customInventory versions of the weapons. Is there an easy way to replace them by using the same ID, or by making the spawn state of the weapon spawn the "pickup" instead?

RE: Weapons and Pickup state

Posted: Mon Mar 25, 2013 6:32 am
by TheMisterCat
yeah, just have the spawn state spawn the pickup actor

RE: Weapons and Pickup state

Posted: Tue Mar 26, 2013 1:26 am
by RobbyPants
I'm having trouble getting it to spawn properly. If I encounter a regular shot gun (the actual gun), nothing is there, like it isn't spawning my shotgun pickup.

Here is the DECORATE code for my shotgun pickup:

Code: Select all

Actor Shot_gunPickup : M&P9Pickup 22021
{
	Inventory.PickupMessage "Shot gun" 
	SpawnID 253
	States
	{
		Spawn:
			SHOT A -1
			stop
			
		Pickup:
			SHOT A 0 A_JumpIfInventory("Shot_gun", 1, "GetAmmo")
			SHOT A 1 ACS_Execute(100, 0, 1, 0, 0)
			SHOT A 0 A_JumpIfInventory("WeaponCapacityFull", 1, "FailPickup")
			stop
			
		GetAmmo:
			SHOT A 0 A_JumpIfInventory("Shell", 0, "FailPickup")
			SHOT A 1 ACS_Execute(103, 0, 1, 3, 0)
			stop
			
		FailPickup:
			SHOT A 1
			fail
	}
}
Here is the Spawn state of the shot gun itself (with the original line commented out).

Code: Select all

Spawn:
  //SHOT A -1
  SHOT A 1 A_SpawnItemEx("Shot_gunPickup", 0, 0, 0)
  stop
I'm not sure if I'm just messing stuff up with IDs, spawn IDs, using "stop" to end the spawn state, or what.

RE: Weapons and Pickup state

Posted: Wed Mar 27, 2013 12:46 am
by RobbyPants
Ha! I figured it out!

Code: Select all

Spawn:
  SHOT A 15
  SHOT A 0 A_SpawnItemEx("Shot_gunPickup", 0, 0, 0)
That being said, I managed to bind a key to the drop script, but how do I remove the standard zdoom drop item command from the menu?

RE: Weapons and Pickup state

Posted: Wed Mar 27, 2013 1:41 am
by TerminusEst13
You don't. Just tell people to use that instead, and pray they listen.