Author Sticky: Post Working Scripts Here
Luminous Posted: Thursday, 25 July 11:34PM
1. Bones Gambling Script
2. This is a simple gambling game initiated through a conversation with an NPC. The rules are such that the player bets a set amount (defined through the conversation and set through SetLocalInt("BonesWager", #). The NPC rolls 2 dice and the PC has to match the number to win. The payout is 3x the wager amount. The script is attached as an Actions Taken after the wager is placed.

NWScript:
//::///////////////////////////////////////////////

//:: Name Bones Gambling Script

//:: FileName opt_bones

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

*/

//:://////////////////////////////////////////////

//:: Created By: Sean D. Francis

//:: Created On: July 24, 2002

//:://////////////////////////////////////////////

void main()

{

    //Get the gambler

    object oPC = GetPCSpeaker();

    int nPCwin = 0;

    //How much did the gambler opt to wager?

    int nWager = GetLocalInt(oPC, "BonesWager");

    //How much will the gambler win?

    int nWinnings = (nWager*3);

    int nGold = GetGold(oPC);

    if (nGold - nWager >= 0)

 {

   //The dice are rolled and the numbers announced.

    int nNPCROLL = (Random(5)+1)+(Random(5)+1);

ActionSpeakString("I rolled a " + IntToString(nNPCROLL), TALKVOLUME_TALK);

    int nPCROLL = (Random(5)+1)+(Random(5)+1);

DelayCommand (2.0, ActionSpeakString("You rolled a " + IntToString(nPCROLL), TALKVOLUME_TALK));

    //Did the gambler win?

if (nNPCROLL == nPCROLL)

    {

DelayCommand (2.0, ActionSpeakString("You win " + IntToString(nWinnings) + " gold pieces!", TALKVOLUME_TALK));

DelayCommand (2.5, GiveGoldToCreature(oPC, nWinnings));

    }

else

{

DelayCommand (2.0, ActionSpeakString("You lose", TALKVOLUME_TALK));

DelayCommand (2.5, TakeGoldFromCreature(nWager, oPC, TRUE));

}

}

else

 {

  ActionSpeakString("You don't have enough gold.");

 }

}



There are variations that can be added, I believe, like allowing a Dex check to help influence the outcome. I'm trying to design a House of Games and am even thinking about having 'loaded dice' in the game that could be used during this game. I'm not sure how to fully implement them, though.

If you use it or modify it, I would like to know. Actual credit isn't necessary as it isn't that original of a script.

sdf2008@stygianlabyrinth.net