Jump to content

Scripting about an unit's position


Recommended Posts

I want to have a group spawning at the very location of a unit that could be located anywhere on the map.

I currently use a sleeping group that I intend to wake up and instantely move using ObjectChangePosition, that function uses Points, not Rects.

Could anyone suggest me another way to proceed ?

Link to comment
Share on other sites

I want to have a group spawning at the very location of a unit that could be located anywhere on the map.

I currently use a sleeping group that I intend to wake up and instantely move using ObjectChangePosition, that function uses Points, not Rects.

Could anyone suggest me another way to proceed ?

Just curious whats going to trigger the spawning unit. Is it when it enters a rect or gets close to a point. Or is it based on the loss of units or time.

Link to comment
Share on other sites

I'm working on a tank re-ammo script.

For now, it works this way :

1) When ammo count is down to 0, a message advices the player to bring his tank near a specially devoted truck.

2) When the tank is at less than 15 meters from the truck, everything is automated :

- it stops and crew bails out

- the truck crew moves a few times from truck to tank and back

- the empty tank is replaced by the sleeping one that has full ammo

- the tank crew gets back in the (new) tank and is now ready to go back to the front

This works, but the trick is too obvious : the tanks dispappears then reappears a few meters away.

And it only works if the ammo truck doesn't moves from its initial place.

I try to have this working anywhere on the map, avoiding the player to see the "tank switching".

Link to comment
Share on other sites

I finished it :

It only works with a third army because the truck musn't move, and I use the truck driver to place the empty tank at the precise place where the sleeping tank will appear.

Here is the script :

Label Attendre

Set @munitionsHE = EntityCountItems ( Unit , 139 , HE )

If ( @munitionsHE != 0 ) Then

Delay ( 3000 )

Goto Attendre

Endif

Label TestDistance

SendMessage ( "Pour ravitailler le B1Bis, il faut l'ammener à moins de 20 m du P107" , 3000 )

Set @Test = Distance ( Unit , 139 , Unit , 155 )

If ( @Test < 25 ) then

SendMessage ( "Distance OK ! Ravitaillement en cours - laisser faire !" , 3000 )

Goto MiseEnPlace

Else

Delay ( 7000 )

Goto TestDistance

EndIf

Label MiseEnPlace

PositionMode ( Unit , 139 , HOLD )

RunCommand ( Unit , 139 , Out_Crew , ALL )

Delay ( 10000 )

PositionMode ( Group , "Main_4" , Free )

BodyMode ( Group , "Main_4" , KNEE )

SetGroupFormation ( "Main_4" , Wedge )

RunCommand ( Group , "Main_4" , Move , Point , "Point_3" )

SetWorkArmy ( ARMY , 3 )

RunCommand ( Unit , 155 , Out_Crew , Crew )

Delay ( 3000 )

RunCommand ( Unit , 156 , In_Crew , Unit , 139 )

Delay ( 20000 )

SetWorkArmy ( ARMY , 1 )

RunCommand ( Group , "Main_4" , Rotate , Point , "Point_1" )

SetWorkArmy ( ARMY , 3 )

Label Placement

RunCommand ( Unit , 139 , Move , Point , "Point_1" )

Set @Place = GetNUnitsInArea ( Unit , 139 , Tanks , "Rect_1" )

If @Place = 0 Then

Delay ( 5000 )

Goto Placement

Endif

RunCommand ( Unit , 139 , Rotate , Point , "Point_2" )

Delay ( 10000 )

set @i1 = 0

Label Ravitailleurs

RunCommand ( Unit , 139 , Out_Crew , Crew )

RunCommand ( Group , "Group_FR_AI_2" , Move , Point , "Point_4" )

Delay ( 9000 )

RunCommand ( Group , "Group_FR_AI_2" , Move , Point , "Point_6" )

RunCommand ( Unit , 156 , In_Crew , Unit , 155 )

Delay ( 9000 )

Add ( @i1 , 1 )

If ( @i1 < 3 ) Then

Goto Ravitailleurs

EndIf

RunCommand ( Group , "Group_FR_AI_2" , In_Crew , Unit , 155 )

ReinforcementDestroy ( unit , 139 )

ReinforcementLand ( unit , 154 )

SetWorkArmy ( ARMY , 1 )

BodyMode ( Group , "Main_4" , STAY )

RunCommand ( Group , "Main_4" , In_Crew , Unit , 154 )

Delay ( 30000 )

SendMessage ( "Le ravitaillement est terminé !" , 5000 )

Halt

Link to comment
Share on other sites

×
×
  • Create New...