I'm.. hitting kind of a wall, here. I have things set up so that "one weapon" (actually all separate ACTORS) can use multiple types of ammo. When I originally got help for an issue involving ammo, this wasn't the case. And now.. it's been so long, I can't remember how to alter this code chunk to do what I need.
What I need to do, here, is add to or alter the "Check" ability of this code chunk to detect things in the player's Inventory.
Right now, it's set up to detect if a Weapon is in their inventory that can use the AmmoType listed. I need it to, instead or in addition to this, check if the player is holding one of several Weapons that would ALL potentially use that ammo.
As it stands, I have two actual, different Shotguns coded, and each Shotgun has a "clone" that uses a different ammo type (one uses Slugs, one uses Shot Shells), for a total of four Actors, and eventually, many more (I have 4 shotguns planned for the project, and a third type of ammo).
I need this code chunk to allow the Player to pick up ammo only when they have one of these guns, and (as you can see in the Code), deposit a residual item if not all of the ammunition in the Pickup can fit in the Player's Inventory.
And I don't know ZScript well enough to figure out how to do that. I've been messing with different ideas for a week, and.. yeah, nothing.
Here's the code chunk as it stands:
Code: Select all
class LooseSGSHOTBase : Inventory
{
Default
{
Inventory.Amount 1;
Inventory.PickupSound "pickup/ammogeneral";
Inventory.PickupMessage "12 Gauge #00 Shot";
Scale 0.3;
}
States
{
Spawn:
SMSH B -1 Bright;
Stop;
}
// These are the ammo types we'll be scanning for
static const class<Ammo> AmmoTypes[] = { 'Shot00BK' };
override bool TryPickup(in out Actor toucher)
{
bool success = false;
// Try to give ammo of each type, as long as we have anything to give at all
for (int i = 0; i < AmmoTypes.Size() && Amount > 0; i++)
{
let at = AmmoTypes[i];
// Check if we have any weapons that use this ammo type
for (let ii = toucher.Inv; ii != null; ii = ii.Inv)
{
let weap = Weapon(ii);
if (weap == null)
{
// Not a weapon
continue;
}
Ammo aa;
if (weap.Ammo1 is at)
{
// Correct ammo1
aa = weap.Ammo1;
}
else if (weap.Ammo2 is at)
{
// Correct ammo2
aa = weap.Ammo2;
}
else
{
// Wrong ammo types
continue;
}
// Correct ammo. See how much we can give
int toGive = Min(aa.MaxAmount - aa.Amount, Amount);
aa.Amount += toGive;
Amount -= toGive;
// Pickup will succeed if at least 1 ammo has been given
success = success || toGive > 0;
}
}
if (success)
{
// If there's still some ammo left, create a residual pickup
if (Amount > 0 && (bDropped || !ShouldRespawn()))
{
let newItem = Inventory(Actor.Spawn("LooseSGSHOTBase", Pos));
if (newItem != null)
{
newItem.Vel = Vel;
newItem.Angle = Angle;
newItem.Pitch = Pitch;
newItem.Roll = Roll;
newItem.FloatBobPhase = FloatBobPhase;
newItem.Amount = Amount;
newItem.bIgnoreSkill = true;
newItem.bDropped = bDropped;
}
}
// OK, register pickup
GoAwayAndDie();
}
else
{
toucher.A_Print("I can't carry any more #00 shotgun shells");
}
return success;
}
}
And here's an example of one of its "children" that has a set amount of ammo.
Code: Select all
class LooseSGSHOTBox7 : LooseSGSHOTBase
{
Default
{
Inventory.Amount 7;
Inventory.PickupMessage "Box of 12 Gauge #00 Shot";
}
States
{
Spawn:
SGAA A -1 Bright;
Stop;
}
}
Again, my thanks for anyone that stops by and has a look, and helps.