#include "_sh_inc_list" //NPC takes action here int GetCardValue(string sCard) { if (sCard == "2") return 2; if (sCard == "3") return 3; if (sCard == "4") return 4; if (sCard == "5") return 5; if (sCard == "6") return 6; if (sCard == "7") return 7; if (sCard == "8") return 8; if (sCard == "9") return 9; if (sCard == "10" || sCard == "J" || sCard == "Q" || sCard == "K") return 10; if (sCard == "A") return 11; return 0; } void DrawExtraCard() { int nValue = GetLocalInt(OBJECT_SELF, "VALUE");; int nHandCards = GetLocalInt(OBJECT_SELF, "CARDS"); object oDeck = GetLocalObject(OBJECT_SELF, "oDeck"); object oHand = GetLocalObject(OBJECT_SELF, "oHand"); //Let's draw a card int nCards = ListGetElementCount(oDeck); int nElement = Random(nCards)+1; string sCard = ListGetString(oDeck, nElement); ListRemoveElement(oDeck, nElement); ListAddString(oHand, "sCard"); //Let's check the hand's value and proceed accordingly nCards = ListGetElementCount(oHand); int i; for (i = 1; i <= nCards; i++) { sCard = ListGetString(oHand, i); nValue += GetCardValue(sCard); } if (nValue > 21) { //We need to check if there are any aces in hand } else if (nValue >= 18) { SetLocalInt(OBJECT_SELF, "CARDS", nHandCards); SetLocalInt(OBJECT_SELF, "VALUE", nValue); return; } else if (nValue >= 15 && Random(3) == 0) { DrawExtraCard(); return; } else if (nValue >= 12 && Random(3) != 0) { DrawExtraCard(); return; } else { DrawExtraCard(); return; } } void main() { object oDeck = GetLocalObject(OBJECT_SELF, "oDeck"); //Make a hand for the NPC string sHand = GetLocalString(OBJECT_SELF, "DeckName")+"_C"; object oHand = ListCreate(sHand); SetLocalObject(OBJECT_SELF, "oHand", oHand); //Draw the first card for the NPC int nCards = ListGetElementCount(oDeck); int nElement = Random(nCards)+1; string sCard = ListGetString(oDeck, nElement); ListRemoveElement(oDeck, nElement); ListAddString(oHand, "sCard"); //Draw the second card for the NPC nCards = ListGetElementCount(oDeck); nElement = Random(nCards)+1; sCard = ListGetString(oDeck, nElement); ListRemoveElement(oDeck, nElement); ListAddString(oHand, "sCard"); //Let's check the hand's value and proceed accordingly int nValue; int nHandCards = 2; sCard = ListGetString(oHand, 1); nValue = GetCardValue(sCard); sCard = ListGetString(oHand, 2); nValue += GetCardValue(sCard); SetLocalInt(OBJECT_SELF, "CARDS", 2); SetLocalInt(OBJECT_SELF, "VALUE", nValue); if (nValue >= 18) { SetLocalInt(OBJECT_SELF, "CARDS", nHandCards); SetLocalInt(OBJECT_SELF, "VALUE", nValue); return; } else if (nValue >= 15 && Random(3) == 0) { DrawExtraCard(); return; } else if (nValue >= 12 && Random(3) != 0) { DrawExtraCard(); return; } else { DrawExtraCard(); return; } }