My program doesn't have bugs. It just develops random features.

Difference between revisions of "UE2:PawnFactory"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
(Moved Legacy Custom Class)
 
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{classbox| [[Legacy:UT2004|UT2004]] :: [[Legacy:Actor|Actor]] >> PawnFactory (Custom)}}
+
__TOC__
 
+
A generic factory for spawning pawns. The pawns used needs to be a sub-class of [[UE2:AnotherPawn|AnotherPawn]].
A generic factory for spawning pawns. The pawns need to be a sub-class of [[Legacy:Fyfe/AnotherPawn|AnotherPawn]].
+
  
 
'''NOTE:''' If your looking for a factory for vehicles check out [[Legacy:SVehicleFactory|Engine.SVehicleFactory]]
 
'''NOTE:''' If your looking for a factory for vehicles check out [[Legacy:SVehicleFactory|Engine.SVehicleFactory]]
  
 
==Properties==
 
==Properties==
 
+
===Visible===
===Main===
+
 
; bool bEnabled : Factory is enabled by default.
 
; bool bEnabled : Factory is enabled by default.
; class<[[Legacy:Fyfe/AnotherPawn|AnotherPawn]]> PawnClass : The pawn to spawn.
+
; class<[[UE2:AnotherPawn|AnotherPawn]]> PawnClass : The pawn to spawn.
 
; int MaxPawnCount : The max number of pawns this factory can create.
 
; int MaxPawnCount : The max number of pawns this factory can create.
 
 
===Hidden===
 
===Hidden===
 
; int PawnCount : The current number of pawns this factory has created.
 
; int PawnCount : The current number of pawns this factory has created.
  
 
==Events==
 
==Events==
; PawnCreated( [[Legacy:Fyfe/AnotherPawn|AnotherPawn]] Pawn ) : Called by the factory when a pawn is created.
+
; PawnCreated( [[UE2:AnotherPawn|AnotherPawn]] Pawn ) : Called by the factory when a pawn is created.
; PawnDestroyed( [[Legacy:Fyfe/AnotherPawn|AnotherPawn]] Pawn ) : Called by the pawn when it's destroyed.
+
; PawnDestroyed( [[UE2:AnotherPawn|AnotherPawn]] Pawn ) : Called by the pawn when it's destroyed.
 
; Trigger( [[Legacy:Actor|Actor]] Other, [[Legacy:Pawn|Pawn]] EventInstigator ) : Spawns a new pawn if <code>PawnClass</code> is set and we haven't reached the <code>MaxPawnCount</code>.
 
; Trigger( [[Legacy:Actor|Actor]] Other, [[Legacy:Pawn|Pawn]] EventInstigator ) : Spawns a new pawn if <code>PawnClass</code> is set and we haven't reached the <code>MaxPawnCount</code>.
  
 
==Code==
 
==Code==
 
+
{{Infobox class
<div class="hidden-block"><span class="hint"></span><div class="hidden">
+
| class   = PawnFactory
 +
| custom  = yes
 +
| parent1 = Actor
 +
}}
 
<uscript>
 
<uscript>
 
// ============================================================================
 
// ============================================================================
Line 131: Line 131:
 
bDirectional=true
 
bDirectional=true
 
}
 
}
</uscript></div></div>
+
</uscript>
 
+
==Related Topics==
+
* [[Open_Source]]
+
  
 
==Notes==
 
==Notes==
'''fyfe:''' Nothing overly fancy or original, it's based off of [[Legacy:SVehicleFactory|Engine.SVehicleFactory]].
+
'''fyfe:''' Added <code>PawnCreated()</code>, and added some code to set <code>bEnabled</code> to false while <code>PawnCount == MaxPawnCount</code> or if <code>PawnClass</code> isn't set.
  
'''fyfe:''' Added <code>PawnCreated()</code>, and added some code to set <code>bEnabled</code> to false while <code>PawnCount == MaxPawnCount</code> or if <code>PawnClass</code> isn't set.
+
==Related Topics==
 +
* [[UE2:AnotherPawn]]

