TR_m7_NPC_ErnasiViran
TR_Mainland.esm
Variables
12
Local Variables
nolore
T_Local_NoLore
TR_Map
control
controlQ
T_Local_NPC
controlB
uncalmed_count
combat_active
riverbend_strength
threshold
calm_timer
Source
1begin TR_m7_NPC_ErnasiViran
2
3short nolore
4short T_Local_NoLore
5short TR_Map
6short control ; teleportation beyond her room for the sleeping npc's dialogue
7short controlQ
8short T_Local_NPC
9
10; Q2
11short controlB ; forcegreeting after Riverbend brawl
12float riverbend_strength
13
14; For calm-based surrender calculation
15short uncalmed_count
16float threshold
17short combat_active ; tracks if combat has been established (prevents false trigger on taunt frame)
18float calm_timer ; tracks how long all thugs have been non-targeting (needs 2s+ to count as calmed)
19
20if ( CellChanged )
21 if ( GetDeadCount "TR_m7_Ernasi Viran_slp" >= 1 )
22 if ( GetDisabled == 0 )
23 disable
24 endif
25 endif
26endif
27
28if ( OnDeath )
29 ; use TR_m7_ErnasiViranDead == 1 check instead of GetDeadCount
30 set TR_m7_ErnasiViranDead to 1
31 return
32endif
33
34if ( GetJournalIndex TR_m7_Ns_IL_2 < 10 )
35elseif ( GetJournalIndex TR_m7_Ns_IL_2 < 25 )
36 if ( control == 0 )
37 set control to 1
38 PositionCell 3755 4199 15557 0 "Narsis, Ernasi Viran's Apartment"
39 AiWander 0 0 0
40 SetHello 0
41 SetAlarm 0
42 endif
43elseif ( GetJournalIndex TR_m7_Ns_IL_2 == 25 )
44 if ( control )
45 set control to 0
46 PositionCell 4132 4355 15562 5400 "Narsis, Ernasi Viran's Apartment"
47 AiWander 0 0 0
48 SetHello 30
49 SetAlarm 100
50 endif
51endif
52
53;---------------------------------------------------------------
54
55; THIS SECTION CONTROLS HOW ERNASI REACTS TO THE RIVERBEND BRAWL
56; Combat check: GetTarget, Player - if targeting player, they're in combat
57; Calm requires 2+ seconds of no thugs targeting player (avoids pathing glitches)
58
59if ( MenuMode )
60 return
61endif
62
63if ( controlB == 0 )
64 if ( GetJournalIndex TR_m7_Ns_IL_2 == 40 )
65 ; Only check if fight has been initiated (at least one thug engaged)
66 if ( "TR_m7_Abael Thelas".control > 0 )
67 elseif ( "TR_m7_Felos Baradan".control > 0 )
68 elseif ( "TR_m7_Tens Velith".control > 0 )
69 else
70 ; No fight initiated yet, skip check
71 return
72 endif
73
74 ; Wait for combat to actually establish (at least one thug targeting player)
75 if ( combat_active == 0 )
76 if ( "TR_m7_Abael Thelas"->GetTarget, Player == 1 )
77 set combat_active to 1
78 elseif ( "TR_m7_Felos Baradan"->GetTarget, Player == 1 )
79 set combat_active to 1
80 elseif ( "TR_m7_Tens Velith"->GetTarget, Player == 1 )
81 set combat_active to 1
82 else
83 ; Combat not established yet, wait
84 return
85 endif
86 endif
87
88 ; Count uncalmed NPCs (targeting player) and sum their health
89 set riverbend_strength to 0
90 set uncalmed_count to 0
91
92 if ( "TR_m7_Abael Thelas"->GetTarget, Player == 1 )
93 set riverbend_strength to ( riverbend_strength + "TR_m7_Abael Thelas".healthpercent )
94 set uncalmed_count to ( uncalmed_count + 1 )
95 endif
96
97 if ( "TR_m7_Felos Baradan"->GetTarget, Player == 1 )
98 set riverbend_strength to ( riverbend_strength + "TR_m7_Felos Baradan".healthpercent )
99 set uncalmed_count to ( uncalmed_count + 1 )
100 endif
101
102 if ( "TR_m7_Tens Velith"->GetTarget, Player == 1 )
103 set riverbend_strength to ( riverbend_strength + "TR_m7_Tens Velith".healthpercent )
104 set uncalmed_count to ( uncalmed_count + 1 )
105 endif
106
107 ; If any thug still targeting player, reset calm timer
108 if ( uncalmed_count > 0 )
109 set calm_timer to 0
110 else
111 ; All thugs not targeting - increment timer
112 set calm_timer to ( calm_timer + GetSecondsPassed )
113 endif
114
115 ; All calmed for 2+ seconds = surrender (use controlB 2 for calm-specific dialogue)
116 if ( uncalmed_count == 0 )
117 if ( calm_timer >= 2 )
118 set controlB to 2
119 ForceGreeting
120 return
121 endif
122 endif
123
124 ; Health-based surrender (no timer needed)
125 set threshold to ( uncalmed_count * 0.34 )
126 if ( riverbend_strength < threshold )
127 if ( uncalmed_count > 0 )
128 set controlB to 1
129 ForceGreeting
130 return
131 endif
132 endif
133 endif
134endif
135
136;---------------------------------------------------------------
137
138if ( TR_Map )
139 return
140endif
141
142set TR_Map to 7
143
144End