[LUA] Marking contacts friendly via VP_GetSide()

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
Imaginos
Posts: 1
Joined: Sun May 28, 2017 1:38 pm

[LUA] Marking contacts friendly via VP_GetSide()

Post 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"?
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

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

Post 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
 
Michael
DeSade
Posts: 156
Joined: Mon Mar 01, 2004 5:08 pm
Contact:

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

Post 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 :)
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

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

Post by michaelm75au »

Your correct. Doing this late at night, and trying to remember what I typed ...[:D]
Michael
Post Reply

Return to “Tech Support”