BlackJack Script

Moderator: Event DM

Post Reply
pitched_black
Prince of Bloated Discourse
Posts: 186
Joined: Thu Feb 06, 2003 8:49 pm
Location: Nova Scotia (GMT - 4)

BlackJack Script

Post by pitched_black » Tue Sep 30, 2003 9:55 pm

Thought it was about time I posted something in here. I chose to put up my blackjack script because it's the most useful thing I have in the mod right now.

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.");
    }
}
BlackJack Dealer (same NPC) OnSpawn:

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);
}
Also might help to put this into the description of a nearby placeable (that isn't static):
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
The Island(s) of Hala
http://www.hala-world.org
User avatar
Neve
Prince of Bloated Discourse
Posts: 192
Joined: Mon Apr 14, 2003 4:09 pm
Location: The Netherlands
Contact:

Post by Neve » Wed Oct 01, 2003 8:01 am

Cool ! I'll give it a go as soon as I get home. Thanks for sharing :D
- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
Post Reply