Lua question - can you use a Lua command to make a unit change sides?

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
jarraya
Posts: 339
Joined: Mon Sep 10, 2007 4:04 pm

Lua question - can you use a Lua command to make a unit change sides?

Post by jarraya »

Is there a command to make a unit change sides during the game?
User avatar
Primarchx
Posts: 1954
Joined: Sun Jan 20, 2013 9:29 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by Primarchx »

No. You can use it to change a side's posture to each other, though.
jarraya
Posts: 339
Joined: Mon Sep 10, 2007 4:04 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by jarraya »

I guess you could use Delete_Unit and then Add_Unit to the other side. However, you would need to be able to "capture" the coordinates of the current unit. Any idea how that would work?
User avatar
Primarchx
Posts: 1954
Joined: Sun Jan 20, 2013 9:29 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by Primarchx »

You can create RPs anchored to the unit that triggers your remove/replace action when an opposing unit enters the area. I usually use a side allied to the enemy side, called Control, to do this. It keeps the enemy side's screen cleaner for patrol RPs and the like.
jarraya
Posts: 339
Joined: Mon Sep 10, 2007 4:04 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by jarraya »

ORIGINAL: Primarchx

You can create RPs anchored to the unit that triggers your remove/replace action when an opposing unit enters the area. I usually use a side allied to the enemy side, called Control, to do this. It keeps the enemy side's screen cleaner for patrol RPs and the like.

Primarchx what I'm trying to do is "transfer" a unit over from a civilian side to player control. If I use a different side to the player controlled one the player won't be able to control the unit. I'm thinking there has to be a Lua code that let's me copy the coordinates of the unit, delete it, then add the same unit with the old coordinates under a new side. Possible??
ExNusquam
Posts: 528
Joined: Mon Mar 03, 2014 11:26 pm
Location: Washington, D.C.

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by ExNusquam »

Try this:

Code: Select all

local unit = ScenEdit_GetUnit({name="Ship A",side="Red Force"})
 newship = ScenEdit_AddUnit({type="Ship", name = "Ship B", side = "Blue Force", DBID = 1023, Latitude = unit.latitude, Longitude = unit.longitude})
 ScenEdit_DeleteUnit({side="Red Force", name="Ship A"})

Unfortunately, you will simply get a brand new unit on the player side.
jarraya
Posts: 339
Joined: Mon Sep 10, 2007 4:04 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by jarraya »

ORIGINAL: ExNusquam

Try this:

Code: Select all

local unit = ScenEdit_GetUnit({name="Ship A",side="Red Force"})
 newship = ScenEdit_AddUnit({type="Ship", name = "Ship B", side = "Blue Force", DBID = 1023, Latitude = unit.latitude, Longitude = unit.longitude})
 ScenEdit_DeleteUnit({side="Red Force", name="Ship A"})

Unfortunately, you will simply get a brand new unit on the player side.

Thanks ExNusquam. For the purposes of my scenario a brand new unit with the same name and in the same position of the previous unit will do! I'll give it a try tonight. Cheers!
User avatar
Primarchx
Posts: 1954
Joined: Sun Jan 20, 2013 9:29 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by Primarchx »

Yes, that's what I was going for. The third, Control side, was for management of the trigger areas, not a faction to which a new unit would be assigned.
jarraya
Posts: 339
Joined: Mon Sep 10, 2007 4:04 pm

RE: Lua question - can you use a Lua command to make a unit change sides?

Post by jarraya »

Worked a charm. Takes the coordinates from the first unit and uses them to place the second unit!
Post Reply

Return to “Mods and Scenarios”