void GetACard();

void main()
{

  object oPC = GetLastSpeaker();
  int nYourHand = GetLocalInt(oPC,"Blackjack");
  int nDealerHand = 17 + Random(8);
  SendMessageToPC(oPC,"You have " + IntToString(nYourHand) + ". The dealer has " + IntToString(nDealerHand) + ".");
  if ((nDealerHand > 21) || (nYourHand > nDealerHand && nYourHand < 22))
  {
    SendMessageToPC(oPC,"You win!");
    SetLocalInt(oPC,"BJGameOver",TRUE);
    GiveGoldToCreature(oPC,50);
  }
  else
  {
    SendMessageToPC(oPC,"You lose!");
    SetLocalInt(oPC,"BJGameOver",TRUE);
    TakeGoldFromCreature(50,oPC,TRUE);
  }

}

void GetACard()

{

  object oPC = GetLastSpeaker();
  int nTotal = GetLocalInt(oPC,"Blackjack");
  int nCard = Random(13) + 1;
  string sCardName = IntToString(nCard);
  if (nCard == 1)
  {
    sCardName = "Ace";
    if (nTotal <= 10)
      nCard = 11;
  }
  if (nCard == 11)
  {
    sCardName = "Jack";
    nCard = 10;
  }
  if (nCard == 12)
  {
    sCardName = "Queen";
    nCard = 10;
  }
  if (nCard == 13)
  {
    sCardName = "King";
    nCard = 10;
  }
  SetLocalInt(oPC,"Blackjack",nTotal + nCard);
  SendMessageToPC(oPC,"The dealer gives you a " + sCardName);

}
