Author Topic: Scripting an Area Transition?.?.?  (Read 1146 times)

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #15 on: May 15, 2011, 03:44:02 pm »


               

datamaster wrote...

With current tests, the door that sets the destination to where the PC says for it to go, is working.
The random side is occasionally working.  I think I know the problem.

This is my script for the random select door(the script on the door is the same as the other door, but this is the script in the conversation's Actions Taken script).


I do not see any problem with the script you posted.  If it is  occasionally working. It sounds like you may have a misspelling in one of your tags double check them. 


I think the problem is in the if statements.
ex. take this one:

  if ((seconddoor == 1) || (seconddoor == 2))

Now the seconddor ==1 is fine, but I think my OR statement is wrong(or using the wrong symbols or something).
I have been trying to find out what the AND, OR, etc. commands for if statements are in the NWN scripting language.  No luck.  I tried looking up Boolean Algebra and c# programming, and it says the OR symbol is +, but that not always working either.


You can fing the sentax for NWN in the lexicon. 

Logical Operators/Truth Tests

Your statment as written is reading
If seconddoor == 1 or seconddoor ==2 then  set the door destination.  That is correct and what you are looking for. 

Here is a pic to review the Truth Tables.

'Posted


Also, I am wondering, is the second SetLocalObject supposed to set the destination door back to this door?  ex. You set door1 to door2(you are standing at door1 though), does this set door2 back to door1 if you click on door2?
If it doesn't, I figure it should be reasonably ok, somehow, to tell the script that sets the objects to get the destination door it is going to use and set it's destination back to this one.
  


You are correct the second SetLocal is to compleate the two way connection between the two doors.
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #16 on: May 15, 2011, 07:32:08 pm »


               I am still having trouble with the random door sometimes not working.  My script for it is:

void main()
{
  int seconddoor = d6();
  string diceroll;
  object oPC = GetPCSpeaker();
  // Get the Object for each door.
  object oNPCsDoor = GetNearestObject(OBJECT_TYPE_DOOR);
  object oDestDoor;
  if ((seconddoor == 1) || (seconddoor == 2))
  {
    oDestDoor = GetObjectByTag("RandomDoor9");
    //This is to let the PC know what the number rolled is.
    diceroll =  IntToString(seconddoor);
    FloatingTextStringOnCreature("The dice roll is:", oPC);
    SendMessageToPC(oPC, diceroll);
  }
  else if ((seconddoor == 3) || (seconddoor == 4))
  {
    oDestDoor = GetObjectByTag("RandomDoor11");
    //This is to let the PC know what the number rolled is.
    diceroll =  IntToString(seconddoor);
    FloatingTextStringOnCreature("The dice roll is:", oPC);
    SendMessageToPC(oPC, diceroll);
  }
  else if ((seconddoor == 5) || (seconddoor == 6))
  {
    oDestDoor = GetObjectByTag("RandomDoor13");
    //This is to let the PC know what the number rolled is.
    diceroll =  IntToString(seconddoor);
    FloatingTextStringOnCreature("The dice roll is:", oPC);
    SendMessageToPC(oPC, diceroll);
  }
  else
    return;
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  // Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
}

I set it where it tells the PC what number the dice rolled.  It works on a 1-4 but on a 5 or 6, it does NOT send
the PC to his door.  I have double checked and triple checked the tags.  That door IS "RandomDoor13".
RandomDoor13 is a bridge door.  I am not sure what else to check.

There is nothing in the way of the PC when they click on the random door, so they are not having trouble getting to it.


------------------------
"Knowledge knows no bounds! But hindsight might have wished for some!"
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #17 on: May 15, 2011, 08:38:18 pm »


               Ok,  add this into the last check to help track down the problem. 

  else if ((seconddoor == 5) || (seconddoor == 6))
  {
    oDestDoor = GetObjectByTag("RandomDoor13");
    //This is to let the PC know what the number rolled is.
    diceroll =  IntToString(seconddoor);
    FloatingTextStringOnCreature("The dice roll is:", oPC);
    SendMessageToPC(oPC, diceroll);
    
    if (!GetIsObjectValid(oDestDoor))
        SendMessageToPC(oPC, "RandomDoor13 is not a valid Object");
     else
        SendMessageToPC(oPC, "RandomDoor13 is in area "+ GetName(GetArea(oDestDoor)));

  }


               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #18 on: May 16, 2011, 01:48:06 am »


               With those lines added, it found the door and told me the correct area it was in. But it still wouldn't send me to that door.
edit-Would you like me to send you this module to look at yourself?  It's not one I have on the vault.
               
               

               


                     Modifié par datamaster, 16 mai 2011 - 12:52 .
                     
                  


            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #19 on: May 16, 2011, 01:50:45 am »


               With this module not being on the vault, would you like me to send it to you somehow?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #20 on: May 16, 2011, 05:02:26 pm »


               Sure, Mail it to me at RicRtsm@hotmail.com
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #21 on: May 16, 2011, 05:03:02 pm »


               I tested another thing.  I switched the tags for RandomDoor11 and RandomDoor13.  Now I was able to get to RandomDoor13 but NOT RandomDoor11.  Is it just something to do with the door I picked for that area?
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #22 on: May 16, 2011, 05:07:42 pm »


               I just sent it to you.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #23 on: May 17, 2011, 02:28:39 am »


               The only thing I can say is that it just does not like jumping to the location of that door.   I guess it is trying to move the PC to a location that is not in the walkmesh.   So I guess we will just jump the PC to a location in front of the door instead.   This will work better any way I also turned the PC around so he is not facing the door he just walked through.  

Replace the First script I gave you with this one.  

#include "X0_I0_TRANSPORT"
void main()
{
  object oClicker = GetClickingObject();
  object oTarget = GetLocalObject(OBJECT_SELF,"TRANS_TARGET");
  float fFacing = GetFacing(oTarget)+180.0;
  vector vPos =GetPosition(oTarget)+ AngleToVector(fFacing);
  location lLoc = Location(GetArea(oTarget),vPos,fFacing);
 
TransportToLocation(oClicker,lLoc);
}

 
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #24 on: May 17, 2011, 03:34:42 am »


               That worked. Still not sure what exactly that fixed that the other one was having problems with, the way the PC was "facing"?
Anyway, it worked. Thanks again for your help Lightfoot8.
Now to plan on what I had originally planned for this(that was just a test module to get it to work).
edit-One of the plans I have for this is a prefab world.  A huge one.
               
               

               


                     Modifié par datamaster, 17 mai 2011 - 02:47 .
                     
                  


            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #25 on: May 17, 2011, 06:34:32 pm »


               Another quick question.  And since it involves an addition to one of these scripts, I will post this here.
I started working on one of the modules I had planned for this and set up at three different spots the random area set script(roll a dice, and depending on the result, set the door's destination to there).  I added to that where it will only use an area once.  If say I have three towns with banks, and the PC activates the conversation right outside(clicks on the sign) it randomly sets that door to one of three premade bank interiors I have made.
Then if I click on the bank sign in another town, it will NOT have the first town's bank(as it is now set) as one of the options(I don't want to different towns that are meant to be far apart having bank doors leading to the same bank.)

Now I have this working with this script:

void main()
{
  int seconddoor;
  int set = 0;
  string diceroll;
  object oPC = GetPCSpeaker();
  int BanksetTotal = GetLocalInt(oPC, "BanksetTotal");
  int Bank01 = GetLocalInt(oPC, "Bank01");
  int Bank02 = GetLocalInt(oPC, "Bank02");
  int Bank03 = GetLocalInt(oPC, "Bank03");
  // Get the Object for each door.
  object oNPCsDoor = GetNearestObject(OBJECT_TYPE_DOOR);
  object oDestDoor;
  if (BanksetTotal == 0)
  {
    seconddoor = d6();
    if ((seconddoor == 1) || (seconddoor == 2))
    {
        oDestDoor = GetObjectByTag("BankDoor1");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank01", Bank01);
    }
    else if ((seconddoor == 3) || (seconddoor == 4))
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }
    else if ((seconddoor == 5) || (seconddoor == 6))
    {
        oDestDoor = GetObjectByTag("BankDoor5");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank03 = Bank03 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank03", Bank03);
    }
  else
    return;
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  // Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
  else if ((BanksetTotal == 1) && (Bank01 == 1))
  {
    seconddoor = d2();
    if (seconddoor == 1)
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }
    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor5");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank03 = Bank03 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank03", Bank03);
    }
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
    else if ((BanksetTotal == 1) && (Bank02 == 1))
  {
    seconddoor = d2();
    if (seconddoor == 1)
    {
        oDestDoor = GetObjectByTag("BankDoor1");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank01", Bank01);
    }
    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor5");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank03 = Bank03 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank03", Bank03);
    }
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
  else if ((BanksetTotal == 1) && (Bank03 == 1))
  {
    seconddoor = d2();
    if (seconddoor == 1)
    {
        oDestDoor = GetObjectByTag("BankDoor1");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank01", Bank01);
    }
    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
else if ((BanksetTotal == 2) && (Bank01 == 0))
  {
//    seconddoor = d2();
//    if (seconddoor == 1)
//    {
        oDestDoor = GetObjectByTag("BankDoor1");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
//        FloatingTextStringOnCreature("The dice roll is:", oPC);
//        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank01", Bank01);
//    }
/*    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }*/
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
else if ((BanksetTotal == 2) && (Bank02 == 0))
  {
//    seconddoor = d2();
//    if (seconddoor == 1)
//    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
//        FloatingTextStringOnCreature("The dice roll is:", oPC);
//        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
//    }
/*    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }*/
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
else if ((BanksetTotal == 2) && (Bank03 == 0))
  {
//    seconddoor = d2();
//    if (seconddoor == 1)
//    {
        oDestDoor = GetObjectByTag("BankDoor5");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
//        FloatingTextStringOnCreature("The dice roll is:", oPC);
//        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank01 = Bank01 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank03", Bank03);
//    }
/*    else if (seconddoor == 2)
    {
        oDestDoor = GetObjectByTag("BankDoor3");
        //This is to let the PC know what the number rolled is.
        diceroll =  IntToString(seconddoor);
        FloatingTextStringOnCreature("The dice roll is:", oPC);
        SendMessageToPC(oPC, diceroll);
        BanksetTotal = BanksetTotal + 1;
        Bank02 = Bank02 + 1;
        SetLocalInt(oPC, "BanksetTotal", BanksetTotal);
        SetLocalInt(oPC, "Bank02", Bank02);
    }*/
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  //Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
  SetLocalInt(oNPCsDoor, "set", 1);
  }
}

BanksetTotal, Bank01, Bank02, and Bank03 are set when the PC enters the module.
The int set that I have this script setting, is where the conversation determines if it should activate the line that runs this script.  This way, it gets the int on the nearest door and if it is 1, it doesn't run the script again.

My question is, can this be streamlined anymore?  It seems a little long to me, and if I add more banks/towns, it will make it even longer.


-------------------------
"Knowledge knows no bounds!  But hindsight might have wished there was some!"
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #26 on: May 20, 2011, 05:11:29 am »


               Thread continued on the scripting forum


What is a good way to clean up big if statements?