Jump to content

Some scripting help please


Stonehouse

Recommended Posts

Tried to find another example of these but no luck so far so hoping someone can provide some assistance:

 

Trying to trap an air spawn event of an aircraft. I came up with this but couldn't get it to work. Any tips?

 

if (world.event.S_EVENT_BIRTH == event.id) and (world.BirthPlace.wsBirthPlace_Air == event.subPlace) then.....

 

The other thing I've been trying to find out is how do you get the vec2 or 3 position of an airbase without using trigger zones. Is there an equivalent command to the unit.getPosition?

 

Thanks,

Stoney

Link to comment
Share on other sites

Ok done some more testing and it appears that the air spawn issue is due to the second half of the condition. Basically

(world.BirthPlace.wsBirthPlace_Air == event.subPlace) is always false.

 

Can anyone give advice on how the birthplace part of the event works please?

 

Thanks,

Stonehouse

Link to comment
Share on other sites

Well, maybe this can help... Look at the Mist Guide Page 28 about mist.addEventHandler. I was looking for something else and saw this and thought of your post.

 

In your IF line you are testing to see if the world. stuff is equal to a specific value (event.id & event.subPlace), but where are you setting those values? I think you are trying to GET the values, not test for them.

 

Maybe use something like this...

do
 if world.event.S_EVENT_BIRTH and world.BirthPlace.wsBirthPlace_Air then
   event.subPlace == world.BirthPlace.wsBirthPlace_Air
 end
end

 

Man, I am really guessing here...

 

---

 

For your airbase locations -- go into Fly mode and put the cursor on an airbase and use LAlt-y to change the coordinate system to the vec position. Those airbases aren't going anywhere :)

 

 

Hope this helps.

 

WC

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Thanks Wrecking Crew. I'll play around with what your suggesting.

 

The airbases thing is an interesting twist to the idea. The reason I'm asking is that the GCICAP script does clean up of wrecks etc at airbases but uses a trigger zone of the same name to set the area of clean up. Which is a good way of doing it but people want to be able to add bases that the script doesn't see for spawning AI (human only bases so no trigger zone) and unfortunately once a base is blue or red then the AI will try to recover to it (per DCS logic) even if unknown to the script but then the clean up routine doesn't clean up lol. So building a hardcoded table of airbase vec2 co-ords might be a good idea not sure. Builds a map dependency into the script which will cause future problems so have to think about it more.

 

Thanks,

Stoney

Link to comment
Share on other sites

According to the ED docs there is an Airbase class which has a getByName method. Airbases are CoalitionObjects, so they inherit getPosition().

 

A quick test in DCS Witchcraft gives me this:

return Airbase.getByName("Batumi"):getPosition()
=> object
{
   "p": {
       "x": -355097.34375,
       "y": 9.9645166397095,
       "z": 616439.6875
   },
   "x": {
       "x": -0.58190792798996,
       "y": 0,
       "z": 0.8132546544075
   },
   "y": {
       "x": 0,
       "y": 1,
       "z": 0
   },
   "z": {
       "x": -0.8132546544075,
       "y": 0,
       "z": -0.58190792798996
   }
}

 

HTH, Ian

Link to comment
Share on other sites

Thank you !!. I did try to use Witchcraft Ian but part of my problem is if I don't know what to type in I don't get very far lol. I might have got to your line of code by a lot of trial and error but there is nothing to beat getting advice from someone who knows a programming language inside out. I wish you had some time to look at the lag issues created by the GCICAP script in MP as it's well beyond my knowledge but I know you are flat out with exams and other real life stuff.

 

On my other issue it seems that event.subPlace is nil when a unit air spawns where according to _G I was expecting 1, Bug perhaps??. Strangely it works fine for a unit spawning on the parking bay (value 5). I guess if it is uniformly nil then I can use that instead of 1.

 

Cheers,

Stoney

Link to comment
Share on other sites

Here is a function I used to get the nearest AB for a given coalition from an arbitrary position:

 

[font=Courier New]function getNearestAirbase(coa,pos)
   rvals = {}
   local airdromes = {}
   local tmp = coalition.getAirbases(coa)
   for i=1,#tmp do
       local j = #airdromes + 1
       airdromes[j] = {}
       airdromes[j].coa = coa
       airdromes[j].name = tmp[i]:getName()
       airdromes[j].pos = {}
       local pos2  = tmp[i]:getPosition()
       airdromes[j].pos = pos2
       airdromes[j].dist = getDistance(pos.p.x,pos.p.z,pos2.p.x,pos2.p.z)
       airdromes[j].brg = getBearing(pos,pos2) -- degrees
   end
   
   function tsort(a1,a2)
       return a1.dist < a2.dist
   end
   
   if #airdromes > 1 then
       table.sort(airdromes,tsort)
   end
   
   if #airdromes > 0 then
       return  airdromes[1]
   else
       return nil
   end
end
[/font]

It's designed to return the nearest AB, but by changing "return airdromes[1]" to "return airdromes" it will return all. You can also iterate over all coalitions to return all ABs. The returned table structure includes the AB's position.

 

getBearing and getDistance are separate functions (defined elsewhere in the script), and they can be safely deleted.


Edited by ajax
Link to comment
Share on other sites

  • Recently Browsing   0 members

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