Author Topic: multiple spawns from a trigger...  (Read 310 times)

Legacy_diggerplus

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
multiple spawns from a trigger...
« on: July 10, 2014, 02:04:31 am »


               

so i found a script called TOD_encounters on the vault a while back, added it in to my mod and used it for a second till i realized it wasn't what i wanted.


 


it does the whole 4 times of the day thing that i want, but the spawns the trigger produces all come from the same spot, never changes, always from the furthest south corner.


 


so i was wondering if it was possible to make the following script not rely on encounter triggers and instead spawn say at a distance of 10-15 meters/feet/measurement of some kind around the PC that entered the trigger?


 


also keeping in mind that once it's triggered it deactivates for say 900 seconds so any party members don't spawn more upon entering the same trigger.


 


script:


 


// TOD Encounter Trigger

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

// This script enables you to use a trigger to make an encounter spawn only during

// a specific time of day (TOD). There are four time periods used: dawn, day, dusk,

// and night. You can specify any combination of those four TODs on the trigger to

// tell it when you want the encounter to spawn. To use this, all your encounters

// must have different tags. You can, however have two or more TOD triggers

// associated with the same encounter by giving them all the same tag.

// Typically what you do is place your encounter down on the map, then place a TOD

// trigger down so that it completely overlaps the encounter trigger with a little

// space to spare all the way around it. You place it so that there is no way to

// get to the encounter trigger without first going through the TOD trigger. The

// TOD trigger will activate and deactivate the encounter trigger based on the time

// of day. Note that the encounter trigger is still the one used to determine if

// the spawn should occur when the encounter is active. A player must walk onto the

// encounter trigger just as he would without the TOD trigger.

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

// Triggers are associated with an encounter object by thier tag names.

// The trigger tag = "TOD_" +TagOfEncounter

// If you have an encounter with a tag "myEncounter" then you can associate a

// TOD Encounter Trigger to it by making the trigger's tag be "TOD_myEncounter"

// and placing this script into the trigger's OnEnter event.

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

// Putting this script into the OnEnter script of a trigger will turn that trigger

// into a TOD Encounter Trigger. Set up the tag names of the trigger and some

// encounter you want to associate with the trigger as described above. Then enter

// the TOD Spawn code into the KeyTag field in the Advanced tab of the properties

// screen of the trigger. The first 4 letters of this key will be used as the code

// and the rest of the key tag will be ignored.

// TOD Spawn Code format is 4 letters:

//   1st letter is Dawn  - "S" = spawn at dawn, "N" = don't spawn at dawn.

//   2nd letter is Day   - "S" = spawn at day, "N" = don't spawn at day.

//   3rd letter is Dusk  - "S" = spawn at dusk, "N" = don't spawn at dusk.

//   4th letter is Night - "S" = spawn at night, "N" = don't spawn at night.

// Examples: NNSS = spawn at dusk and night, don't spawn at dawn or daytime.

//           nSnn = spawn during day only.

//           S_S_ = spawn at dusk and dawn only.

// Note you can use any letter instead of "N" to disable spawns during that

// time of day, but if you use "S" or "s" you will enable spawning.

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

// Note thet if the trigger's tag does not match up with any encounter correctly

// or if the keytag entered into the trigger is less than 4 letters long, the

// trigger will do nothing at all to the encounter.

// Note also that only the first four letters of the KeyTag field are used for the

// TOD code so you can still use the rest of the KeyTag field for your own purposes

// as long as you remember the first four letters will be used to determine the

// time of day code.

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

// The faction of the trigger should be set to match the faction of the encounter.

// You can play with the Faction setting of the trigger to get one type of creature

// to set them off but if its different than the encounter its not clear if the

// spawns will happen outside the specified time restrictions. I suspect that will

// happen sometimes depending on what the two factions are and how they relate to

// each other and how they relate to NPCs or PCs.

//

// These triggers work when any creature (NPC or PC) walks over them even if the

// encounter trigger doesn't fire.

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

 

 

 

// Trigger OnEnter script main function

void main()

