Weapons and Pickup state

Discuss all aspects related to modding Zandronum here.
Post Reply
RobbyPants
 
Posts: 37
Joined: Wed Mar 13, 2013 12:53 am

Weapons and Pickup state

#1

Post by RobbyPants » Wed Mar 20, 2013 2:31 am

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?

User avatar
Xenaero
Retired Staff / Community Team Member
Posts: 81
Joined: Fri Jun 01, 2012 8:51 pm

RE: Weapons and Pickup state

#2

Post by Xenaero » Wed Mar 20, 2013 3:17 am

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.
Last edited by Xenaero on Wed Mar 20, 2013 3:17 am, edited 1 time in total.

TheMisterCat
 
Posts: 79
Joined: Mon Jun 04, 2012 2:21 pm
Location: NZ

RE: Weapons and Pickup state

#3

Post by TheMisterCat » Wed Mar 20, 2013 12:59 pm

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

RobbyPants
 
Posts: 37
Joined: Wed Mar 13, 2013 12:53 am

RE: Weapons and Pickup state

#4

Post by RobbyPants » Mon Mar 25, 2013 2:47 am

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?

TheMisterCat
 
Posts: 79
Joined: Mon Jun 04, 2012 2:21 pm
Location: NZ

RE: Weapons and Pickup state

#5

Post by TheMisterCat » Mon Mar 25, 2013 6:32 am

yeah, just have the spawn state spawn the pickup actor

RobbyPants
 
Posts: 37
Joined: Wed Mar 13, 2013 12:53 am

RE: Weapons and Pickup state

#6

Post by RobbyPants » Tue Mar 26, 2013 1:26 am

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.

RobbyPants
 
Posts: 37
Joined: Wed Mar 13, 2013 12:53 am

RE: Weapons and Pickup state

#7

Post by RobbyPants » Wed Mar 27, 2013 12:46 am

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?

TerminusEst13
Retired Staff / Community Team Member
Posts: 865
Joined: Tue Jun 05, 2012 11:06 pm

RE: Weapons and Pickup state

#8

Post by TerminusEst13 » Wed Mar 27, 2013 1:41 am

You don't. Just tell people to use that instead, and pray they listen.
The Ranger - New class for HeXen.
ZDoom Wars - I drew some pictures.
Samsara - Some class-based mod I guess?
Metroid: Dreadnought - I am a dumb fanboy.
DemonSteele - ~come with me to anime world~

Post Reply