View Single Post
Old 09-26-2011, 11:31 AM   #16
zbyl2
Junior Member
 
zbyl2's Avatar
 
Join Date: May 2008
Location: a galaxy far far away...
Posts: 320
Contest winner - Modding Veteran Modder 
Quote:
Originally Posted by Qui-Gon Glenn View Post
What I would like to ask the more knowledgable - how would I subroutine-ize the repeated portion of the code, so that I could just have the main script call it twice rather than having the text there for both instances of use? I know I would need to consolidate variables by making oParty (or oParty2, being arbitrary) be assigned to the regular (non-custom) party member. I had tried to do just that, but I am doing something wrong when I try to make subroutines... I think it has to do with where I am declaring my variables
Not sure if it's exactly what you wanted, but it doesn't have same code repeated twice anyway. Probably not the best way to do it, but it should work. I think.
Code:
void main()
{
   object oPC=GetFirstPC();
   object oCustom=GetObjectByTag("p_avix");
   object oParty=GetNextPC();
   object oParty2=GetNextPC();
   object oDoor=GetObjectByTag("man26ad_door02");

   // Define oProper object, which we'll use instead of oParty/oParty2 later.
   object oProper;

   if(oParty != oCustom && oParty2 != oCustom)
   {
      SendMessageToPC(oPC,"Something's screwy around here");
      return;
   }
   
   //figure out who's who
   if(oParty != oCustom) {
         oProper = oParty;
    } else {
     oProper = oParty2;
    }
   
       // your code, with oParty replaced by oProper.
         ActionPauseConversation();
         SetCommandable(TRUE,oDoor);
         SetCommandable(TRUE,oCustom);
         SetCommandable(TRUE,oProper);
         SetCommandable(TRUE,oPC);
         AssignCommand(oDoor, ActionOpenDoor(oDoor));
         ActionWait(1.0);
         AssignCommand(oPC, ActionForceMoveToLocation (Location(Vector(420.65048, 164.75064, 8.00), 0.0)));
         AssignCommand(oCustom, ActionForceMoveToLocation (Location(Vector(423.07117, 163.83559, 8.00), 0.0)));
         AssignCommand(oProper, ActionForceMoveToLocation (Location(Vector(419.32086, 165.04903, 8.00), 0.0)));
         DelayCommand(5.0, AssignCommand(oDoor, ActionCloseDoor(oDoor)));
         ActionResumeConversation();   

}
Nice thread by the way QGG - it saved me from boredom of setting up camera angles once more... need to get back to it now, though.
zbyl2 is offline   you may: quote & reply,