{ // Get the tag name of this trigger.

  string sEncounter = GetTag( OBJECT_SELF);

 

  // If its not a Time Of Day Trigger return.

  if( GetStringLeft( sEncounter, 4) != "TOD_") return;

 

  // Find the associated encounter, return if not found.

  sEncounter = GetStringRight( sEncounter, GetStringLength( sEncounter) -4);

  object oEncounter = GetObjectByTag( sEncounter);

  if( !GetIsObjectValid( oEncounter)) return;

 

  // Get the TOD spawn code from the trigger key and validate it.

  string sKey = GetLockKeyTag( OBJECT_SELF);

  if( GetStringLength( sKey) < 4) return; // Key specified wrong.

 

  // This flag will be used to determine if the encounter should be active at

  // the time of day when the trigger was entered.

  int bActivate = FALSE;

 

  // Activate if its a dawn trigger and time of day is dawn.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDawn());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a day trigger and time of day is day.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDay());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a dusk trigger and time of day is dusk.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDusk());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a night trigger and time of day is night.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsNight());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // If this encounter has never been triggered before, initialize it and make sure

  // its activation state is correct. Activation state is stored in a variable on the

  // encounter object. It is an integer and can have 3 possible values, -1/0/1. If

  // it is zero, the encounter has never been entered or triggered. If it is -1, the

  // encounter has been set to be active. If it is 1, the encounter has been set to

  // disabled.

  if( GetLocalInt( oEncounter, "TOD_Deactivated") == 0)

  { SetLocalInt( oEncounter, "TOD_Deactivated", (bActivate ? -1 : 1));

    SetEncounterActive( bActivate, oEncounter);

    return;

  }

 

  // Activate or deactivate the encounter object as necessary based on its current

  // state and the time of day.

  int iDeactivated = GetLocalInt( oEncounter, "TOD_Deactivated"); // Get current state.

  if( (iDeactivated == 1) && bActivate)

  { // The encounter is deactivated and it should be active, so activate it.

    SetEncounterActive( TRUE, oEncounter);

    SetLocalInt( oEncounter, "TOD_Deactivated", -1);

  }

  else if( (iDeactivated == 1) && !bActivate)

  { // The encounter is deactivated as it should be at this time of day.

    if( GetEncounterActive( oEncounter))

    { // But the encounter object seems to have reactivated itself, or there is

      // a battle in progress. Thats ok, we can just make sure its deactivated.

      // It will keep becoming active again by itself until the battle is over.

      // So everytime someone walks in try to make it deactive. Eventually the

      // battle will end and it will stick.

      SetEncounterActive( FALSE, oEncounter);

    }

  }

  else if( (iDeactivated == -1) && !bActivate)

  { // The encounter is activated and it should be inactive, so deactivate it.

    SetEncounterActive( FALSE, oEncounter);

    SetLocalInt( oEncounter, "TOD_Deactivated", 1);

  }

  else if( (iDeactivated == -1) && bActivate)

  { // The encounter is activated as it should be at this time of day.

    if( !GetEncounterActive( oEncounter))

    { // But the encounter object isn't active. It might be waiting to become

      // active after a previous trigger. Or it could be turned off by mistake

      // and will never re-activate itself. If we force another reactivate on it

      // we will bypass the respawn timer on it. If we don't it may never turn

      // itself on again. If it is indeed turned off by mistake, at least we know

      // it will get fixed on the next day/night cycle. So we will just assume

      // its not messed up but is merely on a respawn delay timer. That way we

      // don't screw up the respawn timer. Therefore, we don't force an activation

      // on it, we just do nothing and assume it will reactivate itself.

      return;

    }

  }

}

 

 

sorry, left the comments in cause i'm lazy and it would have taken too long... besides you might need them =D

 

thank you all

 

if i forgot anything ask away... i tend to do that


               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
multiple spawns from a trigger...
« Reply #1 on: July 10, 2014, 02:43:26 am »


               

I guess the first question is,  " Did you paint down spawn points with your encounter?."   That would be the first place to start.  When you place the spawn points, keep in mind, the the encounter will always spawn the creatures at the spawn point that is the greatest distance from the PC's.


 


 


EDIT: To draw a spawn point right click on the encounter.   Once one is drawn you can drag and drop it where you want it. 


 


EDIT2:  that is as much control as you can get over where an encounter spawns from the default NWN encounters. 



               
               

               
            

Legacy_diggerplus

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
multiple spawns from a trigger...
« Reply #2 on: July 10, 2014, 01:39:12 pm »


               

sorry lightfoot, lets try this from a different angle because i think maybe people might be misunderstanding me.


 


