Author Sticky: Post Working Scripts Here
Irritatus Posted: Thursday, 27 June 12:04AM
Hi all, here is my first script, I haven't read the docs's yet, so if you improve it, let me know!

Script Name: CowardlyCrier

What it does: a crier that spouts random nay sayer phrases on perceiving the PC's, walks around randomly, and flees from attacks with random retorts.

Notes: Three functions. All intended to be dropped into the OnUserDefined event.

sorry for the oddnaming, my pile of words is low today 

NWScript:
float fCrierDelay=8.0f; //time crier faces PC's and waits before

                        //walking around again.

int nAttackRepMod=-2;   //Reputation penalty for atacking this Crier

string xGetNaySayerCry()

{

/**********************************************************************/

/* Script Name:     xGetNaySayerCry()

/* Copyright (c) 2001 Bioware Corp.

/*

/* Created By:      Irritatus Maximus

/* Created On:      6/27/02

/* Last Modified:   6/27/02

/*

/* What it does:

/*

/* Returns a random nay sayer string, like "we're all doomed!"

/*

/* Inputs:

/*  None

/*

/* Returns:

/*  string

/*

/**********************************************************************/



    string sCryString;

    int nRandNum=d6(1);

        switch(nRandNum){

            case 1:

                sCryString="We're All Doomed!";

            break;

            case 2:

                sCryString="The End is Near";

            break;

            case 3:

                sCryString="Repent now sinners! Judgement Awaits!";

            break;

            case 4:

                sCryString="Bewared the Beast of Reckoning!";

            break;

            case 5:

                sCryString="The Dark Queen approaches!";

            break;

            default:

                sCryString="Run Henny Penny, Run!  The sky is falling";

            break;

        }//end switch



    return sCryString;

}



string xGetHelpCry()

{

/**********************************************************************/

/* Script Name:     xGetHelpCry()

/* Copyright (c) 2001 Bioware Corp.

/*

/* Created By:      Irritatus Maximus

/* Created On:      6/27/02

/* Last Modified:   6/27/02

/*

/* What it does:

/*

/* Returns a random help retort, like "I fart in you're general direction!"

/*

/*

/* Inputs:

/*      None

/*

/* Returns:

/*      string

/*

/**********************************************************************/

    string sHelpCry;

    int nRand=d6(1);

    switch(nRand){

        case 1:

            sHelpCry="Help I'm being repressed";

        break;

        case 2:

            sHelpCry="I Fart in your general direction";

        break;

        case 3:

            sHelpCry="You cowardly bastard!";

        break;

        case 4:

            sHelpCry="The better part of valor...";

        break;

        case 5:

            sHelpCry="Na Na Na Na Na, you can't catch me!";

        break;

        default:

            sHelpCry="OW";

        break;

       }//end switch



    return sHelpCry;

}

void main()

{

/**********************************************************************/

/* Script Name:     CowardlyCrier

/* Copyright (c) 2001 Bioware Corp.

/*

/* Created By:      Irritatus Maximus

/* Created On:      6/26/02

/* Last Modified:   6/27/02

/*

/* What it does:

/*    This is a generic town crier, who wanders around an area and

/*    shout's out something specific.  In my version he is used to

/*    tell the PC's about my area that, so he is just trying to get

/*    their attention.  I have added a section for randomized "crys"

/*    which is commented out, since I don't want that.

/*    - Additionally, if he is attacked, he will try to flee

/*    shouting for "help" as well as a random retort I put in for fun.

/*    - Finally, the players reputation is affected should they attack

/*    the crier. The reputation effect, if any is based on the chance that

/*    the attack was noticed, which is affected by day/night.  I have a 100%

/*    chance the attack is seen in the day, since this crier is used in very

/*    busy areas, like markets and city gates.  At night I have it to 40%.

/*

/*

/* Notes:

/*  Uses:xGetNaySayerCry(),xGetHelpCry()

/*

/*  The script is used in the OnUserDefined event.

/*  The following flags need to be "uncommented" in the custom OnSpawn event:

/*  HEARTBEAT, ATTACK, and PERCEIVE.

/*

/*  I would also include a variable in each area, and use that to

/*  detmine the penalty to reputation, for example, if an area is a

/*  law abiding town, a penalty of 10, if it is a seedy hot-bed of

/*  bad guys, maybe the penalty would be none?

/*

/**********************************************************************/

    int nUser = GetUserDefinedEventNumber();

    object oCreature;

    int nSeen;

    if(nUser == 1001) //HEARTBEAT

    {

        /* If not trying to flag a PC, walk around */

        ActionRandomWalk();

    }//end if heartbeat

    else if(nUser == 1002) //PERCEIVE

    {

        oCreature = GetLastPerceived();

        /* Check to see if I actually saw a PC */

        if ((GetLastPerceptionSeen()) && (GetIsPC(oCreature)))

        {

            /* Turn to face the PC */

            SetFacingPoint(GetPosition(oCreature));

            SpeakString(xGetNaySayerCry(),TALKVOLUME_SHOUT);

            

            /* Stop walking around to give the PC's time to talk t to you */

            ClearAllActions();

            ActionWait(fCrierDelay);

        }//end if PC

    }//end if PERCEIVE

    else if(nUser == 1005) //ATTACKED

    {

        /* Negatively affect PC's Reputation for attacking a commoner */



        oCreature=GetLastAttacker(OBJECT_SELF);

        /* If dark out, attack possible not seen */

        if((GetIsNight()) || (GetIsDusk()) )

        {

            /* 40% chance it was seen in the dark */

            SetLocalInt(OBJECT_SELF,"nSeen",(d10(1)<5));

        }//end if dark out

        else

        {

            SetLocalInt(OBJECT_SELF,"nSeen",1);

        }//end else

        if(GetLocalInt(OBJECT_SELF,"nSeen")==1)

        {

            /* They were caught, bookem Dano */

            AdjustReputation(oCreature,OBJECT_SELF,nAttackRepMod);

        }//end If nSeen

        /* Set up a random retort to being attacked */

        string sRandomString=xGetHelpCry();

        SpeakString("Help I'm being repressed!!",TALKVOLUME_SHOUT);

        /* Run Away */

        ActionMoveAwayFromLocation(GetLocation(OBJECT_SELF),TRUE,40.0f);

        /* Say something while running, in theory */

        DelayCommand(2.0f,SpeakString(sRandomString,TALKVOLUME_SHOUT));

    }



    return;

}//end main