Author Topic: Jump NPC to random area. Is it possible?  (Read 989 times)

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« on: March 13, 2016, 03:25:39 am »


               

as the title says, can you transfer an NPC in an area chosen at random among those present on the module?
If so, how i must proceed?


 


 


EDIT


important...i forgot to say that I have the opportunity to use the plugins nwnx_area and nwnx_functions,if that can help me in some way.



               
               

               


                     Modifié par Cursed Eclipse, 13 mars 2016 - 03:56 .
                     
                  


            

Legacy_dunahan_schwerterkueste_de

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #1 on: March 13, 2016, 03:53:15 pm »


               

Should be possible, even without nwnx_functions. But within it, there is a function to get any area.


nwnx_funcs include

 



   Spoiler
   


With that, you should be able to code a function for a random area to jump to.


Or  you take that:


   Spoiler
   


It is an include from MJ/Zaddix/Knat I'm using to get every area in my PW too. Only one thing is important: For every area there must be placed a hidden placeable, which will be searched at module load and then deleted.



               
               

               
            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #2 on: March 14, 2016, 09:27:25 am »


               

thx for having shared your code dunahan_schwerterkueste_de


 


 


 


 



nwnx_funcs include


// Returns the total number of areas in the module NWNXFuncs_GetAreaCount();// Returns the first area of the module.// [/code]



Im im pretty sure that this function isn't present on linux version of nwnx_funcs.


And so this option it is not available for me.


 


 


 


 


Instead ,GetNextArea it's available.


 


Here what i have:



    object Area = GetFirstArea();.

     while(GetIsObjectValid(Area)==TRUE)

       {

       SetLocalObject(oModule,"Area_"+IntToString(i),Area);

       i++;

       Area = GetNextArea();

       }



This should return the total number of the areas present in the module.


 


 


Now that i have the tot. number of the areas what i should do to transport the npc into the random area?


Where should I use the random(); function?


 


 


This is the rest of the code I figured I can use,but obviously I'm missing a few pieces.



AssignCommand(oNPC, ClearAllActions(TRUE));


DelayCommand(0.1,AssignCommand(oNPC, ActionJumpToObject(Area)));


 




               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #3 on: March 14, 2016, 01:07:09 pm »


               

You can't jump to an area. You have to jump to a location or object in the area.  Fwiw, what I would do for this is put a WP in each area that could be selected, each with the same tag, like WP_RANDOM_AREA or something.  There may be areas which you don't want PCs to get to and this will allow you to limit it.  Put the waypoint somewhere you'd want to the PC to show up in the area.


 


You could count them on module load and store the number of WP_RANDOM_AREA waypoints. 


Then do something like :



int nRand = Random(count);
AssignCommand(oNPC, ClearAllActions(TRUE));
AssignCommand(oNPC, ActionJumpToObject(GetObjectByTag("WP_RANDOM_AREA", nRand)));

This is probably a problem you don't need to bother with nwnx for anyway '<img'>


               
               

               
            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #4 on: March 14, 2016, 02:06:20 pm »


               

thx Meaglyn.


But i would avoid the work of having to place a WP for each area,although actually it remains the problem of avoiding unwanted areas,as zone set as no_pvp.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #5 on: March 14, 2016, 02:37:12 pm »


               

You still need to find a valid location in the area to jump to.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #6 on: March 14, 2016, 04:05:05 pm »


               

exactly. a PC is jumped to a location (which is area and position), not to an area.


 


so you either jump to a random position in a random area and deal with all the code it will require to find a valid and playable location, or you simply lay out a ton of waypoints and maintain a pseudo array of them on the module (build it in module load) in order to have a fast random waypoint destination that you know will work every time.


 


"The choice is yours."


 


'<img'>



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #7 on: March 14, 2016, 04:09:51 pm »


               

We have an "Adventure Portal" in a Temple of Tymora that sends people to a random area. I utilize a homebrew function called SelectQuestDangerArea() that has a list of all the names of adventure areas in the module, and then I utilize the NWNXFuncs_GetXXXArea() functions to find the area chosen from the homebrew function.


 


To get someone to a specific spot in the area -