can someone assist me in making this script below do the following:


Use the dawn, day, dusk, and night features


make it so it has a delay of at least 900 seconds


the ability to have multiple creatures spawned (different resref/tags)


please.


 


//////////////////////////////////////////////

/// Created by: Jassper  ////////

//////////////////////////////////////////////

 

location MoveLocation(location lCurrent,float fDirection,float fDistance,float fOffFacing = 0.0,float fOffZ = 0.0f)

{

    vector vPos = GetPositionFromLocation(lCurrent);

    float fFace = GetFacingFromLocation(lCurrent);

    float fNewX = vPos.x + (fDistance * cos(fFace + fDirection));

    float fNewY = vPos.y + (fDistance * sin(fFace + fDirection));

    float fNewZ = vPos.z + (fOffZ);

    vector vNewPos = Vector(fNewX,fNewY,fNewZ);

    location lNewLoc = Location(GetAreaFromLocation(lCurrent),vNewPos,fFace + fOffFacing);

    return lNewLoc;

}

 

 

void ActivateTrigger(object oTrigger)

{

    // Set Up random numbers

    int iCount = Random(4)+3;

    float fDelay = IntToFloat((Random(3)+2)*60);

    int iLoop;

    location lLoc;

 

    //is Player still insdie trigger

    object oObj = GetFirstInPersistentObject(oTrigger);

    while(GetIsObjectValid(oObj))

        {

        if(GetIsPC(oObj))

            {

            for(iLoop = iCount; iLoop > 0; iLoop--)

                {

                lLoc = MoveLocation(GetLocation(oObj),IntToFloat(Random(360)),IntToFloat(Random(7)+2));

                CreateObject(OBJECT_TYPE_CREATURE,"goblin_k_01",lLoc);

                }

            DelayCommand(fDelay,ActivateTrigger(oTrigger));

            return;

            }

        oObj = GetNextInPersistentObject(oTrigger);

        }

    // no player in trigger, deactivate

    SetLocalInt(OBJECT_SELF,"ACTIVATED",FALSE);

}

 

 

void main()

{

    object oPC = GetEnteringObject();

    if(!GetIsPC(oPC))return;

 

    if(GetLocalInt(OBJECT_SELF,"ACTIVATED") != TRUE)

        {

        SetLocalInt(OBJECT_SELF,"ACTIVATED",TRUE);

        ActivateTrigger(OBJECT_SELF);

        }

}

 

thank you in advance for your assistance.


               
               

               
            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
multiple spawns from a trigger...
« Reply #3 on: July 13, 2014, 08:37:28 pm »


               

i'm gonna bump this cause it's something i could use myself... second one that is..


 


anyone got the testicular fortitude to get this done or know of a script out there that already does this?


 


i would assume that this section here would just need to be inserted somehow and it would work fine... i think.


 


void main()

{ // Get the tag name of this trigger.

  string sEncounter = GetTag( OBJECT_SELF);

 

  // If its not a Time Of Day Trigger return.

  if( GetStringLeft( sEncounter, 4) != "TOD_") return;

 

// Get the TOD spawn code from the trigger key and validate it.

 string sKey = GetLockKeyTag( OBJECT_SELF);

  if( GetStringLength( sKey) < 4) return; // Key specified wrong.

 

// This flag will be used to determine if the encounter should be active at

 // the time of day when the trigger was entered.

 int bActivate = FALSE;

 

 // Activate if its a dawn trigger and time of day is dawn.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDawn());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a day trigger and time of day is day.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDay());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a dusk trigger and time of day is dusk.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsDusk());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 

  // Activate if its a night trigger and time of day is night.

  bActivate |= (((GetStringLeft( sKey, 1) == "S") || (GetStringLeft( sKey, 1) == "s")) && GetIsNight());

  sKey = GetStringRight( sKey, GetStringLength( sKey) -1);

 


Lets get on it guys =D


 


Lets make this forum as good as the old one, you know.. before bioware got bought up by EA and killed it... where people didn't pick and choose so much about who they helped and actually helped if they knew how to do something....  If i have something someones looking for i post it, no questions asked.... that's how communities stay strong.. something i've noticed has gotten really bad here as of late.


 


DO THE RIGHT THING AND HELP MAKE THIS SCRIP WORK!!!


 


there you go diggerplus... hope someone gets 'er done.