Author Topic: Spawn in allies based on PCs present  (Read 505 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Spawn in allies based on PCs present
« on: March 18, 2016, 07:08:27 pm »


               

Hi, I'm trying to modify the script I have so it will stop spawning in mobs when the number of NPC/hostile faction members equals the number of PC faction members. If it could also possibly keep track of the ones that have already died that would be awesome. I need help if anyone's willing or knows how to do this.


 


 


Here's what I have right now.


{


object oSpawn;

effect eVFX;

object oSelf = OBJECT_SELF;


object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(OBJECT_SELF), TRUE);

int i = 0;

while(oTarget != OBJECT_INVALID)

{

if(GetIsPC(oTarget))

{

if(GetObjectSeen(oTarget) && i != 1)

{

i++;

}

else if(GetObjectSeen(oTarget))

{

//DO CALL FOR HELP THING HERE


    eVFX = EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_EVIL);

    oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ephemeralnegativ", GetLocation(oSelf));

    DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSpawn));


break;

}

}

oTarget = GetNextObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(OBJECT_SELF), TRUE);

}

}


 


 



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Spawn in allies based on PCs present
« Reply #1 on: March 20, 2016, 12:09:44 am »


               

I'm not sure I understand the situation.


 


This script is in OnEnter for the trigger, yes?


If so, when you enter the trigger, all objects within 27.0m of it are checked.


 


If it is a PC we check if it is seen.  I'm not sure a trigger can "see" a PC, so that function may not work when called from a script put on a trigger. I could be wrong - the gurus live much further up the mountain than I.


 


My question is, why does the PC need to be seen?  Do you want to know instead how many PCs there are that are alive so you can count them?


               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Spawn in allies based on PCs present
« Reply #2 on: March 20, 2016, 01:26:19 am »


               

The event I have the script in currently is OnHeartbeat, on an npc. The latter part of your question is yes, though I suppose it could be done without them being seen?



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Spawn in allies based on PCs present
« Reply #3 on: March 20, 2016, 06:58:12 pm »


               

Just to get it right, What you have is a HB script set on the NPC that will "DO CALL FOR HELP".


 


The way the script is set up currently, it will perform the call if he returned object is a PC on the first iteration of the conditional loop, 1=0, but not the second PC object, i=1, and continue to perform after that, 1 >1,  as long as there is a valid PC object returned by GetNext and as long as those objects returned are seen. By perform I mean create the spawn(s) and apply the visual fx 0.5 seconds after the termination of the script.


 


Q#1: Does this HB script run on more than ONE NPC in the confrontation. If so, probably not a goo thing. You will get endless spawning especially if all NPC mobs run this.


 


Q#2: When you say you want it to keep track of the ones that have already died, do you mean PC's or NPC's. Not clear.



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Spawn in allies based on PCs present
« Reply #4 on: March 22, 2016, 01:45:26 am »


               

I do my Call Help from the OnUserDefined handle and put the code in the end combat round section.


 


In order for the NPC to run that code they need this somewhere in their OnSpawn handle:


 SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT) so the system knows that it should look in the UserDef script for code to run.


 


From there you can add whatever you want.


 


Instead of running every 6 seconds while the NPC exists, it only runs while the NPC is in combat and you might be able to assume that if they are in combat there is a PC fighting them (and save yourself the need to check for one).


 


All that aside, I think this is the code snippet might be what you want and may work in either place.



 
    object oSpawn;
    object oSelf = OBJECT_SELF;
    int iPC = 0;
    int iNPC = 0;
    effect eVFX;
 
 
    object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(oSelf), TRUE);
    //this first loop will count the number of PCs we can see, and the number of friendly NPCs
    while( GetIsObjectValid(oTarget) )
    {
        if( GetIsPC(oTarget) && GetObjectSeen(oTarget,oSelf) )
        {
            iPC++;
        }
        else if( GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetIsFriend(oTarget,oSelf) )
        {
            iNPC++;
        }
    oTarget = GetNextObjectInShape(SHAPE_SPHERE, 27.0, GetLocation(oSelf), TRUE);
    }
    //now that we have counted them up, lets spawn things until iNPC = iPC
    do
    {
        eVFX = EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_EVIL);
        oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ephemeralnegativ", GetLocation(oSelf));
        DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSpawn));
    }
    while( iPC > iNPC );