Scripts

TR_m1_NPC_FrasciaJandacia

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