Jump to content

Recommended Posts

Posted (edited)

I would like to create a script to implement a function that measures the time from when someone enters a zone to when they exit and displays a message, but I am inexperienced with scripting and cannot quite put it together.
I know that I can measure the time spent by subtracting the time that someone leaves from the time that he/she starts the measurement, but I have no idea how to script it.
Can you give me some advice or examples if you don't mind?

Edited by Admiral_ZIPANGU

Phantom Forever

F-4EJ / F-4EJ Kai 1971-2021

Sorry, I don't speak English, so I use DeepL Translate. Well, I can speak Japanese.

Posted

Okay, I'll try to help as best I can but I'm afraid there is nothing pre-made that will work for you.

Firstly, if you look at DCS singleton world - DCS World Wiki - Hoggitworld.com you'll see there is an event:

S_EVENT_TRIGGER_ZONE = 35

That *should* be what you could use to see what units (player and AI) are inside a trigger zone. However, like a lot of these events, it's unreliable and doesn't fire 99.9% of the time (I've only been able to detect it by having a trigger zone near a runway at a blue base and having blue AI ground units drive into it.)

So the only way around this bug is to do it manually. 

That means, you'll need to use a script to do a calculation from the Trigger zones getPoint() position and the radius of it and then do the maths involved to see if any unit's getPoint() is within that circle.

You could look at MOOSE/MIST to see how they do this (they do it as I've just described) and the maths is rather simple:

algorithm - Equation for testing if a point is inside a circle - Stack Overflow

But this is what's called a 'brute force' solution i.e. you have to test every unit, or you could make it somewhat smarter by only testing units that you would ever be interested in rather than everything. Either way, it's a not insignificant amount of code to cycle through all the units and do a calculation if they are inside that circle. 

Because Trigger zones are either spheres or cubes, you would then have to translate the y value (height) into it once you've detected that they x and z are inside the 'circle' so that you can then detect if the unit is inside the sphere that's up in the air. This would mean doing two more circle tests, but in two planes x & y and z & y, or you could do it like this: 

vectors - Check if 3D point is inside sphere - Mathematics Stack Exchange

without writing the functions myself (they're on my to-do list) I can't give you any code, but this is how you would go about solving it (AFAIK) unless you choose to use or 'take inspiration from' MOOSE/MIST'.

Good luck.

 

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...