T_ScNpc_Mw_Map4NineHoles
Tamriel_Data.esm
Variables
15
Local Variables
TR_Map
control
controlQ
T_Local_NPC
T_Local_Khajiit
NoLore
T_Local_PlayNineholesNpcState
T_Local_PlayNineholesGold
T_Local_PlayNineholesNpcId
T_Local_PlayNineholesMinStakes
T_Local_PlayNineholesMaxStakes
lastTurn
wager
changelevel
localDaysPassed
Source
1Begin T_ScNpc_Mw_Map4NineHoles
2; This short script is there to allow dialogue to be filtered on the TR_Map local variable,
3; allowing for regional topics such as "Morrowind Lore" or "Geographic Regions" to be
4; appropriate to the location the NPC is.
5; It also adds the framework for playing the nine-holes minigame
6
7short TR_Map
8short control
9short controlQ
10short T_Local_NPC
11short T_Local_Khajiit
12short NoLore
13; START Local variables for nine-holes NPC scripting
14short T_Local_PlayNineholesNpcState ; 0:not in game, 1:assigned to ongoing game
15short T_Local_PlayNineholesGold ; Keeps track of the gold NPC has
16short T_Local_PlayNineholesNpcId ; A (hopefully) unique ID of this NPC used to track if a game against them is played
17short T_Local_PlayNineholesMinStakes ; 1(low), 2(mid), 3(high)
18short T_Local_PlayNineholesMaxStakes ; 1(low), 2(mid), 3(high)
19short lastTurn ; hold the previous value of T_Glob_NineholesGameState
20short wager ; Used for money counting when adding/removing it.
21short changelevel ; Initial gold value the NPC starts with, used for replenishing from time to time
22short localDaysPassed ; DaysPassed storage, used for replenishing from time to time
23; END Local variables for nine-holes NPC scripting
24
25
26; START Main logic code snippet for the nine-holes NPC scripting
27; -- Keep track of NPC's gold
28if ( T_Local_PlayNineholesGold != ( GetItemCount gold_001 ) )
29 set T_Local_PlayNineholesGold to ( GetItemCount gold_001 )
30endif
31
32; -- Replenish gold after a week if it went below initial level
33if ( changelevel > 0 )
34 if ( T_Local_PlayNineholesGold < changelevel )
35 if ( ( localDaysPassed + 7 ) <= DaysPassed ) ; At least a week passed
36 set wager to ( changelevel - T_Local_PlayNineholesGold )
37 while ( wager >= 10 )
38 AddItem "Gold_001" 10
39 set wager to ( wager - 10 )
40 endwhile
41 while ( wager >= 1 )
42 AddItem "Gold_001" 1
43 set wager to ( wager - 1 )
44 endwhile
45 set T_Local_PlayNineholesGold to ( GetItemCount gold_001 )
46 set localDaysPassed to DaysPassed
47 endif
48 endif
49endif
50
51; -- Track the game state and react to it
52if ( T_Local_PlayNineholesNpcState == 0 )
53 if ( T_Local_PlayNineholesNpcId != 0 )
54 if ( T_Glob_NineholesOpponentId == T_Local_PlayNineholesNpcId ) ; The game now belongs to this NPC
55 set T_Local_PlayNineholesNpcState to 1
56 set lastTurn to T_Glob_NineholesGameState
57 endif
58 endif
59elseif ( T_Local_PlayNineholesNpcState == 1 )
60 if ( T_Glob_NineholesOpponentId != T_Local_PlayNineholesNpcId ) ; The game doesn't belong to this NPC anymore
61 set T_Local_PlayNineholesNpcState to 0
62 Return
63 endif
64 if ( lastTurn != 20 )
65 if ( T_Glob_NineholesGameState == 20 ) ; New game started for this NPC
66 if ( T_Glob_NineholesBet > 0 ) ; NPC takes player's bet on game start
67 set wager to ( T_Glob_NineholesBet )
68 while ( wager >= 10 )
69 AddItem "Gold_001" 10
70 set wager to ( wager - 10 )
71 endwhile
72 while ( wager >= 1 )
73 AddItem "Gold_001" 1
74 set wager to ( wager - 1 )
75 endwhile
76 endif
77 set lastTurn to T_Glob_NineholesGameState
78 endif
79 elseif ( lastTurn == 20 )
80 if ( T_Glob_NineholesGameState == 30 ) ; Player won
81 if ( T_Glob_NineholesBet > 0 ) ; NPC loses their bet + the player's part
82 set wager to ( T_Glob_NineholesBet )
83 while ( wager >= 10 )
84 RemoveItem "Gold_001" 20
85 set wager to ( wager - 10 )
86 endwhile
87 while ( wager >= 1 )
88 RemoveItem "Gold_001" 2
89 set wager to ( wager - 1 )
90 endwhile
91 endif
92 endif
93 if ( T_Glob_NineholesGameState != lastTurn )
94 set lastTurn to T_Glob_NineholesGameState
95 endif
96 endif
97endif
98
99; -- Reset the game if NPC can't play it anymore
100if ( OnDeath )
101 if ( T_Local_PlayNineholesNpcState == 1 )
102 set T_Glob_NineholesBet to -123 ; Reset all game on death
103 set lastTurn to 0
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 ( T_Local_Khajiit )
115 return
116endif
117
118set T_Local_Khajiit to -1
119
120if ( GetRace "T_Els_Cathay" )
121 set T_Local_Khajiit to 1
122elseif ( GetRace "T_Els_Cathay-raht" )
123 set T_Local_Khajiit to 1
124elseif ( GetRace "T_Els_Dagi-raht" )
125 set T_Local_Khajiit to 1
126elseif ( GetRace "T_Els_Ohmes" )
127 set T_Local_Khajiit to 1
128elseif ( GetRace "T_Els_Ohmes-raht" )
129 set T_Local_Khajiit to 1
130elseif ( GetRace "T_Els_Suthay" )
131 set T_Local_Khajiit to 1
132elseif ( GetRace "T_Els_Tojay" )
133 set T_Local_Khajiit to 1
134elseif ( GetRace "Khajiit" )
135 set T_Local_Khajiit to 1
136endif
137set TR_Map to 4
138
139; START DoOnce variable settings code snippet for the nine-holes NPC scripting
140; Depends on the early return due to T_Local_Khajiit! If used elsewhere, edit accordingly
141set T_Glob_NineholesNpcId to ( T_Glob_NineholesNpcId + 1 )
142set T_Local_PlayNineholesNpcId to T_Glob_NineholesNpcId
143set changelevel to T_Local_PlayNineholesGold
144set localDaysPassed to DaysPassed
145set T_Local_PlayNineholesMaxStakes to 1
146set T_Local_PlayNineholesMinStakes to 1
147if ( changelevel > 360 )
148 set T_Local_PlayNineholesMaxStakes to 3
149 if ( changelevel > 500 )
150 set T_Local_PlayNineholesMinStakes to 3
151 elseif ( changelevel > 420 )
152 set T_Local_PlayNineholesMinStakes to 2
153 endif
154elseif ( changelevel > 120 )
155 set T_Local_PlayNineholesMaxStakes to 2
156 if ( changelevel > 150 )
157 set T_Local_PlayNineholesMinStakes to 2
158 endif
159endif
160; END DoOnce variable settings code snippet for the nine-holes NPC scripting
161
162End