Talk:Fallout 3 random encounters/Trigger script

Complete unaltered copy of FFETriggerScript, the script which governs the triggering of encounters.

A few explanations:
 * FFEUniqueA, FFEUniqueB, FFERepeatA and FFERepeatB are the quests which store the encounter information itself. Every encounter is a quest stage in one of these quests.
 * FFERepeatCond and FFEUniqueCond are the quests which store the additional conditions for specific encounters.

scn FFETriggerScript

short	triggered			; trigger only operates once short chance			; used for calculations short dieRoll			; used for die rolls

short uniqueEncounter	; set to 1 if we're looking for a unique encounter; 0 = repeatable

short startRolling 			; set to 1 to trigger looping die rolls for unique encounters (until a new one is picked) short encounterRoll 		; used for encounter die rolls

ref marker1 ref marker2 ref marker3 ref marker4 ref marker5 ref marker6 ref marker7
 * reference variables hold specific markers for this trigger
 * this is initialized OnLoad

short encounterSet		; 0 = set A								; 1 = set B
 * initialized on load based on GetIsID check

short childTrigger			; set to 1 if this trigger is linked to another one ; in this case, this trigger doesn't do anything but activate its parent

begin onTriggerEnter player set marker1 to GetLinkedRef ; if I'm linked to another trigger zone, don't initialize the rest of it	if marker1.getIsID FFETriggerA == 1 || marker1.getIsID FFETriggerB == 1 || marker1.getIsID FFETriggerBNoVertibird == 1 set childTrigger to 1 else set marker2 to marker1.GetLinkedRef set marker3 to marker2.GetLinkedRef set marker4 to marker3.GetLinkedRef set marker5 to marker4.GetLinkedRef set marker6 to marker5.GetLinkedRef set marker7 to marker6.GetLinkedRef endif
 * initializing with linked markers

if getIsID FFETriggerB == 1 || getIsID FFETriggerBNoVertibird == 1 set encounterSet to 1 endif
 * what kind of trigger am I?

if triggered == 1 return endif

; if I'm a "child trigger", just act as if my parent was triggered if childTrigger == 1 marker1.enterTrigger player return endif

; otherwise, ; randomly pick whether to trigger an encounter at all

if GetRandomPercent <= FFEncounterChance ; initialize trigger quest reference variables with my markers set FFETrigger.marker1 to marker1 set FFETrigger.marker2 to marker2 set FFETrigger.marker3 to marker3 set FFETrigger.marker4 to marker4 set FFETrigger.marker5 to marker5 set FFETrigger.marker6 to marker6 set FFETrigger.marker7 to marker7

; fail if these markers don't exist if marker1 == 0 || marker2 == 0 || marker3 == 0 || marker4 == 0 || marker5 == 0 set triggered to 1 return endif

; only "default" B triggers allow vertibird landing if encounterSet == 1 && getIsID FFETriggerB == 1 set FFETrigger.vertibirdLand to 1 else set FFETrigger.vertibirdLand to 0 endif

; if in FFEEncounterWorld, just set up quest variables if getInWorldspace FFEncounterWorld == 1 || FFETrigger.manual == 1 if getInWorldspace FFEncounterWorld == 1 || FFETrigger.debug == 1 ShowMessage FFEDebugMsgInit endif set triggered to 1 return endif

; unique or repeatable encounter? ; 1. figure out chance of repeatable encounter set chance to FFERepeatChance		; base value for a repeatable encounter ; increase chance as unique encounters are used up		if encounterSet == 0 set chance to chance + 50 * ( FFEUniqueACount / FFEUniqueAMax ) elseif encounterSet == 1 set chance to chance + 50 * ( FFEUniqueBCount / FFEUniqueBMax ) endif

if FFETrigger.debug == 1 ShowMessage FFEDebugMsgChance chance endif

; 2. roll for unique vs repeatable set dieRoll to GetRandomPercent if dieRoll <= chance ; repeatable if FFETrigger.debug == 1 ShowMessage FFEDebugMsgRepeatRoll dieRoll endif set uniqueEncounter to 0 else ; unique if FFETrigger.debug == 1 ShowMessage FFEDebugMsgUniqueRoll dieRoll endif set uniqueEncounter to 1 endif

; tell script to start rolling for encounters set startRolling to 1 set encounterRoll to 0

set triggered to 1		; mark as triggered -- trigger zone only generates an encounter once endif

end

