Alright, so Panzerfaust spawns linked to SpawnAreas is something I have been trying to accomplish for Kriegstadt for quite a long time, but have never quite gotten it to work out. What you are going to see is a mish-mash of code from a lot of stuff...ROVehicleFactory, ROTeamGame, ROPanzerFaustPickup, all that good stuff.
So if any coding gurus can lend a hand, it would be much appreciated...
So if any coding gurus can lend a hand, it would be much appreciated...
Code:
class ROPanzerFaustPickupEH extends ROPlaceableAmmoPickup;
var Ammo LastSpawnedPickup;
var bool bActive;
var() bool bDestroyPickupWhenInactive;
var() class<Inventory> WeaponType;
var() int PickupRespawnLimit;
var int TotalSpawnedPickups;
var array<ROPanzerFaustPickupEH> FaustPickups;
var array<ROSpawnArea> SpawnAreas;
var ROSpawnArea CurrentSpawnArea[2]; // Stores the current spawn areas being used
var array<ROSpawnArea> TankCrewSpawnAreas;
var ROSpawnArea CurrentTankCrewSpawnArea[2];// Stores the current tank crew spawn areas being used
var() bool bUsesSpawnAreas;
static function StaticPrecache(LevelInfo L)
{
L.AddPrecacheStaticMesh(StaticMesh'WeaponPickupSM.Weapons.Panzerfaust');
L.AddPrecacheStaticMesh(StaticMesh'WeaponPickupSM.Ammo.Warhead3rd');
L.AddPrecacheStaticMesh(StaticMesh'WeaponPickupSM.Ammo.Warhead1st');
L.AddPrecacheMaterial(Material'Weapons3rd_tex.German.Panzerfaust_world');
L.AddPrecacheMaterial(Material'Weapons1st_tex.Grenades.Panzerfaust_S');
}
function PostBeginPlay()
{
Super.PostBeginPlay();
if( !bUsesSpawnAreas )
Activate();
}
//Yanked from ROTeamGame
function CheckFaustPickups()
{
local int i;
for( i = 0; i < FaustPickups.Length; i++)
{
if( FaustPickups[i] == none )
continue;
if( FaustPickups[i].bUsesSpawnAreas )
{
if( ((CurrentTankCrewSpawnArea[AXIS_TEAM_INDEX] != none &&
CurrentTankCrewSpawnArea[AXIS_TEAM_INDEX].Tag == FaustPickups[i].Tag) ||
CurrentSpawnArea[AXIS_TEAM_INDEX].Tag == FaustPickups[i].Tag) ||
( (CurrentTankCrewSpawnArea[ALLIES_TEAM_INDEX] != none &&
CurrentTankCrewSpawnArea[ALLIES_TEAM_INDEX].Tag == FaustPickups[i].Tag) ||
CurrentSpawnArea[ALLIES_TEAM_INDEX].Tag == FaustPickups[i].Tag) )
{
FaustPickups[i].Activate();
}
else
{
FaustPickups[i].Deactivate();
}
}
else
{
FaustPickups[i].Activate();
}
}
}
function Activate()
{
bActive = True;
}
function Deactivate()
{
bActive = False;
//This part is sketchy; not sure how to word it properly
//if (bDestroyPickupWhenInactive && ROVehicle(LastSpawnedVehicle) != None )
//{
// ROVehicle(LastSpawnedVehicle).ResetTime = Level.TimeSeconds + 1;
//}
}
auto state Pickup
{
function bool ReadyToPickup(float MaxWait)
{
return true;
}
/* ValidTouch()
Validate touch (if valid return true to let other pick me up and trigger event).
*/
function bool ValidTouch( actor Other )
{
// make sure its a live player
if ( (Pawn(Other) == None) || !Pawn(Other).bCanPickupInventory || (Pawn(Other).Health <= 0) || (Pawn(Other).DrivenVehicle == None && Pawn(Other).Controller == None))
return false;
if( ROPawn(Other) != none && ROPawn(Other).AutoTraceActor != none && ROPawn(Other).AutoTraceActor == self )
{
// do nothing
}
// make sure not touching through wall
else if ( !FastTrace(Other.Location, Location) )
return false;
// make sure game will let player pick me up
if( Level.Game.PickupQuery(Pawn(Other), self) )
{
TriggerEvent(Event, self, Pawn(Other));
return true;
}
return false;
}
// When touched by an actor.
function Touch( actor Other )
{
}
function CheckTouching()
{
}
function UsedBy( Pawn user )
{
local Inventory Copy;
local inventory Inv;
local bool bHasWeapon;
if( user == none )
return;
// check if Other has a primary weapon
if( user != none && user.Inventory != none )
{
for ( Inv=user.Inventory; Inv!=None; Inv=Inv.Inventory )
{
if ( Inv != none && Weapon(Inv) != None )
{
if( Inv.class == WeaponType)
{
if( Weapon(Inv).AmmoMaxed(0) )
return;
else
bHasWeapon = true;
}
}
}
}
// valid touch will pickup the object
if( ValidTouch( user ) )
{
if( bHasWeapon )
Copy = SpawnCopy(user);
else
Copy = SpawnWeaponCopy(user);
AnnouncePickup(user);
if ( Copy != None )
Copy.PickupFunction(user);
//if (bActive)
//SetRespawn();
}
}
function Timer()
{
if (bDropped)
{
GotoState('FadeOut');
//SetRespawn();
}
}
function BeginState()
{
UntriggerEvent(Event, self, None);
if ( bDropped )
{
AddToNavigation();
SetTimer(DropLifeTime, false);
}
}
function EndState()
{
if ( bDropped )
RemoveFromNavigation();
}
Begin:
CheckTouching();
}
//
// Set up respawn waiting if desired.
//
function SetRespawn()
{
//if (bActive)
StartSleeping();
}
function inventory SpawnWeaponCopy( pawn Other )
{
local inventory Copy;
if ( Inventory != None )
{
Copy = Inventory;
Inventory = None;
}
else
Copy = Other.spawn(WeaponType,Other,,,rot(0,0,0));
Copy.GiveTo( Other, self );
return Copy;
}
function Reset()
{
if( !bUsesSpawnAreas )
Activate();
}
event Trigger( Actor Other, Pawn EventInstigator )
{
}
defaultproperties
{
InventoryType=class'PanzerFaustAmmoEH'//class'PanzerFaustWeapon'
WeaponType=class'PanzerFaustWeaponEH'
PickupMessage="You got the Panzerfaust."
TouchMessage="Pick Up: Panzerfaust"
PickupSound=Sound'Inf_Weapons_Foley.WeaponPickup'
PickupForce="AssaultRiflePickup" // jdf
bAmmoPickupIsWeapon=true
MaxDesireability=+0.78
StaticMesh=StaticMesh'WeaponPickupSM.Weapons.Panzerfaust'
RespawnTime=3.000000
AmmoAmount = 1
DrawType=DT_StaticMesh
DrawScale=1.0
AmbientGlow=10
bDestroyPickupWhenInactive=True
TeamNum=NEUTRAL
PickupRespawnLimit=255
CollisionRadius=25.0
CollisionHeight=3.0
PrePivot=(X=0.0,Y=0.0,Z=3.0)
}