Mostly Harmless
Legacy:ClientMaterialTrigger
These classes were written by Wormbo.
The ClientMaterialTrigger class triggers Materials just like a MaterialTrigger. The important difference is: The ClientMaterialTrigger also works on network clients. (See Replication.)
The MaterialTriggerReplicationInfo is a helper class to replicate trigger events to network clients.
Contents
Properties[edit]
- array<Material> MaterialsToTrigger
- Inherited from MaterialTrigger. A list of materials 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[edit]
ETriggerAction[edit]
- TriggerTriggers
- Triggering triggers the materials. (default)
- TriggerResets
- Triggering resets the materials.
- TriggerDoesNothing
- Triggering has no effect.
EUntriggerAction[edit]
- UntriggerDoesNothing
- Untriggering does nothing. (default)
- UntriggerTriggers
- Untriggering triggers the materials.
- UntriggerResets
- Untriggering resets the materials.
Code[edit]
This custom class actually consists of two classes. Both are required for compiling.
ClientMaterialTrigger[edit]
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 // // 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[edit]
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 // // 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); } }