Travelling functions

From Oldunreal-Wiki
Revision as of 07:33, 21 May 2011 by .:..: (talk | contribs) (Created)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Inventory travelling functions

Since 227g GameInfo has following functions for modifying inventory travelling:

event ModifyTravelList( PlayerPawn Other, out array<Actor> TravelList );
event string GetPlayerTravelID( PlayerPawn Other, bool bSave )
{
	return Other.PlayerReplicationInfo.PlayerName;
}
event Actor SpawnTravelActor( Class<Actor> ActorClass, PlayerPawn DesiredOwner )
{
	return SpawnAct(ActorClass,DesiredOwner.Location,DesiredOwner.Rotation,,DesiredOwner,DesiredOwner,,false);
}

ModifyTravelList - is called shortly before level change when saving player inventory, this allows modder to change the inventory list to save.

GetPlayerTravelID - is called before level change with bSave==true and after a player postlogin with bSave==false, used to get ID of player for identifying the inventory lists (MULTIPLAYER ONLY!).

SpawnTravelActor - is called after PostLogin for each inventory that's about to spawn for a player.

Example modification

Let's say you want all nearby monsters to travel with the player to next level:

function ModifyTravelList( PlayerPawn Other, out array<Actor> TravelList )
{
	local Pawn P;
	local int i;

	i = Array_Size(TravelList); // Store the current length of the array.

	// Collect all nearby visible monsters thats alive.
	foreach VisibleCollidingActors(Class'Pawn',P,1000,Other.Location)
	{
		if( P.bIsPlayer || P.Health<=0 )
			continue;
		TravelList[i++] = P; // Add monster to the array.
	}
}
function Actor SpawnTravelActor( Class<Actor> ActorClass, PlayerPawn DesiredOwner )
{
	if( ActorClass.Default.bIsPawn ) // Is a Pawn, not inventory, so spawn it next to player.
		return TryToSpawnAt(ActorClass,DesiredOwner);
	else return SpawnAct(ActorClass,DesiredOwner.Location,DesiredOwner.Rotation,,DesiredOwner,DesiredOwner,,false);
}
final function Actor TryToSpawnAt( class<Actor> A, Actor Other )
{
	local byte i;
	local vector V;
	local Actor A;

	for( i=0; i<10; ++i ) // Give it 10 tries.
	{
		V.X = FRand()-0.5;
		V.Y = FRand()-0.5; // Randomize offset around player
		V.Z = 0;

		// Normalize the vector and multiply by randomized distance from player.
		V = Normal(V)*(Other.CollisionRadius+A.Default.CollisionRadius+100*FRand())+Other.Location;
		A = Spawn(A,,,V,Other.Rotation);
		if( A!=None )
			return A;
	}
	return None; // Give up, too small spawn area.
}

Since only Pawn.Health is marked as "travel" variable, only the monster's health will remain from last map. Note: this code has not been tested yet.