I use a modified version of NESS waypoints for virtually all creature and treasure spawns in our adventure areas which only spawn when a PC cannot see them (so even if they get jumped to a NESS waypoint they won't have bad guys spawn right on top of them). So that means I usually have plenty of waypoints, and also a number of doors, in these areas which make for good locations to jump a PC to a location that they can get out of. I.E. - jumping to a waypoint or door means they don't get stuck on an island or inaccessible random location in the area because the spawn waypoints and doors are in places that they'd normally be able to get to and from.


 


If you don't use NESS, I could also picture this working alright with encounter triggers (for dangerous areas) and doors (for all areas) instead of waypoints and doors.


 


Here's the code for the OnUsed of the adventure portal.



  //Adventure Portal in the Pyarados Temple of Tymora
  if (sTag == "AdventurePortal") {
    object oPortalDestination = GetLocalObject(OBJECT_SELF, "AdventureLocation");
    if (oPortalDestination == OBJECT_INVALID) { //If no adventure area is set, choose based off the level of the person using the portal first
      string sAdventureArea = SelectQuestDangerArea(oPC);

      object oAdventureArea = NWNXFuncs_GetFirstArea();
      while (oAdventureArea != OBJECT_INVALID) {
        if (GetName(oAdventureArea) == sAdventureArea) { //If we've found the area, cycle through and find a random place to port them
          oPortalDestination = GetFirstObjectInArea(oAdventureArea);
          while (oPortalDestination != OBJECT_INVALID) {
            int iObjectType = GetObjectType(oPortalDestination);
            //25% chance to jump them to this waypoint or door
            if ((iObjectType == OBJECT_TYPE_WAYPOINT || iObjectType == OBJECT_TYPE_DOOR) && d4() == 1) break;
            oPortalDestination = GetNextObjectInArea(oAdventureArea);
          }
          //Safety to try and jump them to *something* if all waypoints/doors have been exhausted (hopefully very rare)
          if (oPortalDestination == OBJECT_INVALID) oPortalDestination = GetFirstObjectInArea(oAdventureArea);
          break;
        }
        oAdventureArea = NWNXFuncs_GetNextArea();
      }

      SetLocalObject(OBJECT_SELF, "AdventureLocation", oPortalDestination);
      DelayCommand(60.0, DeleteLocalObject(OBJECT_SELF, "AdventureLocation"));
    }

    FadeToBlack(oPC);
    DelayCommand(2.0, AssignCommand(oPC, JumpAssociatesToObject(oPortalDestination)));
    DelayCommand(2.5, FadeFromBlack(oPC));
  }


               
               

               
            

Legacy_AndrueD

  • Sr. Member
  • ****
  • Posts: 253
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #8 on: March 14, 2016, 05:41:59 pm »


               

Hmmm... I try following this topic cuz we try something like this.  But our script use WPs like other ppl say cus much easier than random.  We try take PC location then add some x-y to that to get a target but only 4 directions NSEW on map.


 


But wen I read ur post was thinking you want to jump maybe ahead 50m or something in any direction that target icon find ok on map.  Was thinking some code like what posted here in wiki.


 


We try making trigger area all over maps that will let random target happen there but nowhere else like saferest.  It really donna work though, unless no more trigger needed in same place cuz they must overlap. And too many trigger so we fail.



               
               

               
            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #9 on: March 15, 2016, 09:10:52 am »


               

I have read very carefully the post of Thayan,


May I ask if this below,is a function?


string sAdventureArea = SelectQuestDangerArea(oPC);


 



and what it does?

it's a list of all the areas?


 


 


 


Anyway,now I'm trying to write my code.


 


Here's what I have:



object oMod = GetModule();
object Area = GetFirstArea();
int i;
             
 while(GetIsObjectValid(Area)==TRUE)//while (oArea != OBJECT_INVALID)
  {
  SetLocalObject(oMod,"Area_"+IntToString(i),Area);
  i++;
  Area = GetNextArea();
  }
   SetLocalInt(oMod,"MAX_AREAS",i);
   int nTot = GetLocalInt(oMod, "MAX_AREAS");
   int iRandom = Random(nTot);
   object RandomArea = GetLocalObject(oMod,"Area_"+IntToString(iRandom));
   
   //Looking for waypoint or a door
   object oObjectDestination = GetFirstObjectInArea(RandomArea);
    while (oObjectDestination != OBJECT_INVALID)
     {
     int iObjectType = GetObjectType(oObjectDestination);
     if ((iObjectType == OBJECT_TYPE_WAYPOINT || iObjectType == OBJECT_TYPE_DOOR))break;
     oObjectDestination = GetNextObjectInArea(RandomArea);
     }
      DelayCommand(0.9,AssignCommand(oKiller,ClearAllActions(TRUE)));
      DelayCommand(1.0,AssignCommand(oKiller, ActionJumpToObject(oObjectDestination)));

I do not know if I'm doing the right thing,I think I'm failing in the search for a door or a wp.


Every correction is welcome.



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #10 on: March 15, 2016, 02:01:23 pm »


               

The SelectQuestDangerArea function takes the PC as input, gets their hit dice, and then looks at the list of adventure areas I have setup in the list and returns the name of one (as a string) which is targeted for a PC of that level. They main thing with that function is I update it every time I add an adventure/encounter location to the module so it's not a completely random area (which is what I think you're trying to do, right?).


