SOLVED: Access to object var via FindInventoryType possible?

Discussions about Coding and Scripting
Post Reply
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

SOLVED: Access to object var via FindInventoryType possible?

Post by Aldebaran »

I have a class named MH2UDamage which extends UDamage.
In my base mutator class I have a function where I have to set some variables in the one and only active MH2UDamage object to default values.

So it should look like this in the base mutator class:

Code: Select all

local MH2UDamage damage; 
local Inventory Inv;

Inv = PlayerPawn.FindInventoryType(class'MH2UDamage');
if ( Inv != None)  
{
   damage=MISSING_REFERENCE_TO_OBJECT_FOUND_VIA_INVENTORY;
   damage.FinalCount = damage.Default.FinalCount;
   damage.Charge = damage.Default.Charge;
}
How can I assign the object of an inventory in line "damage=MISSING_REFERENCE_TO_OBJECT_FOUND_VIA_INVENTORY" ?
Or is it not possible?
Last edited by Aldebaran on Sat Sep 30, 2017 10:40 am, edited 1 time in total.
Chris
Experienced
Posts: 134
Joined: Mon Nov 24, 2014 9:27 am

Re: Access to object variables via FindInventoryType possibl

Post by Chris »

What are you talking about? Is it a typecast you're looking for?

Just replace damage with MH2Udamage(Inv).
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Access to object variables via FindInventoryType possibl

Post by Aldebaran »

Thanx :tu:

I think that was it, I can compile the code and I will test it asap.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Access to object variables via FindInventoryType possibl

Post by sektor2111 »

These is what I'm using - functional codes so to speak:

Code: Select all

event float BotDesireability( pawn Bot )
{
	local XCPistol D;

	D = XCPistol(Bot.FindInventoryType(class'XCPistol'));
	if ( ( D == None ) || ( D.PowerLevel >= 4 ) )
		return -1;
	else 
		return Super.BotDesireability(Bot);
}
and these

Code: Select all

function inventory SpawnCopy( pawn Other )
{
	local inventory Copy;
	local Inventory I;

	Copy = Super.SpawnCopy(Other);
	I = Other.FindInventoryType(class'XCPistol');
	if ( XCPistol(I) != None )
		XCPistol(I).amp = osAmplifier(Copy);

	I = Other.FindInventoryType(class'XCASMD');
	if ( XCASMD(I) != None )
		XCASMD(I).amp = osAmplifier(Copy);

	return Copy;
}
These are part of powerups currently boosting "Dispersion" and "ASMD".
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Access to object variables via FindInventoryType possibl

Post by Aldebaran »

Yes thanx, this is similar what Chris has posted.
And I have tested my code now, it works fine.
I think I will use this method more often :D
Post Reply