PDA

View Full Version : Turn auto pickup into manual button pressed pickup



Kinos
03-09-2011, 10:19 AM
I want to change the pickup system so I can pickup items by pressing a button.
I tried changing pickupQuery function, but weapons won't pickup once pawn is inside weapon's collision box. I want to change it so it doesn't matter if you are already inside. I have this much.


function bool PickupQuery(Pawn Other, class<Inventory> ItemClass, Actor Pickup)
{
local byte bAllowPickup;
cont = Other.controller;
if (BaseMutator != None && BaseMutator.OverridePickupQuery(Other, ItemClass, Pickup, bAllowPickup))
{
return bool(bAllowPickup);
}

if(cont.isAimingAt(PickUp, 0))
{
`log("Should PickUp");
if(Other.InvManager!=none)
{
Other.ClientMessage("This is a "$PickUp); `log("Will pick up");
if(bTrue)
{
`log("Pick up: " $PickUp @" ?");
return Other.InvManager.HandlePickupQuery(ItemClass, Pickup);
}
else
return false;
}
else
{
return false;
}
}
else
{
return false;
}
}

Any ideas?

he3117
03-09-2011, 10:35 AM
override isvalidtouch or touch in your pickup and put your pickup codes in PerformedUseAction in player controller:


function bool CheckWeaponToPickup()
{
local KADroppedPickup V, Best;
local vector ViewDir, PawnLoc2D, VLoc2D;
local float NewDot, BestDot;

// Pick best nearby vehicle
PawnLoc2D = Pawn.Location;
PawnLoc2D.Z = 0;
ViewDir = vector(Pawn.Rotation);

ForEach Pawn.OverlappingActors(class'KADroppedPickup', V, 50)
{
// Prefer vehicles that Pawn is facing
VLoc2D = V.Location;
Vloc2D.Z = 0;
NewDot = Normal(VLoc2D-PawnLoc2D) Dot ViewDir;
if ( (Best == None) || (NewDot > BestDot) )
{
// check that vehicle is visible
//if ( FastTrace(V.Location,Pawn.Location) )
//{
Best = V;
BestDot = NewDot;
//}
}
}
if (Best != none && Best.ValidUse(Pawn))//write valid use function or change with validtouch
{
Best.GiveTo(Pawn);
return true;
}
return false;

}
///////////
simulated function bool PerformedUseAction()
{
if(Role >= Role_Authority && CheckWeaponToPickup())
{
return true;
}
return super.PerformedUseAction();
}

Blade[UG]
03-09-2011, 01:42 PM
you guys always make things so hard :D



auto state Pickup
{
function bool ValidTouch(Pawn Other) { return False; }
function bool UsedBy(Pawn User) { GiveTo(User); return True; }
}


then implement the code in your player controller to use the item.

Kinos
03-10-2011, 12:30 PM
That didn't work. I'm still having trouble because my pawn and the weapon having their collision boxes touch, but not equiping the weapon until the player presses E (exec function use()).
Any ideas?

Kinos
03-11-2011, 03:57 PM
bumping because it hurts.
I still don't have a solution to my issue. To reiterate( and explain clearer) I want to pickup items by pressing the use key. However, it seems that once I'm inside the collision box of the item and pressed the button, my pawn won't pickup.
I did another method where I made an bool function. While true and if ran over the item(from outside the collision box), pawn could pickup weapon. It's not what I want, but at least it isolated my issue. Please advise. Thanks.

slowJusko
03-11-2011, 09:05 PM
xxxPawn default properties change:


bCanPickupInventory=false
xxxPlayerController variables:


var Actor CurrentPickup;
xxxPlayerController functions:


/*
================================================
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() :


...
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.

Blade[UG]
03-12-2011, 08:41 AM
got 3 working solutions here, one of them should do it for ya :D

Kinos
03-13-2011, 05:15 PM
Just wanted to say waInfinite thanks + 1. That worked out for me.

Kinos
04-11-2011, 09:15 AM
How do I make it so I have to hold the E button instead of pressing it.