For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Trying to prevent item redundancy upon level load, how would that be fixed?

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
Post Reply
User avatar
Martin Vole
OldUnreal Member
Posts: 21
Joined: Thu Dec 07, 2017 3:45 am

Trying to prevent item redundancy upon level load, how would that be fixed?

Post by Martin Vole »

Code: Select all

var() class PowerSuitType;

var inventory RedundantSuit;

function PreBeginPlay()
{
      local inventory PowSuit;
      
      RedundantSuit = Findinventorytype(PowerSuitType);
      //ClientMessage("Do I have a:"@RedundantSuit@"?");
      If (PowerSuitType != None && !bInventoryLoaded && RedundantSuit == None)
      {
            PowSuit=Spawn(PowerSuitType,Self,,self.location);
            PowSuit.GiveTo(Self);
            bInventoryLoaded = True;
      }
      Super.PreBeginPlay();
}
The idea here is that, upon first load, the PowerSuit of the type specified is given to the player, but afterwards, no new ones are added as each level is loaded to prevent redundant suits being given. What ACTUALLY happens is, that after each level load, another suit is given and any redundancy check is ignored.

There must be something I'm missing here.

Edit: Holy crap, I've placed in dozens of prevention checks and it still duplicates like rabbits in heat after each level load. What the hell is this? Seriously, is there something specific to PreBeginPlay or something that makes it largely unsuitable?

Edit 2: Prettied up ordering.

Edit 3: This is relevant only to single player modes, mind.
Last edited by Martin Vole on Tue Mar 06, 2018 2:36 am, edited 1 time in total.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Trying to prevent item redundancy upon level load, how would that be fixed?

Post by []KAOS[]Casey »

Try using PostBeginPlay and not PreBeginPlay, your inventory chain is probably not complete or even initialized yet during PreBeginPlay
User avatar
Martin Vole
OldUnreal Member
Posts: 21
Joined: Thu Dec 07, 2017 3:45 am

Re: Trying to prevent item redundancy upon level load, how would that be fixed?

Post by Martin Vole »

Try using PostBeginPlay and not PreBeginPlay, your inventory chain is probably not complete or even initialized yet during PreBeginPlay

Code: Select all

var() class PowerSuitType;

var inventory RedundantSuit;

event PostBeginPlay()
{
      local inventory PowSuit;
      
      RedundantSuit = Findinventorytype(PowerSuitType);
      //ClientMessage("Do I have a:"@RedundantSuit@"?");
      If (PowerSuitType != None && !bInventoryLoaded && RedundantSuit == None)
      {
            PowSuit=Spawn(PowerSuitType,Self,,self.location);
            PowSuit.GiveTo(Self);
            bInventoryLoaded = True;
      }
      Super.PostBeginPlay();
}
Still seems to be duplicating itself after each level load. Also, doesn't seem to give the item at all in deathmatch modes.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Trying to prevent item redundancy upon level load, how would that be fixed?

Post by []KAOS[]Casey »

I assume the class that's executing this code is some kind of playerpawn?

edit: if that's the case, try using:

Code: Select all

event TravelPostAccept()
{
      local inventory PowSuit;

      Super.TravelPostAccept();

      RedundantSuit = Findinventorytype(PowerSuitType);
      //ClientMessage("Do I have a:"@RedundantSuit@"?");
      If (PowerSuitType != None && !bInventoryLoaded && RedundantSuit == None)
      {
            PowSuit=Spawn(PowerSuitType,Self,,self.location);
            PowSuit.GiveTo(Self);
            bInventoryLoaded = True;
      }
} 
Last edited by []KAOS[]Casey on Tue Mar 06, 2018 5:14 am, edited 1 time in total.
User avatar
Martin Vole
OldUnreal Member
Posts: 21
Joined: Thu Dec 07, 2017 3:45 am

Re: Trying to prevent item redundancy upon level load, how would that be fixed?

Post by Martin Vole »

Oh wow, that actually worked! Fixed both the issues! Many thanks! I didn't even know about that event call, that will be nifty to have to apply to a number of other mods I'm messing with.
User avatar
[]KAOS[]Casey
OldUnreal Member
Posts: 4497
Joined: Sun Aug 07, 2011 4:22 am
Location: over there

Re: Trying to prevent item redundancy upon level load, how would that be fixed?

Post by []KAOS[]Casey »

For reference "TravelPostAccept" is called after your inventory chain is guaranteed to be initialized. This is also called in the inventory classes themselves, you can see an example in Amplifier (check 227 versions, pre 227 has a bug)
Post Reply

Return to “UScript Board”