| Home Page | Recent Changes | Preferences

ClientMaterialTrigger

UT2003 :: Actor >> Triggers >> MaterialTrigger >> ClientMaterialTrigger
UT2003 :: Actor >> Info >> ReplicationInfo >> MaterialTriggerReplicationInfo

The ClientMaterialTrigger class triggers Materials just like a MaterialTrigger. The important difference is: The ClientMaterialTrigger also works on network clients.

The MaterialTriggerReplicationInfo is a helper class to replicate trigger events to network clients.

Properties

array<Material> MaterialsToTrigger
Inherited from MaterialTrigger. A list of matarials that should be triggered or reset.
ETriggerAction TriggerAction
What to do with the materials when the ClientMaterialTrigger is triggered.
EUntriggerAction UntriggerAction
What to do with the materials when the ClientMaterialTrigger is untriggered.

Enums

ETriggerAction

TriggerTriggers
Triggering triggers the materials. (default)
TriggerResets
Triggering resets the materials.
TriggerDoesNothing
Triggering has no effect.

EUntriggerAction

UntriggerDoesNothing
Untriggering does nothing. (default)
UntriggerTriggers
Untriggering triggers the materials.
UntriggerResets
Untriggering resets the materials.

Code

This custom class actually consists of two classes. Both are required for compiling.

ClientMaterialTrigger

Create A Subclass of MaterialTrigger in the package MyLevel and name it ClientMaterialTrigger. Paste the following code replacing the lines UnrealEd automatically added to the class:

//=============================================================================
// ClientMaterialTrigger
// Copyright 2003 by Wormbo <wormbo@onlinehome.de>
//
// A MaterialTrigger that works in network games.
//=============================================================================


class ClientMaterialTrigger extends MaterialTrigger;


//=============================================================================
// Variables
//=============================================================================

// whether triggering resets or triggers the materials
var(MaterialTrigger) enum ETriggerAction {
  TriggerTriggers,
  TriggerResets,
  TriggerDoesNothing
} TriggerAction;

// whether untriggering resets or triggers the materials
var(MaterialTrigger) enum EUnriggerAction {
  UntriggerDoesNothing,
  UntriggerTriggers,
  UntriggerResets
} UntriggerAction;

// array holding the ReplicationInfos for clientside triggering
var array<MaterialTriggerReplicationInfo> ReplicatedMaterialTriggers;


//=============================================================================
// PostBeginPlay
//
// Spawns a MaterialTriggerReplicationInfo for each triggered material.
//=============================================================================

function PostBeginPlay()
{
  local int i;
  
  ReplicatedMaterialTriggers.Length = MaterialsToTrigger.Length;
  
  for (i = 0; i < MaterialsToTrigger.Length; i++) {
    ReplicatedMaterialTriggers[i] = Spawn(class'MaterialTriggerReplicationInfo', Self);
    ReplicatedMaterialTriggers[i].SetMaterialToTrigger(string(MaterialsToTrigger[i]));
  }
}


//=============================================================================
// Trigger
//
// Tells the MTRIs about the Instigators and triggering actors and tells them
// to trigger the material.
//=============================================================================

function Trigger(Actor Other, Pawn EventInstigator)
{
  local int i;
  
  if ( Other == None )
    Other = Self;
  
  if ( TriggerAction == TriggerTriggers ) {
    for (i = 0; i < ReplicatedMaterialTriggers.Length; i++)
      if ( ReplicatedMaterialTriggers[i] != None )
        ReplicatedMaterialTriggers[i].TriggerMaterial(Other, EventInstigator);
  }
  else if ( TriggerAction == TriggerResets ) {
    for (i = 0; i < ReplicatedMaterialTriggers.Length; i++)
      if ( ReplicatedMaterialTriggers[i] != None )
        ReplicatedMaterialTriggers[i].ResetMaterial();
  }
}


//=============================================================================
// Untrigger
//
// Triggers or resets the materials depending on the UntriggerAction property.
//=============================================================================

function Untrigger(Actor Other, Pawn EventInstigator)
{
  local int i;
  
  if ( Other == None )
    Other = Self;
  
  if ( UntriggerAction == UntriggerTriggers ) {
    for (i = 0; i < ReplicatedMaterialTriggers.Length; i++)
      if ( ReplicatedMaterialTriggers[i] != None )
        ReplicatedMaterialTriggers[i].TriggerMaterial(Other, EventInstigator);
  }
  else if ( UntriggerAction == UntriggerResets ) {
    for (i = 0; i < ReplicatedMaterialTriggers.Length; i++)
      if ( ReplicatedMaterialTriggers[i] != None )
        ReplicatedMaterialTriggers[i].ResetMaterial();
  }
}

MaterialTriggerReplicationInfo

Create A Subclass of ReplicationInfo in MyLevel and name it MaterialTriggerReplicationInfo. (You need to uncheck the "Placeable classes Only" checkbox to see ReplicationInfo in the Actor Classes Browser.) Paste the following code replacing the lines UnrealEd automatically added to the class:

//=============================================================================
// MaterialTriggerReplicationInfo
// Copyright 2003 by Wormbo <wormbo@onlinehome.de>
//
// Used by ClientMaterialTrigger to replicate material trigger events to
// network clients.
//=============================================================================


class MaterialTriggerReplicationInfo extends ReplicationInfo;


//=============================================================================
// Variables
//=============================================================================

var Material MaterialToTrigger;
var string MaterialName;
var int ClientTriggerCount;
var int ClientUnTriggerCount;
var int TriggerCount;
var struct TTriggerData {
  var Actor Triggerer;
  var Pawn EventInstigator;
  var byte TriggerAction; // 0 = nothing/idle, 1 = trigger, 2 = reset
} LastTriggerings[10];


//=============================================================================
// Replication
//=============================================================================

replication
{
  reliable if ( Role == ROLE_Authority )
    TriggerCount, LastTriggerings, MaterialName;
}


simulated function PostBeginPlay()
{
  SetTimer(0.1, True);
}


function SetMaterialToTrigger(string newMaterial)
{
  MaterialName = newMaterial;
}


function TriggerMaterial(Actor Other, Pawn EventInstigator)
{
  TriggerCount++;
  LastTriggerings[TriggerCount % 10].Triggerer = Other;
  LastTriggerings[TriggerCount % 10].EventInstigator = EventInstigator;
  LastTriggerings[TriggerCount % 10].TriggerAction = 1;
}


function ResetMaterial()
{
  TriggerCount++;
  LastTriggerings[TriggerCount % 10].TriggerAction = 2;
}


simulated function Timer()
{
  if ( MaterialName != "" && MaterialToTrigger == None ) {
    MaterialToTrigger = Material(DynamicLoadObject(MaterialName, class'Material'));
    if ( MaterialToTrigger != None )
      MaterialToTrigger.Reset();
  }
  
  if ( MaterialToTrigger != None && TriggerCount > ClientTriggerCount
      && LastTriggerings[(ClientTriggerCount + 1) % 10].TriggerAction != 0 ) {
    ClientTriggerCount++;
    if ( LastTriggerings[ClientTriggerCount % 10].TriggerAction == 2 )
      MaterialToTrigger.Reset();
    else
      MaterialToTrigger.Trigger(LastTriggerings[ClientTriggerCount % 10].Triggerer,
          LastTriggerings[ClientTriggerCount % 10].EventInstigator);
  }
}

Category Class (UT2003)
Category Custom Class

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In