The one thing I was aiming for in the game was to have something that players could do while already in a conversation with other players. Because of this, there were some rule changes and the whole thing is based on a few typed-in commands. The changes rule is that it's based on a d20 instead of a deck of cards. This was done so that players could only keep half an eye on whats hapenning and still not miss anything. It could easily be changed to 2d10s, with one going out as a server message but this way is easier to follow. I know it does ruin it a bit but it does help a lot.
Anyways, on to the scripts themselves...
BlackJack Dealer (NPC) OnConversation:
Code: Select all
void main()
{
int iHeard = GetListenPatternNumber();
object oPC = GetLastSpeaker();
string sPC = GetName(oPC);
int iStart = GetLocalInt(OBJECT_SELF, "started");
int iCount = GetLocalInt(OBJECT_SELF, "count");
int iStarted = GetLocalInt(OBJECT_SELF, "begin");
int iNewCount;
int iCurrent = GetLocalInt(OBJECT_SELF, "current");
string sCurrent = GetLocalString(OBJECT_SELF, IntToString(iCurrent));
if ((iHeard == 4003) && (iStarted == 0) && (iStart == 1))
{
if ((GetGold(oPC)) < 50)
{
SpeakString("Sorry " + sPC + ", you don't have enough gold to play.");
}
else
{
int iNewCount = (iCount + 1);
SetLocalInt(OBJECT_SELF, "count", iNewCount);
SpeakString("Hello " + sPC + ". There is now " + IntToString(iNewCount) + " players.");
SetLocalString(OBJECT_SELF, IntToString(iNewCount), sPC);
SetLocalObject(OBJECT_SELF, "object" + IntToString(iNewCount), oPC);
TakeGoldFromCreature(50, oPC);
}
}
if ((iHeard == 4004) && (iStarted == 0) && (iStart == 1))
{
SetLocalInt(OBJECT_SELF, "begin", 1);
SpeakString("Everyone is here. Say 'begin' when you're ready.");
SetLocalInt(OBJECT_SELF, "current", 1);
}
if ((iHeard == 4004) && (iStarted == 1))
{
int iCards = d20();
string sCard = (IntToString(iCurrent) + "cards");
SetLocalInt(OBJECT_SELF, sCard, iCards);
SpeakString(sCurrent + " shows " + IntToString(iCards) + ". What would you like to do?");
}
if ((iHeard == 4001) && (iStarted == 1))
{
string sPCTalker = GetLocalString(OBJECT_SELF, IntToString(iCurrent));
if (sPC == sPCTalker)
{
int iCard = d10();
string sCard = (IntToString(iCurrent) + "cards");
int iOld = GetLocalInt(OBJECT_SELF, sCard);
int iNew = (iCard + iOld);
SetLocalInt(OBJECT_SELF, sCard, iNew);
SpeakString(sPC + " now has " + IntToString(iNew) + ".");
if ((iCurrent == iCount) && (iNew > 21))
{
int iHigh = GetLocalInt(OBJECT_SELF, "high");
object oHigh = GetLocalObject(OBJECT_SELF, "object" + IntToString(iHigh));
GiveGoldToCreature(oHigh, (iCount * 50));
string sHighName = GetLocalString(OBJECT_SELF, IntToString(iHigh));
SpeakString(sPC + " is bust. " + sHighName + " has won " + IntToString(iCount * 50) + " gold. Talk to me if you want to play again.");
ExecuteScript("blackjackstop", OBJECT_SELF);
}
if ((iNew > 21) && (iCurrent < iCount))
{
iCurrent = (iCurrent + 1);
SetLocalInt(OBJECT_SELF, "current", iCurrent);
string sCurrent = GetLocalString(OBJECT_SELF, IntToString(iCurrent));
int iCards = d20();
string sCard = (IntToString(iCurrent) + "cards");
SetLocalInt(OBJECT_SELF, sCard, iCards);
SpeakString(sPC + " is bust. " + sCurrent + " shows " + IntToString(iCards) + ". What would you like to do?");
}
}
else
{
SpeakString("It is still " + sPCTalker + "'s turn.");
}
}
if ((iHeard == 4002) && (iStarted == 1))
{
string sPCTalker = GetLocalString(OBJECT_SELF, IntToString(iCurrent));
if (sPC == sPCTalker)
{
int iHisCard = GetLocalInt(OBJECT_SELF, (IntToString(iCurrent) + "cards"));
int iHighOwner = GetLocalInt(OBJECT_SELF, "high");
int iHighCard = GetLocalInt(OBJECT_SELF, (IntToString(iHighOwner) + "cards"));
if ((iHisCard >= iHighOwner) && (iHisCard <= 21))
{
SetLocalInt(OBJECT_SELF, "high", iCurrent);
}
if (iHisCard > 21)
{
SpeakString("Player " + sCurrent + " is bust.");
}
if (iCurrent == iCount)
{
int iHigh = GetLocalInt(OBJECT_SELF, "high");
object oHigh = GetLocalObject(OBJECT_SELF, "object" + IntToString(iHigh));
GiveGoldToCreature(oHigh, (iCount * 50));
string sHighName = GetLocalString(OBJECT_SELF, IntToString(iHigh));
SpeakString(sHighName + " has won " + IntToString(iCount * 50) + " gold. Talk to me if you want to play again.");
ExecuteScript("blackjackstop", OBJECT_SELF);
}
if (iCurrent < iCount)
{
iCurrent = (iCurrent + 1);
SetLocalInt(OBJECT_SELF, "current", iCurrent);
string sCurrent = GetLocalString(OBJECT_SELF, IntToString(iCurrent));
int iCards = d20();
string sCard = (IntToString(iCurrent) + "cards");
SetLocalInt(OBJECT_SELF, sCard, iCards);
SpeakString(sCurrent + " shows " + IntToString(iCards) + ". What would you like to do?");
}
}
}
if ((iHeard == 4005) && (iStarted == 0))
{
SetLocalInt(OBJECT_SELF, "started", 1);
SpeakString("A game of Blackjack has begun.");
}
}
Code: Select all
void main()
{
SetListening(OBJECT_SELF, TRUE);
SetListenPattern(OBJECT_SELF, "hit", 4001);
SetListenPattern(OBJECT_SELF, "stay", 4002);
SetListenPattern(OBJECT_SELF, "player", 4003);
SetListenPattern(OBJECT_SELF, "begin", 4004);
SetListenPattern(OBJECT_SELF, "start", 4005);
}
How to Talk to Trained Blackjack Dealers
To start a game, say "start".
Once the game has begun, every player must then say "player" to register. It costs each player 50 gold to play.
When all players are registered, you must say "begin" to begin.
The purpose of Blackjack is to get the closest to 21 without going over.
If you want to add to your total, say "hit".
If you want to keep what you have, say "stay".
It's a lot more code then I remember... but it does work! Oh, and I never got around to putting in a stop command, was probably to avoid an exploit but if you feel confident, go for it!
- Pitched Black