Aller au contenu

Photo

Jump NPC to random area. Is it possible?


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

#1
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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 .


#2
dunahan_schwerterkueste_de

dunahan_schwerterkueste_de
  • Members
  • 43 messages

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.


  • Cursed Eclipse aime ceci

#3
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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)));

 


  • dunahan_schwerterkueste_de aime ceci

#4
meaglyn

meaglyn
  • Members
  • 807 messages

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 :)


  • henesua et Grani aiment ceci

#5
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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.



#6
meaglyn

meaglyn
  • Members
  • 807 messages

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



#7
henesua

henesua
  • Members
  • 3 863 messages

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."

 

:)



#8
Thayan

Thayan
  • Members
  • 244 messages

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));
  }

  • henesua et Cursed Eclipse aiment ceci

#9
AndrueD

AndrueD
  • Members
  • 136 messages

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.



#10
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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.



#11
Thayan

Thayan
  • Members
  • 244 messages

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)));

  • Cursed Eclipse aime ceci

#12
SHOVA

SHOVA
  • Members
  • 522 messages

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..



#13
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

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.



#14
meaglyn

meaglyn
  • Members
  • 807 messages

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...



#15
SHOVA

SHOVA
  • Members
  • 522 messages

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.



#16
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

about waypoint...you are right but im looking to keep the module the lightest that i can.

I know that WP it is very light object,
but that's how I work, avoiding the superfluous as much as possible,
and trying to recycle what is already there.

 

Would be approximately 230 WP to to be placed.One for each area.

 

However I'm still undecided on what to do;

there is still the problem of avoiding the NO_PVP areas,like shops and city.



#17
SHOVA

SHOVA
  • Members
  • 522 messages

By not placing a waypoint in an area, there is no chance of spawning the "Bounty Boss" in that area. I agree with Meaglyn - 20 waypoints is more than enough for a random chance. When you take into account other factors- "believable action" for instance, would the Boss, go to that area to hide? Is the area that spawns this Boss, hard enough to get to- to make searching for it there realistic? I doubt you want the boss to spawn in the main room of the local inn- that would be a rather short quest, with at least a shorter trek back to turn in the head- or whatever is used to identify the boss has been killed. I guess it depends on what you are after, I have learned over the years that random in NWN isn't really random- I seem to roll a lot more 1's than 20's. I would say start with 20 existing waypoints in your mod to use for this and test it. See if it is something you want to go full out 230 options, or if 20 will do.



#18
meaglyn

meaglyn
  • Members
  • 807 messages

I'm not telling you how to do it. I just said that's how I'd do it. I'd be done with the feature by now ;)

 

Whether its superfluous or not ... dunno that I'd call it that if it implements a feature you want. 



#19
Cursed Eclipse

Cursed Eclipse
  • Members
  • 70 messages

Incredible,work! O_O"

 

And it worked on the first try! :o

 

 

 

 

Here is the place where I found the boss:

http://imgur.com/iy3OXgE

 

 

Which is far from his usual residence.

 

 

I  do not have placed any wp.

In order to avoid unwanted areas i have enriched my script (fix'd by Thayan) with some additional line:

while(GetIsObjectValid(Area)==TRUE)//while (oArea != OBJECT_INVALID)
                {
//these lines below prevent areas ,on which was set a local variable, to be counted.
                 if(!GetLocalInt(Area, "autorespawn") || (!GetLocalInt(Area, "ARENA"))
                 {
////////////////////////////end of the addition/////////////////////////////////////////////////
                 SetLocalObject(oMod,"Area_"+IntToString(i),Area);
                 i++;
                 }
                 Area = GetNextArea();
                }
               SetLocalInt(oMod,"MAX_AREAS",i);
               }
add this code to the bounty system made by Blasco-Yang, and the job is done.
 

 

Thank Thayan, for correction to my script.
And thanks to everyone for the advice...and the patience.


  • Thayan et meaglyn aiment ceci

#20
dunahan_schwerterkueste_de

dunahan_schwerterkueste_de
  • Members
  • 43 messages

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.

I think I have the source code for the dll from Terra's codings... If I find them, I'll link them.

 

Here is the source code as 7zip-file: http://s000.tinyuplo...630667587878600

I had some code too, for placing placeables randomly in a area, without any waypoint. It even sets the right height and looks, if the new position is valid. I use it for a random builded dungeon, with some prebuilded areas, whitch are randomly connected. I have not finished this properly, due some other things on my PW.