Home   Help Search Login Register  

Author Topic: How to detect whether or not a unit is in a building or vehicle  (Read 1304 times)

0 Members and 1 Guest are viewing this topic.

Offline Roni

  • Members
  • *
  • Play the Game !
Hello All

This (should be) a simple one.  How can I tell whether or not a unit is in a building or vehicle - ANY building or vehicle, not just a particular one ?

I am writing a mission with time dilation that takes place in the desert.  I have given the players an addaction that allows them to build a Tent unit on command.  The idea will be that the longer you stay in the open the more damaged you become, conversely the longer you stay indoors the healthier you become.  So the players SHOULD move around a lot, then either find a town or build a camp and restore their lost health.

The problem is that I want to know when they are "indoors", not just in a particular object.

Any ideas ?



Roni

deaddog

  • Guest
The vehicle part is easy.

vehicle player != player means they are in some sort of vehicle.

vehicle player == player means they are not.


The building part is not so easy.  One way would be to use the nearestbuilding function:

?player distance (nearestbuilding player) < 3:hint "indoors"

But that doesn't necessarily mean they are inside the building.  Not all buildings can be entered.  You may have to find all the object IDs of enterable buildings and check if the player is close enough to them.

Offline Roni

  • Members
  • *
  • Play the Game !
Hi deaddog

Actually that should just about do it !   :thumbsup: :cheers:

I am assuming that the "location" of an object is the central point of its model.  A building that you can't get into just means that you can't get closer than a certain distance to it's central point - problem solved !

Now all I have to do is test this out with a test script (show hint once player is "inside" the building).  Because of the small size of most buildings I am thinking that the distance should be something like one metre, not three.  I just get the script to check the player' position every 5 seconds or so and flash "Indoors" whenever they reach the safe spot.

Thanks again !

 :) :) :)


Roni

deaddog

  • Guest
You're welcome :)

That's a good point about the buildings.  I think your right about an objects location being the center of it. You could always check the larger buildings separatly if that turns out to be necessary (hard to find the "sweet spot")  8)

Offline Roni

  • Members
  • *
  • Play the Game !
Oddly enough I tested out a sample script last night and discovered that I could never get "Indoors", even after I set the radius to 10 metres !

I varied the hint to show the distance to the nearest building every 5 seconds rather than a simple headsup and even when I was in the middle or a building it said that the nearest one was around 1,600m away !

The problem could be the map I was using (Desert Everon).  I think that all of the buildings are custom made which means that they might not be recognised by the editor as being buildings.  I ran out of time but I will check again tonight.

More news as it happens !





deaddog

  • Guest
I tried this out on Nogova and Saragao and it worked ok:


player sidechat format ["%1",(player distance (nearestBuilding player))]

I don't have Desert Everon but it shouldn't have too many buildings, right?  You might try getting all the object IDs for the buildings and put them in an array like this:

_buildings=[3432,23234,564,etc] (use the right #s :) )

#loop
~5

_indoors=false

{if (player distance (object _x) < 2) then {_indoors=true}} foreach _buildings

?_indoors:hint "I'm inside!!"
goto "loop"


You could use this to set a global variable as well.


Offline Roni

  • Members
  • *
  • Play the Game !
Thanks - I must have been doing something wrong, I will try again tonight.

So how do I find out which buidlings are on the map ?  Don't I have to DePBO it somehow (I've never tried that before) ?

But as you say - it SHOULD be easy !



Cheers


Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Use Amalfi's depbo 1.5 from the Ed Depot - it's very easy.
Plenty of reviewed ArmA missions for you to play

deaddog

  • Guest
My script is using the object ID numbers, which you can get by clicking the "Show ID" box in the editor.  You may have to zoom in to see the numbers.

One cool thing I noticed about "nearestbuilding" is that it seems to work for large distances.  I had it work for over 700 meters.  The "nearestobject" function only works within 50 meters.

Depbo is great for taking apart missions or anything that is in .pbo format.  You can learn a lot by seeing how other people have done things.