This article's documentation is for anything that uses the Source engine. Click here for more information.

logic_random_outputs

From Valve Developer Community
Jump to: navigation, search
English (en)Translate (Translate)
Class hierarchy
CLogicRandomOutputs
CLogicalEntity
CServerOnlyEntity
CBaseEntity
logic_random_outputs.cpp

logic_random_outputs is a point entity available in all Source Source games since Alien Swarm Alien Swarm. (also in Mapbase) It randomly fires one of up to eight separate outputs. Use logic_case in older engine branches or if you need twice as many outputs.

Icon-Bug.pngBug:The numbering of the OnTriggerChance keyvalues is off by one: they start at 1 while the game expects them to start at 0.code This causes the keyvalues to not correspond to the expected outputs. See below for a fix.
For example, the keyvalue OnTriggerChance1 determines the chance of the OnTrigger2 output. With this incorrect set of keyvalues, OnTrigger1 is never fired and OnTriggerChance8 does not correspond to any of the outputs.  [todo tested in?]

Keyvalues

Name (targetname) <string>
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

OnTrigger1 Chance (OnTriggerChance1) to OnTrigger8 Chance (OnTriggerChance8) <float>
Chance (from 0 to 1) of the OnTrigger1-8 output firing when this entity is triggered.
Start Disabled (StartDisabled) <boolean>
Stay dormant until activated (with theEnableinput).

Flags

Only trigger once : [1]
Allow fast retrigger : [2]

Inputs

Trigger
Trigger this entity, causing its OnTrigger outputs to fire if it is enabled.
Toggle
Toggle this entity between enabled and disabled.
CancelPending
Cancel any events fired by this entity that are currently pending in the I/O event queue.

EnableDisable:

Enable / Disable
Enable/disable this entity from performing its task. It might also disappear from view.

Outputs

OnSpawn
Fired when this entity is spawned. If this entity is set to only trigger once, it will delete itself after firing this output.
OnTrigger1 to OnTrigger8
This output has a chance to fire when the entity is triggered.


FGD Code

This code belongs to base.fgd. In the highlighted lines, the index of the KeyValue's name was decreased by 1 each but not their display text. So that with this fix, the numbering of the KeyValues and outputs will match in Hammer such that mappers can act as if this bug didn't exist, as long as SmartEdit is turned on.

@PointClass base(Targetname, EnableDisable) iconsprite("editor/logic_random_outputs.vmt") = logic_random_outputs :
	"A message forwarder. Fires up to eight separate outputs, each with a different chance of firing."
[
	spawnflags(flags) =
	[
		1: "Only trigger once" : 0
		2: "Allow fast retrigger" : 0
	]
	OnTriggerChance0(float) : "OnTrigger1 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger1 output firing when this entity is triggered."
	OnTriggerChance1(float) : "OnTrigger2 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger2 output firing when this entity is triggered."
	OnTriggerChance2(float) : "OnTrigger3 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger3 output firing when this entity is triggered."
	OnTriggerChance3(float) : "OnTrigger4 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger4 output firing when this entity is triggered."
	OnTriggerChance4(float) : "OnTrigger5 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger5 output firing when this entity is triggered."
	OnTriggerChance5(float) : "OnTrigger6 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger6 output firing when this entity is triggered."
	OnTriggerChance6(float) : "OnTrigger7 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger7 output firing when this entity is triggered."
	OnTriggerChance7(float) : "OnTrigger8 Chance" : "1.0" : "Chance (from 0 to 1) of the OnTrigger8 output firing when this entity is triggered."

	// Inputs
	input Trigger(void) : "Trigger this entity, causing its OnTrigger outputs to fire if it is enabled."
	input Toggle(void) : "Toggle this entity between enabled and disabled."
	input CancelPending(void) : "Cancel any events fired by this entity that are currently pending in the I/O event queue."
	
	// Outputs
	output OnSpawn(void) : "Fired when this entity is spawned. If this entity is set to only trigger once, it will "+
		"delete itself after firing this output."
	output OnTrigger1(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger2(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger3(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger4(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger5(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger6(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger7(void) : "This output has a chance to fire when the entity is triggered."
	output OnTrigger8(void) : "This output has a chance to fire when the entity is triggered."
]