BioWare Forums: View Post For Code Display


You are viewing a single post. Please do not take this post out of context.
Read the full topic: Post Working Scripts Here

Author Sticky: Post Working Scripts Here
Severun Posted: Saturday, 20 July 02:05AM
Script Name: npc_escort_user 1.0

What It Does: Allows you to have NPC's that want to be escorted to a waypoint. Once they get there they will reward the player, then run off and dissapear. This also supports multiple Areas, and glues to the PC that accepted the quest (Not the nearest PC as in the original).


Notes: Be sure to check the comments, this is the main script, but you have to cut and paste several other short scripts from the comments that become part of your conversation tree on your NPC (Don't forget to remove those //:: things before saving and compiling) =:)

Aside from that, you scripters are Uber Geeks, I love you all and just wanted to post this little tidbit to give back some Love..

NWScript:
//::
//:: Escort by player
//::
//:: npc_escort_user.nss
//::
//:: By Severun July 19, 2002
//::
//:: Copyright (c) 2002 All You Groovy NWN Scripters
//:: go on take it!! I've used all yours.
//:://////////////////////////////////////////////
//::
//:: Follows player.  If gets close to a waypoint
//:: named E_WAY_ then says thank you text
//:: and escapes area.
//::
//:://////////////////////////////////////////////
//::
//::  So I copied the original  NW_C3_Escort1.nss and
//:: after looking at it a bit, it seemed like it wouldn't
//:: work across areas.  It also was doing a GetNearestPC
//:: When it was deciding who to follow.  So anyway here
//:: is the hack/slash/rewrite.  It follows whoever said
//:: Would take them and it works across areas.  To Install
//:: Do the following:
//::
//::  1. Place an NPC Creature then right click, get properties and
//::     uncomment the  SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);
//::  2. Get the tag of your NPC from their properties and create
//::     a waypoint that will be the NPC's destination.
//::  3. Click on the properties of the waypoint and name the tag
//::     E_WAY_NpcTagName.  So if the tag on your NPC is foo then
//::     you would name your waypoint E_WAY_foo (yes case sensitive).
//::  4. Place this script in the OnUser script for your NPC
//::  5. Create a conversation script that looks something like this
//::     at the top level:
//::
//::     a) I am so glad I am here
//::     b) Thanks for taking me here is your reward.
//::     c) Is there a problem?  (This appears when in transit)
//::     d) I need to go to fooland will you take me?  (This appears before accepting)
//::
//::  Definitions
//::  -----------
//::  a) What NPC says when they have arrived and have awarded
//::  b) What NPC says when they are rewarding.
//::  c) What NPC says after quest accepted but before arrival
//::  d) What NPC says before quest has been accepted.
//::
//::  6. In your conversation script for a) add the following script
//::  to Text Appears When:
//::
//::  int StartingConditional()
//::  {
//::
//::    // Inspect local variables
//::    if(!(GetLocalInt(OBJECT_SELF, "EscStatus") == 40))
//::        return FALSE;
//::
//::    return TRUE;
//::  }
//:: 7. Then do the same thing for b and c, except
//:: on b) 40 changes to 30 c) 40 changes to 10.
//::
//:: 8. Now that you have that done.  In your conversation,
//:: wherever you want to have the PC start the quest add
//:: The following to Actions Taken
//::
//::
//::  void main()
//::  {
//::     // Set the variables
//::    SetLocalInt(OBJECT_SELF, "EscStatus", 10);
//::    SetLocalObject(OBJECT_SELF, "MyEscort",GetPCSpeaker());
//::
//::  }
//::
//:: 9. If you want to stop the quest, i.e. they said go away Add
//:: the following to your actions taken for the PC response.
//::
//::  void main()
//::  {
//::    // Set the variables
//::    SetLocalInt(OBJECT_SELF, "EscStatus", 0);
//::
//::  }
//::
//::  The NPC will then wait where they are for someone else to
//::  take them.
//::
//:: 10. The last thing (promise) is to add the following code to
//:: The Actions Taken part of what the NPC says for b)to reward
//:: the PC then run off into the night.
//::
//:: #include "nw_i0_tool"
//::
//:: void main()
//:: {
//::    // Give the speaker some gold
//::    GiveGoldToCreature(GetPCSpeaker(), 5000);
//::
//::    // Give the party some XP
//::    RewardPartyXP(2000, GetPCSpeaker());
//::
//::    // Now set the quest as done on the char
//::    SetLocalInt(OBJECT_SELF,"EscStatus",40);
//::    // Now run away! run away! mooooooo! plunk!
//::    // *cow flies over the wall and lands on NPC*
//::    // (Not really but it would be cool huh?)
//::    ActionMoveAwayFromObject(GetPCSpeaker(),TRUE,50.0);
//::    DestroyObject(OBJECT_SELF,4.0);
//::  }
//::
//::
//::
//:: Enjoy all.  This was originally from Brent
//:: On: May 16, 2001  I found it on a script site
//:: It's basically a complete re-write though.  You
//:: Also could extend this to do lots of things.
//:: some ideas would be, after a certain amount of time
//:: the NPC attacks the PC. *evil grin*.  You could also
//:: add things so that when you pass a certain waypoint the
//:: PC says or does something, i.e. you go to a dungeon
//:: and the NPC says I'm scared and runs away. stuff like that.
//:: Feel free to cut/paste/glue
//::
//::
//:://////////////////////////////////////////////
// #include "NW_I0_PLOT"
void main()
{
    int nUser = GetUserDefinedEventNumber();
    // enter desired behaviour here
    if(nUser == 1001) //HEARTBEAT EVENT
    {
        ClearAllActions();
        // First Let's see if we even have an escort
        int iEscStatus = GetLocalInt(OBJECT_SELF,"EscStatus");
        // SpeakString(IntToString(iEscStatus));
        // No sense in going any further if we don't have an escort
        if (iEscStatus > 0)
        {
            // OK we have an escort, let's get who he is
            object oMyEscort = GetLocalObject(OBJECT_SELF,"MyEscort");
            // Make sure the object is still valid, if not just return
            if(!(GetIsObjectValid(oMyEscort)== TRUE)) {
                SetLocalInt(OBJECT_SELF,"EscStatus",0);
                return;
            }
            // Mom.. Dad.. Are we there yet?
            float fDistance = GetDistanceToObject(GetNearestObjectByTag("E_WAY_"+GetTag(OBJECT_SELF)));
            // SpeakString("I am "+FloatToString(fDistance)+" Away");
            if ((fDistance < 10.0)&& (iEscStatus == 10) && (fDistance > -1.0))
            {   // Set int to the thanks and reward conversation starts
                SetLocalInt(OBJECT_SELF,"EscStatus",30);
                ActionStartConversation(oMyEscort);
                // SetLocalInt(OBJECT_SELF,"EscStatus",40);
                 // No kids we're not there yet
            } else {
                // * follow, if players accepted
                // First see if player object is valid, if not they
                // Disconnected, or went to another area.  If they went
                // To anoter area then we have to Jump to them.
                if ((GetLocalInt(OBJECT_SELF,"EscStatus") == 10))
                {
                    float fEscDist= GetDistanceToObject(oMyEscort);
                    // Run to PC if too far away
                    if(fEscDist > 4.0){
                        ActionMoveToObject(oMyEscort,TRUE,1.0);
                    }
                    if(fEscDist < 0.0) {
                    // Must be in another area
                        location lMyEscort = GetLocation(oMyEscort);
                        ClearAllActions();
                        JumpToLocation(lMyEscort);
                    }
                }
            }
        } // End if iEscStatus > 0
    }  // End Event 1001 (Heartbeat)
} // End Main

This post taken from the BioWare Forums
Powered by BioBoards Version 2.05.010
Please read our Copyright and Trademark Information