Latest revision as of 16:36, 8 April 2008

A generic factory for spawning pawns. The pawns used needs to be a sub-class of AnotherPawn.

NOTE: If your looking for a factory for vehicles check out Engine.SVehicleFactory

Properties[edit]

Visible[edit]

bool bEnabled 
Factory is enabled by default.
class<AnotherPawn> PawnClass 
The pawn to spawn.
int MaxPawnCount 
The max number of pawns this factory can create.

Hidden[edit]

int PawnCount 
The current number of pawns this factory has created.

Events[edit]

PawnCreated( AnotherPawn Pawn ) 
Called by the factory when a pawn is created.
PawnDestroyed( AnotherPawn Pawn ) 
Called by the pawn when it's destroyed.
Trigger( Actor Other, Pawn EventInstigator ) 
Spawns a new pawn if PawnClass is set and we haven't reached the MaxPawnCount.

Code[edit]

UE2 Actor >> PawnFactory (custom)
This class in other games:
U2XMP
// ============================================================================
// PawnFactory
// Copyright (c) 2006 by Andrew Fyfe <andrew@neptune-one.net>
// This program is free software; you can redistribute and/or modify
// it under the terms of the Lesser Open Unreal Mod License version 1.1.
//
// A generic factory for spawning pawns. The pawns need to be a sub-class of
// NeptuneOne.AnotherPawn.
//
// NOTE: If your looking for a factory for vehicles check out
// Engine.SVehicleFactory
// ============================================================================
 
class PawnFactory extends Actor
	placeable;
 
 
// ============================================================================
// Properties
// ============================================================================
 
var()	bool				bEnabled;		// Factory is enabled by default.
var()	class<AnotherPawn>	PawnClass< SEMI >		// The pawn to spawn.
var()	int 				MaxPawnCount;	// The max number of pawns this factory can create.
var		int 				PawnCount;		// The current number of pawns this factory has created.
 
 
// ============================================================================
// PawnCreated
//
// Called by the factory when a pawn is created.
// ============================================================================
 
event PawnCreated( AnotherPawn Pawn )
{
	PawnCount++;
	Pawn.ParentFactory = self;
 
	if ( PawnCount >= MaxPawnCount )
	{
		Log( "PawnFactory.Trigger(): MaxPawnCount reached, I'm not going to spawn another pawn.", 'NeptuneOne' );
		bEnabled = false;
	}
}
 
 
// ============================================================================
// PawnDestroyed
//
// Called by the pawn when it's destroyed.
// ============================================================================
 
event PawnDestroyed( AnotherPawn Pawn )
{
	PawnCount--;
 
	if ( PawnCount < MaxPawnCount )
	{
		Log( "PawnFactory.PawnDestroyed(): The factory is enabled again.", 'NeptuneOne' );
		bEnabled = true;
	}
}
 
 
// ============================================================================
// Trigger
//
// Spawns a new pawn if PawnClass is set and we haven't reached the
// MaxPawnCount.
// ============================================================================
 
event Trigger( Actor Other, Pawn EventInstigator )
{
	local AnotherPawn CreatedPawn;
 
	if ( !bEnabled )
		return;
 
	if ( PawnClass == None )
	{
		// Oops somebody forgot to set a PawnClass.
		Warn( "PawnFactory.Trigger(): "@self@" has no PawnClass! Disabling factory!" );
		bEnabled = false;
		return;
	}
 
	CreatedPawn = Spawn( PawnClass, , , Location, Rotation );
	if ( CreatedPawn != None )
		PawnCreated( CreatedPawn );
}
 
 
// ============================================================================
// Defaults
// ============================================================================
 
defaultproperties
{
	bEnabled=true
	MaxPawnCount=1
 
	bHidden=true
	Texture=S_Keypoint
	RemoteRole=ROLE_None
	bNoDelete=true
	bDirectional=true
}

Notes[edit]

fyfe: Added PawnCreated(), and added some code to set bEnabled to false while PawnCount == MaxPawnCount or if PawnClass isn't set.

Related Topics[edit]