Author Topic: Getting a Walkable location?  (Read 1426 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Getting a Walkable location?
« on: May 31, 2011, 10:42:28 am »


               Is it possible to, via nwn scripting - Get a Location in an area, which conforms to

1. It must be on the ground or against a solid surface, and
2. It must not be inside a wall etc.



But the catch is, that it must return a semi-random location.



The plan I have, is to make a plane travelling system.



Similar to the Spectral Realm I have here....


But instead of being a Plane of Spirits, tinted blue, with music to suit, I was planning on having a player ability, that allows the player to travel to different planes depending on their elemental affinity.


eg - If you are aligned with Fire, you travel to the Fire Plane.
The result being you travel to a plane which is tinted in red, has firey ambient music etc, but the problem comes with placeable objects.


I want to be able to place certain placeable objects programatically in the area to suit the plane. eg - Random Distribution of Fire, and maybe Lava etc
(The lava comment just gave me an idea, isnt there tilemagix or something, that lets you turn water in an area to Lava, Ice and Grass - Bingo)


Anyhow..
Fire Plane = Fire all over the area
Earth Plane = Tree's and Grass
Air Plane = Er.... I dunno... Clouds?
Water Plane = Underwater sort of effect.


I can do most of this, I just need to work out a random distribution system, and be able to determine if the location generated conforms to a valid location, and wont materialize inside a wall.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting a Walkable location?
« Reply #1 on: May 31, 2011, 12:56:48 pm »


               The only way i know how to do this would be to create a creature into the area.  This will make sure that the location the creature is in the walk mesh.  Place a script in the onspawn of the creature to destroy the creature and create the placeable in the same location.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Getting a Walkable location?
« Reply #2 on: May 31, 2011, 01:16:19 pm »


               Hmm, suppose that would do it.

There are some functions in the #include "x0_i0_position" which can also be used to get Random Locations - Although I cant see it on the Lexicon - I remember seeing it in the Function List in Toolset.

I could use that function to spawn say.... 20 basic creatures at random locations in the area, and in the onSpawn event, have them destroy themselves, and spawn the placeables.

I just wonder if this will create too much overhead.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Getting a Walkable location?
« Reply #3 on: May 31, 2011, 01:30:06 pm »


               Has anyone used
x0_i0_infinite


   string INF_BASE;
   void INF_CreateRandomEncounter(object oArea, object oPC);
   void INF_CreateRandomPlaceable(object oArea, object oPC);
   string INF_GetEntryMessage();
   string INF_GetReentryMessage();
   string INF_GetReachStartMessage();
   string INF_GetReturnToStartMessage();
   string INF_GetReachRewardMessage();
   string INF_GetReturnToRewardMessage();
   string INF_GetPoolEmptyMessage();


This function looks interesting.
INF_CreateRandomPlaceable(object oArea, object oPC);


I havent had a chance to look at it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting a Walkable location?
« Reply #4 on: May 31, 2011, 01:48:38 pm »


               

Baaleos wrote...

Has anyone used
x0_i0_infinite


string INF_BASE;
void INF_CreateRandomEncounter(object oArea, object oPC);
void INF_CreateRandomPlaceable(object oArea, object oPC);
string INF_GetEntryMessage();
string INF_GetReentryMessage();
string INF_GetReachStartMessage();
string INF_GetReturnToStartMessage();
string INF_GetReachRewardMessage();
string INF_GetReturnToRewardMessage();
string INF_GetPoolEmptyMessage();


This function looks interesting.
INF_CreateRandomPlaceable(object oArea, object oPC);


I havent had a chance to look at it.


Nope I hvae never seen that one before, 

If it does not work you can use Function - GetAreaSize to find your area size for your random locations.
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Getting a Walkable location?
« Reply #5 on: May 31, 2011, 06:04:40 pm »


               The tile thingy allows you to place any tile anywhere as an effect. It wont be solid though, so generally its only used for stuff like grass, water and lava.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Getting a Walkable location?
« Reply #6 on: May 31, 2011, 06:54:42 pm »


               

Baaleos wrote...

Hmm, suppose that would do it.

There are some functions in the #include "x0_i0_position" which can also be used to get Random Locations - Although I cant see it on the Lexicon - I remember seeing it in the Function List in Toolset.

I could use that function to spawn say.... 20 basic creatures at random locations in the area, and in the onSpawn event, have them destroy themselves, and spawn the placeables.

I just wonder if this will create too much overhead.

Lightfoot's way is the only way I know of to do it. I seem to recall someone - virusman, maybe? - looking at this issue and finding it too problematic to make a GetIsLocationWalkable because of z values or somesuch.

As for lag, so long as you only spawn the first, and Copy the rest of the creatures, it should be fine. I would probably stagger placeable creation slightly, once you have the locations, depending on how beefy your server is.

Funky
               
               

               
            

Legacy_Melkior_King

  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Getting a Walkable location?
« Reply #7 on: June 01, 2011, 11:17:43 am »


               I had a similar problem and solved it.

I wanted a mini-boss in an area to "feed" off of a placeable object's "life" during battle until the placeable ran out of life.

Once the placeable ran out of life, I wanted it to explode and scatter gems around the room, near to where the placeable used to be.

In order to make the gems look realistic, I used the gemstone placeables as containers and created an appropriate gem inside each container.

The important point is that the floor was uneven (the skull-shaped floor) so I needed to find exactly where "floor height" was.  The only realistic way to find the correct floor height was to create a NPC in a random location, find out where it was standing then destroy it.

Since the area was a single, self-contained mission, I set up the onenter for the area to check if the boss had been defeated or not, and to set up the area for the entering player if it hadn't already been set up before and the boss left unkilled.

As part of the onenter script, I made a loop which created NPCs randomly around the correct location and then stored the locations of those NPCs in variables on the area before destroying the NPCs.

Since all of the hard work is done during the onenter script, any lag caused is combined with the normal delay on loading a new area and therefore is less noticable.

When I need to create the placeables which contain the loot gems, I just access the variables I stored previously on the area.

Maybe you can do something similar?
               
               

               


                     Modifié par Melkior_King, 01 juin 2011 - 10:24 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Getting a Walkable location?
« Reply #8 on: June 01, 2011, 01:31:45 pm »


               Yeah, suppose that idea is feasible.

In order to make sure that the system doesnt lag everytime it does it, I can have it so that the Locations of where the placeables are spawned, are stored persistently per area.


Meaning that next time the server resets, and runs the same function, it doesnt need to spawn NPC's to get the data, because the server will have the position date already on hand.


If I wanted to be really fanci, I could have the onModLoad event, load the Persistent Locations into Memory or something as Locals.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Getting a Walkable location?
« Reply #9 on: June 01, 2011, 01:54:33 pm »


               Is it at all possible to somehow import/use NWN2 functions into NWN1 here? Just curious, as we have the functions GetIsLocationValid() and CalcSafeLocation() that sound like they are the exact functions you are in need of. The first obviously tells you if a location is a valid (walkable) spot, the other allows you to do a random search within a given space/range, centered on a given starting point, to find/pick a valid (walkable) location. Just wondering.
               
               

               


                     Modifié par _Knightmare_, 01 juin 2011 - 12:56 .
                     
                  


            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Getting a Walkable location?
« Reply #10 on: June 01, 2011, 03:41:04 pm »


               There are a few functions for this: GetGroundHeight & GetIsWalkable in nwnx_funcs and GetSurface in nwnx_funcsext.
CalculateSafeLocation is possible, but hasn't been requested; besides, it can be done with existing functions.
               
               

               


                     Modifié par virusman, 01 juin 2011 - 02:42 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
Getting a Walkable location?
« Reply #11 on: June 05, 2011, 08:48:27 pm »


               Just curious, have you thought of using a number of waypoints and then grabbing a random waypoint in order to give the illusion of randomness?
               
               

               
            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
Getting a Walkable location?
« Reply #12 on: June 05, 2011, 08:49:31 pm »


               Blarg! Post did not show up for a minute.
               
               

               


                     Modifié par DM_Vecna, 05 juin 2011 - 07:50 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Getting a Walkable location?
« Reply #13 on: June 06, 2011, 01:07:07 am »


               I agree with lightfoot, and funky...
A:)  Generating random loc is very easy with Function - GetAreaSize, then create a creature at loc to check validity. annd follow funky way of copying and placeing objects.

the mention of nwnx_funct extender I had know Idea it GetGroundHeight & GetIsWalkable, the CalculateSafeLocation would be a nice function and make the above A:) even easyer I would enjoy a function like that.  Rather then go through all the create a creature and check.  I VOTE if you can do it V-Man Go For it, I will use it rather then the A:) meathod
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Getting a Walkable location?
« Reply #14 on: June 06, 2011, 09:20:32 am »


               just keep in mind that walkable surface isn't allways reachable surface. ie in exterior you might have thing poping onto "wall terrain" ie terrain that is there to prevent the player from going in one direction. You can usually not be here so if you pop down something at this location the player will never reach it. Depending on what you do with random location, you might get logic bugs aswell such as thing poping up on heigh ledges. NWN isn't really suitable for physics properties.