While I don't enumerate my areas first since I use that function, but it appears you are doing that, here's my suggestions for modifications to your code. I did not compile it (as it doesn't appear it's the entire script anyway), but so long as you are have the nwnx_funcs in your module and put #include nwnx_funcs at the top of the script, I believe it should compile.



  object oMod = GetModule();
  int i = 1;

  if (!GetLocalInt(oMod,"MAX_AREAS")) { //Thayan - If module areas have not been enumerated, do that now. Otherwise, don't keep running this as it is unnecessary and inefficient
    object oArea = NWNXFuncs_GetFirstArea(); //You need to use the NWNX function for this as there is no GetFirstArea() function in NWN by default    
    while (GetIsObjectValid(Area)==TRUE) {
      SetLocalObject(oMod, "Area_"+IntToString(i), oArea);
      i++;
      oArea = NWNXFuncs_GetNextArea(); //You need to use the NWNX function for this as there is no GetNextArea() function in NWN by default
    }

    SetLocalInt(oMod, "MAX_AREAS", i);
  }

  int nTot = GetLocalInt(oMod, "MAX_AREAS");
  int iRandom = Random(nTot)+1;
  object oRandomArea = GetLocalObject(oMod, "Area_"+IntToString(iRandom));

  //Looking for waypoint or a door
  object oObjectDestination = GetFirstObjectInArea(oRandomArea);
  while (oObjectDestination != OBJECT_INVALID) {
    int iObjectType = GetObjectType(oObjectDestination);
    //Thayan - Note that this will always send oKiller to the first waypoint or door it finds in oRandomArea
    if (iObjectType == OBJECT_TYPE_WAYPOINT || iObjectType == OBJECT_TYPE_DOOR) break;
    oObjectDestination = GetNextObjectInArea(oRandomArea);
  }

  DelayCommand(0.9,AssignCommand(oKiller, ClearAllActions(TRUE)));
  DelayCommand(1.0,AssignCommand(oKiller, ActionJumpToObject(oObjectDestination)));


               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #11 on: March 15, 2016, 06:22:34 pm »


               

Was the original post to teleport a NPC, or a PC to a random location? This thread seems to have switched from NPC, to PC..


               
               

               
            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #12 on: March 15, 2016, 06:33:52 pm »


               


Was the original post to teleport a NPC, or a PC to a random location? This thread seems to have switched from NPC, to PC..




 


A npc.Only a NPC.


 


In my case I'm trying to jump in another area, the monster (NPC) that kill the player character (PC).
Always on the same monster (the NPC killer) it is applied a bounty for the murder of the player character.


To make it more interesting,i'm thinking about teleport the monster in a randomly area, in order to simulate his escape .
Players must therefore look around the module, to find it.


 


Only the bosses who kill the players trigger the bounty.Not ordinary monster.


 


That my original idea.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #13 on: March 15, 2016, 06:37:02 pm »


               

For this discussion the difference is moot.  But yes that was my fault. Misread it. Nothing I said really changes if it's a PC or NPC. How you make sure the jump actually happens could be a bit different just to force it if it was a PC but otherwise finding a valid location in a random area is required either way.


 


I'd still do it by dropping 20 or whatever "hiding place" waypoints around the module and picking one at random.  Plus then it's easy to have a couple in a given large area...



               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Jump NPC to random area. Is it possible?
« Reply #14 on: March 15, 2016, 07:00:08 pm »


               

Interesting idea! I would go with waypoints rather than random placeable/doors in an area, unless of course those placeables/doors are set to plot- There is nothing worse than trying to spawn something, that can't find where it is suppose to spawn at, because someone cast fireball.