xxxPawn default properties change:
Code:
bCanPickupInventory=false
xxxPlayerController variables:
Code:
var Actor CurrentPickup;
xxxPlayerController functions:
Code:
/*
================================================
ValidPickup()
Checks whether or not a certain actor is actually something we can pickup or not.
Rather bad way to go about it, but since PickupFactories, DroppedPickups etc
don't share and common parent class, aside from Actor, I'm unsure what to check for yet...
================================================
*/
function bool ValidPickup(Actor Pickup)
{
// all dropped pickups can be picked up, else they wouldn't exist
if (DroppedPickup(Pickup) != None)
{
return true;
}
else if (PickupFactory(Pickup) != None)
{
// If a pickup factory is hidden, it can't be picked up
return (PickupFactory(Pickup).bPickupHidden == false);
}
// If a pickup factory is hidden, it can't be picked up
else if (UTCarriedObject(Pickup) != None)
{
if (UTCarriedObject(Pickup).bHome == true)
{
return true;
}
if (UTCarriedObject(Pickup).IsInState('Dropped'))
{
return true;
}
}
// not a valid pickup
return false;
}
/*
================================================
FindPickup()
Finds a pickup (dropped, factory, weapon cache etc) within a limited radius.
Returns true if its valid.
================================================
*/
function bool FindPickup()
{
local Actor Pickup, Best;
local vector ViewDir, PawnLoc2D, PickupLoc2D;
local float NewDot, BestDot;
if (Pawn == None)
{
return false;
}
CurrentPickup = None;
// are we standing on one?
if ((Pawn.Base != None) && ValidPickup(Pawn.Base))
{
CurrentPickup = Pawn.Base;
return true;
}
// Pick best nearby item
PawnLoc2D = Pawn.Location;
PawnLoc2D.Z = 0;
ViewDir = vector(Pawn.Rotation);
ForEach Pawn.OverlappingActors(class'Actor', Pickup, Pawn.VehicleCheckRadius)
{
if (ValidPickup(Pickup))
{
// Prefer items that Pawn is facing
PickupLoc2D = Pickup.Location;
PickupLoc2D.Z = 0;
NewDot = Normal(PickupLoc2D-PawnLoc2D) Dot ViewDir;
if ((Best == None) || (NewDot > BestDot))
{
// check that item is visible
if ( FastTrace(Pickup.Location,Pawn.Location) )
{
Best = Pickup;
BestDot = NewDot;
}
}
}
}
// remember what we found please
CurrentPickup = Best;
// if Best is not NULL, we found something
return (Best != None);
}
insert into xxxPlayerController::PerformedUseAction() :
Code:
...
return Vehicle(Pawn).DriverLeave(false);
}
// If we find a valid pickup, touch it.
if (FindPickup())
{
bCanPickupInventory = true;
CurrentPickup.Touch(Pawn, None, CurrentPickup.Location, Normal(CurrentPickup.Location-Pawn.Location));
bCanPickupInventory = false;
return true;
}
// try to find a vehicle to drive
if (FindVehicleToDrive())
{
...
This is based on code I used in UT3, slightly updated.
It was designed to work with default UT3 items/weapons.
If you don't need to do that, then there are better ways to do this, as shown by Blade.
Bookmarks