Author Sticky: Post Working Scripts Here
Nos-NR Posted: Sunday, 28 July 10:19PM
1. Script Name: Super Traffic Light Slot Machine
(MEANT TO BE TRAFIC LIGHTS )
2. What it does: Basically a really cool visual slot machine that can be placed in a pub or a casino or something. You place a lever, and 3 white lights, and gamble away. 25 GP a go, read the file notes for prizes/pitfalls.

3. Notes: Place a lever, and 3 white vertical light effects in desired places. Edit the tags to be inline with the code.

4. The Script itself: ENJOY

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

//:: Name      Traffic Lights Slot Machine

//:: FileName

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

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

/*

    This script will utilise 3 placed light rays, and a pull handle.

    The script will payout on 3 sucessfull matching lights a reward/

    or punishment. Make the lever "useable", and place this script in

    the used section.

        For 3 Green's, you will either get the Jackpot(Gain a level,

    and recieve 500k GP), or a Half Jackpot(3000 XP, 50000 GP), and

    a Win(500 XP).

        For 3 Yellow's a cash payout of 20000 GP.

        For 3 Red's you will either get Death(a nice choice of 3

    deaths, or a percentage loss of GP, calculated on the players

    stash.

    The game costs 25GP ago, as it gives quality prizes :) 

#################### Probability Tables ############################

        - All Green:

                          **JACKPOT**| (1/27) * (1/6) = (1/162)

                         HALF JACKPOT| (1/27) * (2/6) = (1/81)

                                  WIN| (1/27) * (3/6) = (1/54)

        - All Yellow:

                          CASH PAYOUT| (1/27)

        - All Red:

                                DEATH| (1/27) * (1/2) = (1/54)

                 PERCENTAGE CASH LOSS| (1/27) * (1/2) = (1/54)

* N.B My maths is *** so if the Probability is not sound don't windge.

####################################################################

*/

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

//:: Created By:    Sebastian Patten (s.patten@uea.ac.uk)

//:: Created On:    22/07/2002

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

void main()

