Aller au contenu

Photo

Issue comands to multiple NPCs


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages
So I've written a script to issue move comands to a number of NPCs, but it's not working.

I've set up an encounter in which the PC enters a pit to fight a drow.  as soon as they enter the pit the drow goes hostile and archer come out of two room on either side of the pit and take position around the pit.  The number archers could be anywhere from 0 to 6, depending on PC level.

I used a for loop to spawn the archers:
    int iInt;
    for(iInt=1; iInt<=iArchers; iInt++)
    {
        oTarget = GetWaypointByTag("archer_spawn_"+IntToString(iInt));
        lTarget = GetLocation(oTarget);
        CreateObject(OBJECT_TYPE_CREATURE, sArchers, lTarget,FALSE,("drow_archer"+IntToString(iInt)));  //spawn Archers
    }

When the PC enters the pit I use another loop to issue the commands:
//Open the doors for the archers
    oTarget = GetObjectByTag("drow_door1");
    AssignCommand(oTarget, ActionOpenDoor(oTarget));
    oTarget = GetObjectByTag("drow_door2");
    AssignCommand(oTarget, ActionOpenDoor(oTarget));
    
//Assign comands to archers
    int iN;
    for(iN=1;iN<=6;iN++)
    {
        oTarget = GetObjectByTag("drow_archer1"+IntToString(iN));
        DelayCommand(0.5,AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("archer_position_"+IntToString(iN)),TRUE)));
        DelayCommand(1.5,ChangeFaction(oTarget,GetObjectByTag("Hostile")));
    }

When I test the script the doors open but the archers don't come up.  They do spawn, they just don't come out.  Does anyone see a problem in my code or is this just a pathing issue?

#2
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages

Shaun the Crazy One wrote...

        oTarget = GetObjectByTag("drow_archer1"+IntToString(iN));


Typo, should be "drow_archer", not "drow_archer1".

I always suspect myself of rank idiocy when checking code, and I'm often right.

#3
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages
Wow that was a fast responce. Can't believe I missed that. Thanks Lugaid.

#4
Dann-J

Dann-J
  • Members
  • 3 161 messages
This is the sort of thing that the include file ginc_group is very handy for.

For instance, you can spawn an encounter and then (after a very slight delay) use the EncounterToGroup function on them. Then you can command them to do things as a group with a single function, rather than having to create a loop to pick them all up individually.

#5
Shaun the Crazy One

Shaun the Crazy One
  • Members
  • 183 messages

DannJ wrote...

This is the sort of thing that the include file ginc_group is very handy for.

For instance, you can spawn an encounter and then (after a very slight delay) use the EncounterToGroup function on them. Then you can command them to do things as a group with a single function, rather than having to create a loop to pick them all up individually.


The group comands are very useful, but in this case I need each Archer to move to a different position.  I don't think you can do that with group comands.

I suppose another way might have been to simply spawn the archers when the PC enter the pit and use walkwaypoints to get the to move into position on spawn.  Either way it works now.

Modifié par Shaun the Crazy One, 23 janvier 2012 - 09:57 .