Page 1 of 1

[LUA] Marking contacts friendly via VP_GetSide()

Posted: Sun May 28, 2017 1:53 pm
by Imaginos
I'm looking to use lua to mark a neutral contact as friendly as if the track were hooked and the player pressed the "f" key manually. So far I have the below based on the examples in the documentation.

Code: Select all

 unit = ScenEdit_UnitX()
 vp = VP_GetSide({name = "TF599"})
 cp = vp.contacts
 guid = cp[?12?].guid
 contact = VP_GetContact({guid=guid})
 contact.posture='Friendly'
I don't understand how VP_GetSide.contacts is indexed and how to pull a contact out of it based on possessing a unit.guid. I've marked the hard spot with a ?12? above. The error in the log says that the index on line 4 is nil, or sometime it seems that no error is generated at all.

Also, the documentation on contacts.posture isn't clear to me. Should I be setting that to the table value 1, the string "1", or the string "friendly"?

RE: [LUA] Marking contacts friendly via VP_GetSide()

Posted: Mon May 29, 2017 6:56 am
by michaelm75au
vp.contacts returns a table of contacts that the side has.
This is a simpler way:

Code: Select all

 -- my side
 local u = ScenEdit_GetUnit({name = "TF599"})
 -- unit that triggered event
 local contact = ScenEdit_UnitX()
 -- this unit seen as a contact by others
 local con = contact.ascontact
 -- not generated as a contact yet
 if #con ~= 0 then
   -- listed as a contact by some side
   -- what is the side id for the unit
   local myside = ScenEdit_GetSideOptions({side=u.side}).guid
   -- find the side's entry in the triggering unit's contact list
   for x = 1, #con do
     if con[x].side == myside then
       -- contact for my side
       local mycontact = ScenEdit_GetContact(con[x].guid)
       mycontact.posture = 'F'
       break
     end
   end
 end
 

RE: [LUA] Marking contacts friendly via VP_GetSide()

Posted: Mon May 29, 2017 6:59 pm
by DeSade
I think line:

if con[x].side == side then

should look like:

if con[x].side == myside then

otherwise, great example as always Michael, thank you :)

RE: [LUA] Marking contacts friendly via VP_GetSide()

Posted: Mon May 29, 2017 7:18 pm
by michaelm75au
Your correct. Doing this late at night, and trying to remember what I typed ...[:D]