TR_m3_NPC_Nodgar
TR_Mainland.esm
Variables
14
Local Variables
TR_Map
control
controlQ
T_Local_NPC
NoLore
T_Local_PlayNineholesNpcState
T_Local_PlayNineholesGold
T_Local_PlayNineholesNpcId
T_Local_PlayNineholesMinStakes
T_Local_PlayNineholesMaxStakes
lastTurn
wager
changelevel
localDaysPassed
Source
1Begin TR_m3_NPC_Nodgar
2
3short TR_Map
4short control
5short controlQ
6short T_Local_NPC
7short NoLore
8; START Local variables for nine-holes NPC scripting
9short T_Local_PlayNineholesNpcState ; 0:not in game, 1:assigned to ongoing game
10short T_Local_PlayNineholesGold ; Keeps track of the gold NPC has
11short T_Local_PlayNineholesNpcId ; A (hopefully) unique ID of this NPC used to track if a game against them is played
12short T_Local_PlayNineholesMinStakes ; 1(low), 2(mid), 3(high)
13short T_Local_PlayNineholesMaxStakes ; 1(low), 2(mid), 3(high)
14short lastTurn ; hold the previous value of T_Glob_NineholesGameState
15short wager ; Used for money counting when adding/removing it.
16short changelevel ; Initial gold value the NPC starts with, used for replenishing from time to time
17short localDaysPassed ; DaysPassed storage, used for replenishing from time to time
18; END Local variables for nine-holes NPC scripting
19
20
21; START Main logic code snippet for the nine-holes NPC scripting
22; -- Keep track of NPC's gold
23if ( T_Local_PlayNineholesGold != ( GetItemCount gold_001 ) )
24 set T_Local_PlayNineholesGold to ( GetItemCount gold_001 )
25endif
26
27; -- Replenish gold after a week if it went below initial level
28if ( changelevel > 0 )
29 if ( T_Local_PlayNineholesGold < changelevel )
30 if ( ( localDaysPassed + 7 ) <= DaysPassed ) ; At least a week passed
31 set wager to ( changelevel - T_Local_PlayNineholesGold )
32 while ( wager >= 10 )
33 AddItem "Gold_001" 10
34 set wager to ( wager - 10 )
35 endwhile
36 while ( wager >= 1 )
37 AddItem "Gold_001" 1
38 set wager to ( wager - 1 )
39 endwhile
40 set T_Local_PlayNineholesGold to ( GetItemCount gold_001 )
41 set localDaysPassed to DaysPassed
42 endif
43 endif
44endif
45
46; -- Track the game state and react to it
47if ( T_Local_PlayNineholesNpcState == 0 )
48 if ( T_Local_PlayNineholesNpcId != 0 )
49 if ( T_Glob_NineholesOpponentId == T_Local_PlayNineholesNpcId ) ; The game now belongs to this NPC
50 set T_Local_PlayNineholesNpcState to 1
51 set lastTurn to T_Glob_NineholesGameState
52 endif
53 endif
54elseif ( T_Local_PlayNineholesNpcState == 1 )
55 if ( T_Glob_NineholesOpponentId != T_Local_PlayNineholesNpcId ) ; The game doesn't belong to this NPC anymore
56 set T_Local_PlayNineholesNpcState to 0
57 Return
58 endif
59 if ( lastTurn != 20 )
60 if ( T_Glob_NineholesGameState == 20 ) ; New game started for this NPC
61 if ( T_Glob_NineholesBet > 0 ) ; NPC takes player's bet on game start
62 set wager to ( T_Glob_NineholesBet )
63 while ( wager >= 10 )
64 AddItem "Gold_001" 10
65 set wager to ( wager - 10 )
66 endwhile
67 while ( wager >= 1 )
68 AddItem "Gold_001" 1
69 set wager to ( wager - 1 )
70 endwhile
71 endif
72 set lastTurn to T_Glob_NineholesGameState
73 endif
74 elseif ( lastTurn == 20 )
75 if ( T_Glob_NineholesGameState == 30 ) ; Player won
76 if ( T_Glob_NineholesBet > 0 ) ; NPC loses their bet + the player's part
77 set wager to ( T_Glob_NineholesBet )
78 while ( wager >= 10 )
79 RemoveItem "Gold_001" 20
80 set wager to ( wager - 10 )
81 endwhile
82 while ( wager >= 1 )
83 RemoveItem "Gold_001" 2
84 set wager to ( wager - 1 )
85 endwhile
86 endif
87 endif
88 if ( T_Glob_NineholesGameState != lastTurn )
89 set lastTurn to T_Glob_NineholesGameState
90 endif
91 endif
92endif
93
94; -- Reset the game if NPC can't play it anymore
95if ( OnDeath )
96 if ( T_Local_PlayNineholesNpcState == 1 )
97 set T_Glob_NineholesBet to -123 ; Reset all game on death
98 set lastTurn to 0
99 endif
100 if ( GetJournalIndex "TR_m7_HO_MissingFriend" >= 10 )
101 if ( GetJournalIndex "TR_m7_HO_MissingFriend" < 100 )
102 Journal "TR_m7_HO_MissingFriend" 150
103 endif
104 endif
105endif
106if ( GetDisabled )
107 if ( T_Local_PlayNineholesNpcState == 1 )
108 set T_Glob_NineholesBet to -123 ; Reset all game on disable
109 set lastTurn to 0
110 endif
111endif
112; END Main logic code snippet for the nine-holes NPC scripting
113
114if ( TR_Map == 3 )
115 return
116endif
117
118set TR_Map to 3
119
120; START DoOnce variable settings code snippet for the nine-holes NPC scripting
121; Depends on the early return due to TR_Map! If used elsewhere, edit accordingly
122set T_Glob_NineholesNpcId to ( T_Glob_NineholesNpcId + 1 )
123set T_Local_PlayNineholesNpcId to T_Glob_NineholesNpcId
124set changelevel to T_Local_PlayNineholesGold
125set localDaysPassed to DaysPassed
126set T_Local_PlayNineholesMaxStakes to 1
127set T_Local_PlayNineholesMinStakes to 1
128if ( changelevel > 360 )
129 set T_Local_PlayNineholesMaxStakes to 3
130 if ( changelevel > 500 )
131 set T_Local_PlayNineholesMinStakes to 3
132 elseif ( changelevel > 420 )
133 set T_Local_PlayNineholesMinStakes to 2
134 endif
135elseif ( changelevel > 120 )
136 set T_Local_PlayNineholesMaxStakes to 2
137 if ( changelevel > 150 )
138 set T_Local_PlayNineholesMinStakes to 2
139 endif
140endif
141; END DoOnce variable settings code snippet for the nine-holes NPC scripting
142
143End