begin gamemode ; "looping" die rolls for encounters if startRolling > 0 ; are we in the middle or rolling, or just starting? if encounterRoll == 0 ; roll a starting roll if encounterSet == 0 if uniqueEncounter == 1 set encounterRoll to GetRandomPercent * FFEUniqueAMax / 100 + 1 else set encounterRoll to GetRandomPercent * FFERepeatAMax / 100 + 1 endif elseif encounterSet == 1 if uniqueEncounter == 1 set encounterRoll to GetRandomPercent * FFEUniqueBMax / 100 + 51 else set encounterRoll to GetRandomPercent * FFERepeatBMax / 100 + 51 endif endif else ; increment to next encounter number set encounterRoll to encounterRoll + 1 ; if we've rolled over, go back to beginning if encounterSet == 0 if uniqueEncounter == 1 if encounterRoll > FFEUniqueAMax set startRolling to startRolling + 1 set encounterRoll to 1						; starting point for set A					endif else if encounterRoll > FFERepeatAMax set startRolling to startRolling + 1 set encounterRoll to 1						; starting point for set A					endif endif elseif encounterSet == 1 if uniqueEncounter == 1 if encounterRoll > ( FFEUniqueBMax + 51 ) set startRolling to startRolling + 1 set encounterRoll to 51						; starting point for set B					endif else if encounterRoll > ( FFERepeatBMax + 51 ) set startRolling to startRolling + 1 set encounterRoll to 51						; starting point for set B					endif endif endif endif

; did we find an unused encounter? if uniqueEncounter == 1 if ( encounterSet == 0 && getStageDone FFEUniqueA encounterRoll == 0 ) || ( encounterSet == 1 && getStageDone FFEUniqueB encounterRoll == 0 ) ; yes if FFETrigger.debug == 1 ShowMessage FFEDebugMsgUniqueEncounterRoll encounterRoll endif setstage FFEUniqueCond encounterRoll if ( encounterSet == 0 && getStageDone FFEUniqueA encounterRoll == 0 ) || ( encounterSet == 1 && getStageDone FFEUniqueB encounterRoll == 0 ) ; if the encounter didn't actually happen (due to conditions), keep rolling if FFETrigger.debug == 1 ShowMessage FFEDebugMsgInvalid endif else ; encounter happened -- done! set startRolling to 0 endif else ; no -- keep rolling, unless... ; if we've already been once through the whole list, we'd better stop (no valid encounters available) if ( encounterSet == 0 && startRolling > FFEUniqueAMax ) || ( encounterSet == 1 && startRolling > FFEUniqueBMax ) set startRolling to 0 ; reset trigger so encounter location can be used again set triggered to 0 if FFETrigger.debug == 1 ShowMessage FFEDebugMsgNoEncounters endif endif endif else if ( encounterSet == 0 && getStageDone FFERepeatA encounterRoll == 0 ) || ( encounterSet == 1 && getStageDone FFERepeatB encounterRoll == 0 ) ; yes if FFETrigger.debug == 1 ShowMessage FFEDebugMsgRepeatEncounterRoll encounterRoll endif setstage FFERepeatCond encounterRoll ; if the encounter didn't actually happen (due to conditions), keep rolling if ( encounterSet == 0 && getStageDone FFERepeatA encounterRoll == 0 ) || ( encounterSet == 1 && getStageDone FFERepeatB encounterRoll == 0 ) if FFETrigger.debug == 1 ShowMessage FFEDebugMsgInvalid endif ; increment encounter count -- we do this here for repeatable quests because we don't care if we miss a few on each pass through ; (and we want to make sure we don't wait to restart the cycle for encounters which don't pass the conditions) if encounterSet == 0 set FFERepeatACount to FFERepeatACount + 1 elseif encounterSet == 1 set FFERepeatBCount to FFERepeatBCount + 1 endif

; keep rolling, unless... ; if we've already been once through the whole list, we'd better stop (no valid encounters available) if ( encounterSet == 0 && startRolling > FFERepeatAMax ) || ( encounterSet == 1 && startRolling > FFERepeatBMax ) set startRolling to 0 ; reset trigger so encounter location can be used again set triggered to 0 if FFETrigger.debug == 1 ShowMessage FFEDebugMsgNoEncounters endif endif

else ; encounter happened -- done! set startRolling to 0 endif else ; if we've already done ALL the repeatable encounters in this set, reset the quest and repeat if ( encounterSet == 0 && FFERepeatACount >= FFERepeatAMax ) if FFETrigger.debug == 1 ShowMessage FFEDebugMsgRepeatFinishA encounterRoll endif set FFERepeatACount to 0 ResetQuest FFERepeatA setstage FFERepeatCond encounterRoll set startRolling to 0 elseif ( encounterSet == 1 && FFERepeatBCount >= FFERepeatBMax ) if FFETrigger.debug == 1 ShowMessage FFEDebugMsgRepeatFinishB encounterRoll endif set FFERepeatBCount to 0 ResetQuest FFERepeatB setstage FFERepeatCond encounterRoll set startRolling to 0 else ; no -- keep rolling endif endif

if startRolling == 0 ; we found an encounter ; increment encounter count -- we do this here for repeatable quests because we don't care if we miss a few on each pass through ; (and we want to make sure we don't wait to restart the cycle for encounters which don't pass the conditions) if encounterSet == 0 set FFERepeatACount to FFERepeatACount + 1 elseif encounterSet == 1 set FFERepeatBCount to FFERepeatBCount + 1 endif endif

endif

endif end