Scriptname _SAG_PlayCards_MainScript extends Quest ;===================================================================================== ; FUNCTIONS ;===================================================================================== Function OpenCardInterface(_00E_TavernGames_GamlingTableSC objGamblingTableRef) objGamblingTable = objGamblingTableRef s_chargeninitialtext = Game.GetGameSettingString("sCharGenControlsDisabled") Game.SetGameSettingString("sCharGenControlsDisabled","") initialFurn = PlayerRef.GetFurnitureReference() Game.DisablePlayerControls(abMovement = true, abFighting = true, abCamSwitch =true, abLooking = true, abSneaking = true, abMenu = false, abActivate = true, abJournalTabs = false, aiDisablePOVType = 0) Game.ForceFirstPerson() Commentator.GetActorBase().SetVoiceType((Opponent.GetReference() as Actor).GetVoiceType()) Commentator.SetName(Opponent.GetReference().GetDisplayName()) Commentator.SetDisplayName(Opponent.GetReference().GetDisplayName(), true) Game.SetInChargen(abDisableSaving = true, abDisableWaiting = true, abShowControlsDisabledMessage = true) PlayerPosition.MoveTo(PlayerRef) Utility.Wait(0.3) PlayerRef.MoveTo(Cameraman) if Opponent.GetReference().IsDisabled() Opponent.GetReference().Enable() endif Commentator.Say(GenericDialogue_Gambling_StartGameTopic) Utility.Wait(5) PlayCards() EndFunction Function PlayCards() Step01() EndFunction int Function Step01() ; place your bet ; need to calculate the max bet first if Opponent.GetReference().GetItemCount(Gold001) > PlayerRef.GetItemCount(Gold001) MaxBet = (PlayerRef.GetItemCount(Gold001))/2 elseif Opponent.GetReference().GetItemCount(Gold001) < PlayerRef.GetItemCount(Gold001) MaxBet = (Opponent.GetReference().GetItemCount(Gold001))/2 else MaxBet = (PlayerRef.GetItemCount(Gold001))/2 endif if EnderalFunctions.TextInputEnabled() PlayerBet = (((self as QUEST) as FORM) as UILIB_1).ShowTextInput(PlaceYourBet .GetName()+MaxBet, MaxBet) as int else float fPrevValue = PlayerRef.GetActorValue("Variable08") PlayerRef.SetActorValue("Variable08", MaxBet) int iBet = _SAG_SelectBetMessage.Show() PlayerRef.SetActorValue("Variable08", fPrevValue) if iBet == 0 PlayerBet = 50 elseif iBet == 1 PlayerBet = 100 elseif iBet == 2 PlayerBet = 200 elseif iBet == 3 PlayerBet = 350 elseif iBet == 4 PlayerBet = 500 elseif iBet == 5 PlayerBet = 750 elseif iBet == 6 PlayerBet = 1000 else PlayerBet = 0 endif endif if PlayerBet <= 0 FinishGameAndClearUp() elseif PlayerBet > MaxBet Step01() else PlayerPurse.EnableNoWait(true) OpponentBet = utility.RandomInt(PlayerBet +(-3) , PlayerBet +5) if OpponentBet <= 0 OpponentBet = PlayerBet endif GlobalBet = OpponentBet + PlayerBet BetMessage.Show(PlayerBet, OpponentBet, GlobalBet) EnemyPurse.EnableNoWait(true) RegisterForKey(14) RegisterForKey(271) Helps.ShowAsHelpMessage("ShowCurrentStatsPC", 4.0, 3.0, 1) Step02() Return PlayerBet endif EndFunction Function Step02() ; take player's cards PCardLeft = Utility.RandomInt(0, 9) PCardMiddle = Utility.RandomInt(0, 9) PCardRight = Utility.RandomInt(0, 9) totalplayer = 3 + PCardLeft + PCardMiddle + PCardRight int BoostPrice = (PlayerBet*45)/100 Utility.Wait(2.0) CardFlip.Play(PlayerRef) PlayersLeft[PCardLeft].EnableNoWait(true) Utility.Wait(2) CardFlip.Play(PlayerRef) PlayersRight[PCardRight].EnableNoWait(true) Utility.Wait(2) CardFlip.Play(PlayerRef) PlayersMiddle[PCardMiddle].EnableNoWait(true) Utility.Wait(2) RegisterForKey(46) RegisterForKey(280) PressToCheatNow.ShowAsHelpMessage("PCCheatNow", 4.0, 3.0, 1) Utility.Wait(4.0) UnregisterforKey(46) UnregisterforKey(280) ;incase the player was detected while bInCheatAttempt == true Utility.Wait(0.1) endwhile totalplayer = 3 + PCardLeft + PCardMiddle + PCardRight PlayerScore.Show(totalplayer) int choicedices = ThrowDices.Show(BoostPrice) if ChoiceDices == 0 _00E_TavernGames_DiceRollM.Play(PlayerRef) Utility.Wait(0.75) int Dices = Utility.RandomInt(2, 12) PlayerDice01 = Utility.RandomInt(1,6) PlayerDice02 = Utility.RandomInt(1,6) Dices = PlayerDice01 +PlayerDice02 PlayerDiceGroup01[PlayerDice01+(-1)].Enable(true) PlayerDiceGroup02[PlayerDice02+(-1)].Enable(true) totalplayer = totalplayer + Dices PlayerRef.RemoveItem(Gold001, BoostPrice, false, Opponent.GetReference()) DicesResult.Show(Dices, totalplayer) endif Helps.ShowAsHelpMessage("ShowCurrentStatsPC", 4.0, 3.0, 1) Step03() EndFunction Function Step03() ; take opponent's cards Utility.Wait(1.5) ECardLeft = Utility.RandomInt(0, 9) ECardRight = Utility.RandomInt(0, 9) ECardMiddle = Utility.RandomInt(0, 9) totalEnemy = 3 + ECardLeft + EcardRight + EcardMiddle int EBoostPrice = (OpponentBet*45)/100 int EnemyDices = Utility.RandomInt(2, 12) OpponentDice01 = Utility.RandomInt(1,6) OpponentDice02 = Utility.RandomInt(1,6) EnemyDices = OpponentDice01 + OpponentDice02 CardFlip.Play(PlayerRef) EnemyMiddle[ECardMiddle].EnableNoWait(true) Utility.Wait(2) CardFlip.Play(PlayerRef) EnemyRight[ECardRight].EnableNoWait(true) Utility.Wait(2) CardFlip.Play(PlayerRef) EnemyLeft[ECardLeft].EnableNoWait(true) Utility.Wait(2.0) if totalEnemy > totalplayer EnemyResult.Show(totalEnemy) elseif totalEnemy + 11 >= totalplayer _00E_TavernGames_DiceRollM.Play(PlayerRef) Utility.Wait(0.75) OpponentDiceGroup01[OpponentDice01+(-1)].Enable(true) OpponentDiceGroup02[OpponentDice02+(-1)].Enable(true) EnemyDicesResult.Show(totalEnemy, EnemyDices, EBoostPrice) Opponent.GetReference().RemoveItem(Gold001, EBoostPrice, false, PlayerRef) totalEnemy = totalEnemy + EnemyDices else EnemyResult.Show(totalEnemy) endif Helps.ShowAsHelpMessage("ShowCurrentStatsPC", 2.0, 3.0, 1) Step04() EndFunction Function Step04() ; check who won if totalEnemy > totalPlayer EnemyWon.Show(totalplayer, totalEnemy, GlobalBet) PlayerRef.RemoveItem(Gold001, PlayerBet, false, Opponent.GetReference()) LostGames.Value += 1 LostBets.Value += GlobalBet Commentator.Say(GenericDialogue_Gambling_PlayerLostTopic) Utility.Wait(4) elseif totalEnemy < totalPlayer Victory.Add() PlayerWon.Show(totalplayer, totalEnemy, GlobalBet) Opponent.GetReference().RemoveItem(Gold001, OpponentBet, false, PlayerRef) WonGames.Value += 1 WonBets.Value += GlobalBet Commentator.Say(GenericDialogue_Gambling_PlayerWonTopic) If Wongames.GetValueInt() == 10 Steam.UnlockAchievement("END_CARDSHARK_01") EndIf Utility.Wait(4) elseif totalEnemy == totalPlayer NoOneWon.Show(totalplayer, totalEnemy) ExAequo.Value += 1 Commentator.Say(GenericDialogue_Gambling_PlayerWonTopic) Utility.Wait(4) endif if PlayerRef.GetItemCount(Gold001) >= 10 && Opponent.GetReference().GetItemCount(Gold001) >= 10 int PlayAgainCHoice = PlayAgain.Show(PlayerRef.GetItemCount(Gold001),Opponent.GetReference().GetItemCount(Gold001) ) if PlayAgainChoice == 0 ResetGame() else FinishGameAndClearUp() endif else FinishGameNoGold() EndIf EndFunction Function FinishGameNoGold() if Opponent.GetReference().GetItemCount(GOld001) < 10 OpponentNoMoreGold.Show() endif OpponentShoutThief.Clear() UnregisterForKey(14) UnregisterForKey(271) punishment = 0 if Opponent.GetReference().IsDisabled() Opponent.GetReference().Enable() endif PlayerDiceGroup01[PlayerDice01+(-1)].Disable(false) PlayerDiceGroup02[PlayerDice02+(-1)].Disable(false) OpponentDiceGroup01[OpponentDice01+(-1)].Disable(false) OpponentDiceGroup02[OpponentDice02+(-1)].Disable(false) PlayersLeft[PCardLeft].Disable(FALSE) PlayersRight[PCardRight].Disable(false) PlayersMiddle[PCardMiddle].Disable(false) EnemyLeft[ECardLeft].Disable(false) EnemyRight[ECardRight].Disable(false) EnemyMiddle[ECardMiddle].Disable(false) EnemyPurse.Disable(false) PlayerPurse.Disable(false) Opponent.Clear() Victory.Remove() playerbet = 0 opponentbet = 0 globalbet = 0 totalplayer = 0 totalenemy = 0 Message.ResetHelpMessage("ShowCurrentStatsPC") Message.ResetHelpMessage("PCCheatNow") Utility.Wait(2.0) if initialFurn != none PlayerRef.MoveTo(initialFurn) else PlayerRef.MoveTo(PlayerPosition) endif Game.EnablePlayerControls() Game.SetGameSettingString("sCharGenControlsDisabled", s_chargeninitialtext) Game.SetInChargen(abDisableSaving = false, abDisableWaiting = true, abShowControlsDisabledMessage = false) objGamblingTable.SendGameFinishedEvent() EndFunction Function ResetGame() OpponentShoutThief.Clear() punishment = 0 if Opponent.GetReference().IsDisabled() Opponent.GetReference().Enable() endif PlayerDiceGroup01[PlayerDice01+(-1)].Disable(false) PlayerDiceGroup02[PlayerDice02+(-1)].Disable(false) OpponentDiceGroup01[OpponentDice01+(-1)].Disable(false) OpponentDiceGroup02[OpponentDice02+(-1)].Disable(false) PlayersLeft[PCardLeft].Disable(FALSE) PlayersRight[PCardRight].Disable(false) PlayersMiddle[PCardMiddle].Disable(false) EnemyLeft[ECardLeft].Disable(false) EnemyRight[ECardRight].Disable(false) EnemyMiddle[ECardMiddle].Disable(false) EnemyPurse.Disable(false) PlayerPurse.Disable(false) Victory.Remove() playerbet = 0 opponentbet = 0 globalbet = 0 totalplayer = 0 totalenemy = 0 Message.ResetHelpMessage("ShowCurrentStatsPC") Message.ResetHelpMessage("PCCheatNow") PlayCards() EndFunction Function FinishGameAndClearUp() OpponentShoutThief.Clear() UnregisterForKey(14) UnregisterForKey(271) punishment = 0 if Opponent.GetReference().IsDisabled() Opponent.GetReference().Enable() endif PlayerDiceGroup01[PlayerDice01+(-1)].Disable(false) PlayerDiceGroup02[PlayerDice02+(-1)].Disable(false) OpponentDiceGroup01[OpponentDice01+(-1)].Disable(false) OpponentDiceGroup02[OpponentDice02+(-1)].Disable(false) PlayersLeft[PCardLeft].Disable(FALSE) PlayersRight[PCardRight].Disable(false) PlayersMiddle[PCardMiddle].Disable(false) EnemyLeft[ECardLeft].Disable(false) EnemyRight[ECardRight].Disable(false) EnemyMiddle[ECardMiddle].Disable(false) EnemyPurse.Disable(false) PlayerPurse.Disable(false) Opponent.Clear() Victory.Remove() playerbet = 0 opponentbet = 0 globalbet = 0 totalplayer = 0 totalenemy = 0 Message.ResetHelpMessage("ShowCurrentStatsPC") Message.ResetHelpMessage("PCCheatNow") ; Utility.Wait(2.0) if initialFurn != none PlayerRef.MoveTo(initialFurn) else PlayerRef.MoveTo(PlayerPosition) endif Game.EnablePlayerControls() Game.SetGameSettingString("sCharGenControlsDisabled", s_chargeninitialtext) Game.SetInChargen(abDisableSaving = false, abDisableWaiting = true, abShowControlsDisabledMessage = false) objGamblingTable.SendGameFinishedEvent() EndFunction Event OnKeyDown(int control) if !UI.IsMenuOpen("MessageBoxMenu") if control == 14 || control == 271 Stats.Show(playerbet, OpponentBet, GlobalBet, totalplayer, totalenemy) elseif control == 46 || control == 280 AttemptToCheat() endif endif EndEvent Function AttemptToCheat() bInCheatAttempt = true UnregisterforKey(46) UnregisterforKey(280) Int[] iNums = new Int[3] iNums[0] = PCardLeft iNums[1] = PCardMiddle iNums[2] = PCardRight Int index = iNums.Length Int iLowestValue = 9 int iLowestCard While index index -= 1 Int CurrentValue = iNums[index] if CurrentValue < iLowestValue iLowestValue = CurrentValue iLowestCard = index endif EndWhile ;Debug.Notification("Lowest Value: " + (iLowestValue+1) + ", Lowest Card: " + (iLowestCard+1)) if iLowestCard == 0 PCardLeftBeforeCheat = PCardLeft PlayersLeft[PCardLeft].Disable(true) PCardLeft = 9 PlayersLeft[PCardLeft].Enable(true) ReplacedCard = 1 CalculateIfDetected() elseif iLowestCard == 1 PCardMiddleBeforeCheat = PCardMiddle PlayersMiddle[PCardMiddle].Disable(true) PCardMiddle = 9 PlayersMiddle[PCardMiddle].Enable(true) ReplacedCard = 2 CalculateIfDetected() elseif iLowestCard == 2 PCardRightBeforeCheat = PCardRight PlayersRight[PCardRight].Disable(true) PCardRight = 9 PlayersRight[PCardRight].Enable(true) ReplacedCard = 3 CalculateIfDetected() elseif iLowestValue == 9 AllCardsOptimized.Show() endif iLowestValue = 9 bInCheatAttempt = false EndFunction Function CalculateIfDetected() float DetectionChance = Utility.RandomFloat(25.0, 110.0) if PlayerRef.GetActorValue("Pickpocket")+ (-15.0) <= DetectionChance Punishment = (OpponentBet*40)/100 OpponentBet -= Punishment GlobalBet -= Punishment _00E_TavernGames_GetCaughtM.Play(PlayerREF) _00E_TavernGames_CaughtCheatingImod.Apply() Caught.Show(Punishment) if ReplacedCard == 1 PlayersLeft[PCardLeft].Disable(true) PCardLeft = PCardLeftBeforeCheat PlayersLeft[PCardLeft].Enable(true) elseif ReplacedCard == 2 PlayersMiddle[PCardMiddle].Disable(true) PCardMiddle = PCardMiddleBeforeCheat PlayersMiddle[PCardMiddle].Enable(true) elseif ReplacedCard == 3 PlayersRight[PCardRight].Disable(true) PCardRight = PCardRightBeforeCheat PlayersRight[PCardRight].Enable(true) endif Commentator.Say(GenericDialogue_Gambling_PlayerCheatTopic) Utility.Wait(4) EndIf Return EndFunction ;===================================================================================== ; PROPERTIES ;===================================================================================== String s_chargeninitialtext Int TotalEnemy = 0 Int OpponentBet = 0 Int MaxBet = 0 Int Property TotalPlayer = 0 Auto Int GlobalBet = 0 Int Property PlayerBet = 0 Auto Int PlayerDice01 Int PlayerDice02 Int ReplacedCard Int punishment = 0 Int ECardMiddle Int ECardLeft Int ECardRight Int PCardMiddle Int PCardLeft Int PCardRight Int PCardLeftBeforeCheat Int PCardMiddleBeforeCheat Int PCardRightBeforeCheat Int OpponentDice01 Int OpponentDice02 bool bInCheatAttempt = false ObjectReference initialFurn _00E_TavernGames_GamlingTableSC objGamblingTable Topic Property GenericDialogue_Gambling_StartGameTopic Auto Topic Property GenericDialogue_Gambling_PlayerLostTopic Auto Topic Property GenericDialogue_Gambling_PlayerWonTopic Auto Topic Property GenericDialogue_Gambling_PlayerCheatTopic Auto Actor Property Commentator Auto Actor Property PlayerRef Auto Message Property PlaceYourBet Auto Message Property _SAG_SelectBetMessage Auto GlobalVariable Property ExAequo Auto GlobalVariable Property WonGames Auto GlobalVariable Property LostGames Auto GlobalVariable Property LostBets Auto GlobalVariable Property WonBets Auto ReferenceAlias Property OpponentShoutThief Auto ReferenceAlias Property Opponent Auto ImageSpaceModifier Property _00E_TavernGames_CaughtCheatingImod Auto Message Property PlayAgain Auto Message Property PressToCheatNow Auto Message Property PlayerScore Auto Message Property DicesResult Auto Message Property ThrowDices Auto Message Property BetMessage Auto Message Property EnemyDicesResult Auto Message Property EnemyResult Auto Message Property OpponentNoMoreGold Auto Message Property Caught Auto Message Property Helps Auto Message Property Stats Auto Message Property PlayerWon Auto Message Property EnemyWon Auto Message Property NoOneWon Auto Message Property AllCardsOptimized Auto ObjectReference Property EnemyPurse Auto ObjectReference Property PlayerPurse Auto ObjectReference Property PlayerPosition Auto Hidden ObjectReference Property Cameraman Auto ObjectReference Property PlayCards_ThiefShouter Auto ;PLAYER CARDS ObjectReference[] Property PlayersLeft Auto ObjectReference[] Property PlayersMiddle Auto ObjectReference[] Property PlayersRight Auto ; OPPONENT CARDS ObjectReference[] Property EnemyLeft Auto ObjectReference[] Property EnemyMiddle Auto ObjectReference[] Property EnemyRight Auto ObjectReference[] Property PlayerDiceGroup01 Auto ObjectReference[] Property PlayerDiceGroup02 Auto ObjectReference[] Property OpponentDiceGroup01 Auto ObjectReference[] Property OpponentDiceGroup02 Auto MusicType Property Victory Auto Sound Property CardFlip Auto Sound Property _00E_TavernGames_ThiefShoutM Auto Sound Property _00E_TavernGames_GetCaughtM Auto Sound Property _00E_TavernGames_DiceRollM Auto MiscObject Property Gold001 Auto ObjectReference Property BeeHive Auto