Author Topic: Assigning an action to multiple objects  (Read 328 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Assigning an action to multiple objects
« on: July 29, 2014, 09:57:37 am »


               

Hello,


Is it possible to assign commands to more than one object at a time ?


object oNPCa


object oNPCb


AssignCommand(oNPCa and oNPCb, ActionSpeakString(sString,nVolume));


 


Ed



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #1 on: July 29, 2014, 10:53:06 am »


               


Hello,


Is it possible to assign commands to more than one object at a time ?


object oNPCa


object oNPCb


AssignCommand(oNPCa and oNPCb, ActionSpeakString(sString,nVolume));


 


Ed




AssignCommand(oNPCa, ActionSpeakString(sString,nVolume));


AssignCommand(oNPCb, ActionSpeakString(sString,nVolume));


               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #2 on: July 29, 2014, 06:28:35 pm »


               

void doStuff(object oNPC)


{


AssignCommand(oNPC, ClearAllActions());

}


 


void main()


{


object oNPCa;


object oNPCb;


 


doStuff(oNPCa);


doStuff(oNPCb);


}



               
               

               


                     Modifié par WhiteTiger, 01 août 2014 - 10:04 .
                     
                  


            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #3 on: July 30, 2014, 12:16:48 am »


               For most practical purposes, yes.


Strictly speaking, the actions aren't exactly simultaneous, but they generally appear synchronised, provided the AI levels are identical and the action queues are cleared first.


For very precise synchronisation, such as troops marching in formation, it pays to disable all unnecessary AI and build in time or scripting for laggards to catch up.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #4 on: July 30, 2014, 12:37:14 am »


               

No point in clearing the action queue for speaking strings.  If you want to have higher priority than the actions use SpeakString(), if you wish for the actions to resolve themselves, use ActionSpeakString().



               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #5 on: July 30, 2014, 02:50:14 am »


               

Okay,


I want to apologize to you all. I was trying to be brief( Up early trying to get some work done before rushing to work).


I'll abreviate where I can.


Here is the set up. I placed 4 NPCs in an area. A trigger spawns 24 more NPCs. The 24 are divided into 3 factions(groups).


When the 24 are spawned, they are assigned 24 new tags. The script is set on HB of a placeable. It uses Set and GetLocalInt to controll the pace of actions in the area I know that before it's finished it's going to get big.


 


This is the chopped down version that I have so far.


 


object oPC


object oArea Tag


objects Tags of the placed NPCs


object Placeable OBJECT_SELF


if(GetArea(oPC) == oArea)//List of Variables only if PC is in Area &

 {

  if(GetIsNight())// if it is night.

  {


   24 objects Tags


   Various ints, strings,ect


// BEGIN SCRIPT//

   if(GetLocalInt(oCase,"Brawl") == 4)

   {

    AssignCommand(oShA,ActionSpeakString("When Her Boyfriend's Gone Away!",nVolS));

    SetLocalInt(oCase,"Brawl",5);

   }

   else

   {

   if(GetLocalInt(oCase,"Brawl") == 3)

   {

    AssignCommand(oShA,ActionSpeakString("3rd line?",nVolS));

    SetLocalInt(oCase,"Brawl",4);

   }

   else

   {

   if(GetLocalInt(oCase,"Brawl") == 2)

   {

    AssignCommand(oShA,ActionSpeakString("2nd line",nVolS));

    SetLocalInt(oCase,"Brawl",3);

   }

   else

   {

   if(GetLocalInt(oCase,"Brawl") == 1)

   {


    AssignCommand(oShA,ActionSpeakString("1st line of dirty song!",nVolS));

    SetLocalInt(oCase,"Brawl",2);

   }

   else

   {

    SetLocalInt(oCase,"Brawl",1);

   } // int 1

   } // int 2

   } // int 3

   } // int 4

  } //IsNight

 } //oArea

}


 


This is the first verse of the song(2 more to go). As it is currently writen, the first NPC sings all 4 lines and then starts from the beginning.


 What I am trying to do is to have some of the group of 8 singing, some drinking, some laughing and so on. The same for the other 16. It is eventualy going to turn into a barroom brawl.


 


And here is where being a noob sucks. I am not such a noob that I didn't know I could assign the commands individualy, but I am enough of a noob to scratch my head and look confused when I read White Tiger's post. From what I've read on the lexicon, it's called a wrapper function ? Don't get it.


 


So,if any of you could give me some help(small words and an ocassional slap on the back of the head), I would be most grateful.


 


Ed.


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #6 on: July 30, 2014, 09:33:49 am »


               Code you want to use more than once (for different actors, say) can be packaged in a function.
 
The most efficient way to run a set of actions is to AssignCommand to a function:
void doStuff()
  {
    ActionSpeakString("Line 1",nVolS));
    ActionWait(5);
    ActionSpeakString("Line 2",nVolS));
    // ... and so on
  }
 

void main()
  {
    AssignCommand(oNPC1, doStuff());
    AssignCommand(oNPC2, doStuff());
  }
To vary which set of actions each actor is doing, you might choose their action using random().
 
The laughing / drinking action sets will need to run for the same overall time as the song (though a tavern obviously doesn't require military precision!)
 
If there is too much floating text, you might consider having just one or two speakers, with all the singers animated, so they seem to be singing in time.
 
I don't think I can be more specific without knowing your intentions in even more detail!
               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Assigning an action to multiple objects
« Reply #7 on: July 31, 2014, 10:20:57 pm »


               Proleric,
Thank you. Your example made things much clearer to me. Seems to be working. Thanks again.
Ed