Author Topic: NPC and other script help  (Read 311 times)

Legacy_Universal Pagan

  • Newbie
  • *
  • Posts: 23
  • Karma: +0/-0
NPC and other script help
« on: June 05, 2011, 10:53:57 pm »


               I am not a scripter unfortunatly. Wish I was hehe. But I do have a basic understanding of it tho. I am not able to start from scratch but can edit them as long as there are good comments in the script. Enough of that. '<img'>


My idea is to have something like an animal and or other NPC not be hostle until the pc gets within a certain distance. The distance would be fairly close like within just a few feet. But before going hostle tho, I am thinking that the NPC and or animal would give off a warning or something like that. Bear growl, guy saying get away from me or else. Things like that. I know the script would go in the On Precieved Spot or User Spot but have no clue how to even start this. Maybe I could study the Lexicon and other scripts some more but do not have a whole lot of time hehe.

Thanks in advance for any help.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
NPC and other script help
« Reply #1 on: June 06, 2011, 05:59:00 am »


               The OnPerception distance is too great for what you are asking (a few feet). And it only fires once per perception. The player would have to get far away from the creature and then go back into it's perception field again.

This is something that you will want to fire using the creatures OnHeartbeat event.

I made this for NPCs. You could use it or a modified version of it:

#include "nw_i0_generic"
void main()
{
    object oSelf   = OBJECT_SELF;
    location lSelf = GetLocation(oSelf);
    object oThreat = GetFirstObjectInShape(SHAPE_SPHERE, 3.0, lSelf, TRUE, OBJECT_TYPE_CREATURE);
    string sThreat = GetName(oThreat);
    int iWarned    = GetLocalInt(oSelf, sThreat + "WARNED");
    string sSay;
    switch (Random(4))
    {
        case 0: sSay = "Get away from me" ;break;
        case 1: sSay = "Leave me alone"   ;break;
        case 2: sSay = "Go away"          ;break;
        case 3: sSay = "Leave me be"      ;break;
    }

    if (GetIsObjectValid(oThreat) && GetIsPC(oThreat) && !GetIsDead(oThreat))
    {
        if (!iWarned)
        {
            SpeakString(sSay + ".");
            SetLocalInt(oSelf, sThreat + "WARNED", 1);
        }

        else if (iWarned == 1)
        {
            SpeakString("I'm warning you. " + sSay + ".");
            SetLocalInt(oSelf, sThreat + "WARNED", iWarned + 1);
        }

        else if (iWarned == 2)
        {
            SpeakString("I'm not going to tell you again! " + sSay + "!");
            SetLocalInt(oSelf, sThreat + "WARNED", iWarned + 1);
        }

        else if (iWarned > 2)
        {
            DetermineCombatRound(oThreat);
        }
    }

    ExecuteScript("nw_c2_default1", oSelf);
}


It gives the player 3 warnings(and I made the creature's warnings a bit random). After that it will turn hostile and attack. It also remembers each player who gets to close and how many warnings the player has had. So if the player backs off and then comes back later it will continue with the warnings or attack if the player already had his 3 warnings, etc..  The player that is the closest to the creature will be it's current threat

If you need to modify it in any way just ask.

Hope it helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 06 juin 2011 - 05:07 .
                     
                  


            

Legacy_Universal Pagan

  • Newbie
  • *
  • Posts: 23
  • Karma: +0/-0
NPC and other script help
« Reply #2 on: June 06, 2011, 12:52:17 pm »


               Very helpful. Thanks very much Ghost of God.
               
               

               
            

Legacy_Universal Pagan

  • Newbie
  • *
  • Posts: 23
  • Karma: +0/-0
NPC and other script help
« Reply #3 on: June 06, 2011, 12:54:15 pm »


               I will be making two copies of this. One for NPC's and one for animals replacing the get away string with gerrrrr or rawrrrrr or something hehe.