{

    object oSlotLight1;

    object oSlotLight2;

    object oSlotLight3;

    object oPc = GetLastUsedBy();

    location lLever = GetLocation(OBJECT_SELF);

    location lSlotLight1;

    location lSlotLight2;

    location lSlotLight3;

    int j = 1;

    int randomNumber1 = Random(3);

    int randomNumber2 = Random(3);

    int randomNumber3 = Random(3);

    int randomDeath = Random(3);

    int validPlayer;

    int percentToTake = 10;

    int amountToGive = 20000;

    int gameCost = 25;



    if(GetIsObjectValid(oPc) == TRUE)

    {

        if(GetIsDead(oPc) == FALSE)

        {

            validPlayer = TRUE;

        }

    }

    if((GetGold(oPc) >= gameCost) && (validPlayer == TRUE))

    {

        TakeGoldFromCreature(gameCost, oPc, TRUE);

        object oObject = GetFirstObjectInShape(SHAPE_SPHERE, 30.0, lLever, FALSE, OBJECT_TYPE_PLACEABLE);

        while(oObject != OBJECT_INVALID)

        {

            if(GetTag(oObject) == "plc_solwhite" ||

               GetTag(oObject) == "Shaft of Light - Red" ||

               GetTag(oObject) == "Shaft of Light - Yellow" ||

               GetTag(oObject) == "Shaft of Light - Green")

            {

                switch(j)

                {

                    case 1:

                    {

                        oSlotLight1 = oObject;

                        lSlotLight1 = GetLocation(oSlotLight1);

                        break;

                    }

                    case 2:

                    {

                        oSlotLight2 = oObject;

                        lSlotLight2 = GetLocation(oSlotLight2);

                        break;

                    }

                    case 3:

                    {

                        oSlotLight3 = oObject;

                        lSlotLight3 = GetLocation(oSlotLight3);

                        break;

                    }

                }

                j++;

            }

            oObject = GetNextObjectInShape(SHAPE_SPHERE, 30.0, lLever, FALSE, OBJECT_TYPE_PLACEABLE);

        }

        switch(randomNumber1)

        {

            case 0:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight1, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solred", lSlotLight1, FALSE);

                break;

            }

            case 1:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight1, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solyellow", lSlotLight1, FALSE);

                break;

            }

            case 2:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight1, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solgreen", lSlotLight1, FALSE);

                break;

            }

        }

        switch(randomNumber2)

        {

            case 0:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight2, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solred", lSlotLight2, FALSE);

                break;

            }

            case 1:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight2, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solyellow", lSlotLight2, FALSE);

                break;

            }

            case 2:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight2, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solgreen", lSlotLight2, FALSE);

                break;

            }

        }

        switch(randomNumber3)

        {

            case 0:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight3, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solred", lSlotLight3, FALSE);

                break;

            }

            case 1:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight3, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solyellow", lSlotLight3, FALSE);

                break;

            }

            case 2:

            {

                PlaySound("as_cv_bell1");

                DestroyObject(oSlotLight3, 0.0);

                CreateObject(OBJECT_TYPE_PLACEABLE, "plc_solgreen", lSlotLight3, FALSE);

                break;

            }

        }

        if(validPlayer == TRUE)

        {

            // Outcomes from the machine

            // Death

            if(((randomNumber1 == 0) && (randomNumber2 == 0) && (randomNumber3 == 0)))

            {

                // 50/50 Chance of Dying, or loosing n% money once 3 red lights occur

                if(Random(2) == 1)

                {

                    int deathOutcome;

                    AssignCommand(OBJECT_SELF, ActionSpeakString("Fool! Never look a gifthorse in the mouth!", 5));

                    switch(randomDeath)

                    {

                        case 0:

                        {

                            deathOutcome = VFX_IMP_SPIKE_TRAP;

                            break;

                        }

                        case 1:

                        {

                            deathOutcome = VFX_IMP_SONIC;

                            break;

                        }

                        case 2:

                        {

                            deathOutcome = VFX_IMP_SUNSTRIKE;

                            break;

                        }

                    }

                    effect death = EffectVisualEffect(deathOutcome);

                    ApplyEffectToObject(2, death, oPc, 2.0);

                    ApplyEffectToObject(5, EffectDeath(TRUE, TRUE), oPc);

                }

                else

                {

                    AssignCommand(OBJECT_SELF, ActionSpeakString("Sorry, you have lost GP", 5));

                    int pcGold = GetGold(oPc);

                    int amountToTake = ((pcGold / 100) * percentToTake);

                    TakeGoldFromCreature(amountToTake, oPc, TRUE);

                }

            }

            // Money

            else if(((randomNumber1 == 1) && (randomNumber2 == 1) && (randomNumber3 == 1)))

            {

                AssignCommand(OBJECT_SELF, ActionSpeakString("Congratulations! You have won some GP!", 5));

                GiveGoldToCreature(oPc, amountToGive);

            }

            // Level / Jackpot :D 

            else if(((randomNumber1 == 2) && (randomNumber2 == 2) && (randomNumber3 == 2)))

            {

                int randomVar = d6();

                if(randomVar == 6)

                {

                    AssignCommand(OBJECT_SELF, ActionSpeakString("Congratulations! You have earnt a level up!", 5));

                    int playerXP = GetXP(oPc);

                    if(playerXP < 100) GiveXPToCreature(oPc, (100 - playerXP));

                    else if(playerXP < 900) GiveXPToCreature(oPc, (900 - playerXP));

                    else if(playerXP < 2700) GiveXPToCreature(oPc, (2700 - playerXP));

                    else if(playerXP < 5400) GiveXPToCreature(oPc, (5400 - playerXP));

                    else if(playerXP < 9000) GiveXPToCreature(oPc, (9000 - playerXP));

                    else if(playerXP < 13000) GiveXPToCreature(oPc, (13000 - playerXP));

                    else if(playerXP < 19000) GiveXPToCreature(oPc, (19000 - playerXP));

                    else if(playerXP < 27000) GiveXPToCreature(oPc, (27000 - playerXP));

                    else if(playerXP < 36000) GiveXPToCreature(oPc, (36000 - playerXP));

                    else if(playerXP < 49000) GiveXPToCreature(oPc, (49000 - playerXP));

                    else if(playerXP < 66000) GiveXPToCreature(oPc, (66000 - playerXP));

                    else if(playerXP < 99000) GiveXPToCreature(oPc, (99000 - playerXP));

                    else if(playerXP < 150000) GiveXPToCreature(oPc, (150000 - playerXP));

                    else if(playerXP < 200000) GiveXPToCreature(oPc, (200000 - playerXP));

                    else if(playerXP < 260000) GiveXPToCreature(oPc, (260000 - playerXP));

                    else if(playerXP < 340000) GiveXPToCreature(oPc, (340000 - playerXP));

                    else if(playerXP < 440000) GiveXPToCreature(oPc, (440000 - playerXP));

                    else if(playerXP < 580000) GiveXPToCreature(oPc, (580000 - playerXP));

                    else if(playerXP < 760000) GiveXPToCreature(oPc, (760000 - playerXP));

                    GiveGoldToCreature(oPc, 500000);

                }

                else if(randomVar < 6 && randomVar > 3)

                {

                    AssignCommand(OBJECT_SELF, ActionSpeakString("Congratulations! You have earnt 3000 XP Points!", 5));

                    GiveXPToCreature(oPc, 1000);

                    GiveGoldToCreature(oPc, 50000);

                }

                else if(randomVar < 4 && randomVar > 0)

                {

                    AssignCommand(OBJECT_SELF, ActionSpeakString("Congratulations! You have earnt 500 XP Points!", 5));

                    GiveXPToCreature(oPc, 500);

                }

            }

        }

    }

}