### Post by Quintaxel on Aug 24, 2015 21:05:18 GMT 1

bb, this is the script you requested. It's quite straightforward I guess.

I calculate the distance between the 2 units using the function GetDistBetwUnits(unit1, unit2)

and compare it with a set distance.

Make sure to add the function sqrt() to the script.

I do not consider myself a scripter so there may be better solutions but this does the job.

To test the script;

Create a map with 2 units ScriptID 100 and ScriptId 200

Put a reinforcementgroup 300 on the map.

Move the units close to eachother to get the reinforcements.

You can play with the variable <close> to determine the best distance between the units.

copy the script to a Lua file and link it to the map.

Here it goes.

--------------------------------------------- Startup Message -----------------

DisplayTrace ("Sending in reinforcements when 2 units ScriptId's come together");

DisplayTrace ("Scripting by Quintaxel");

DisplayTrace ("24-08-2015 R1");

--------------------------------------------------------------------------------

function BB1()

local close = 150; -- The maximum distance between units to get reinforcements (in scriptpoints)

local distance = GetDistBetwUnits(100, 200); -- Actual distance between both units

if distance < close then -- if the distance between bot units is smaller then the minimum distance

RunScript ("ReinforceGroup300", 3000); --This could be any script that you want to trigger.

Suicide();

end;

end;

function ReinforceGroup300 ()

LandReinforcement ("300"); -- Obvious

Suicide();

end;

function Init()

RunScript ("BB1", 3000);

end;

------------------------------------Metafunctions------------------------------

function GetDistBetwUnits(unit1, unit2)

-- Script by Quintaxel 24-08-2015 (R1)

-- Calculates the distance between 2 units in scriptpoints.

-- Requires sqrt ()

-- Input parameters: unit1, unit2 ScripId's of units

-- Output parameters: dist, distance between 2 units

-- Callingprotocol: GetDistBetwUnits(unit1, unit2);

local dist;

local x1,y1 = GetObjCoord (unit1);

local x2,y2 = GetObjCoord (unit2);

local x = x1-x2;

local y = y1-y2;

dist = sqrt ((x*x) + (y*y));

return dist;

end;

function sqrt(x) -- Insert the function sqrt(x) here !!!!!!!!!!

I calculate the distance between the 2 units using the function GetDistBetwUnits(unit1, unit2)

and compare it with a set distance.

Make sure to add the function sqrt() to the script.

I do not consider myself a scripter so there may be better solutions but this does the job.

To test the script;

Create a map with 2 units ScriptID 100 and ScriptId 200

Put a reinforcementgroup 300 on the map.

Move the units close to eachother to get the reinforcements.

You can play with the variable <close> to determine the best distance between the units.

copy the script to a Lua file and link it to the map.

Here it goes.

--------------------------------------------- Startup Message -----------------

DisplayTrace ("Sending in reinforcements when 2 units ScriptId's come together");

DisplayTrace ("Scripting by Quintaxel");

DisplayTrace ("24-08-2015 R1");

--------------------------------------------------------------------------------

function BB1()

local close = 150; -- The maximum distance between units to get reinforcements (in scriptpoints)

local distance = GetDistBetwUnits(100, 200); -- Actual distance between both units

if distance < close then -- if the distance between bot units is smaller then the minimum distance

RunScript ("ReinforceGroup300", 3000); --This could be any script that you want to trigger.

Suicide();

end;

end;

function ReinforceGroup300 ()

LandReinforcement ("300"); -- Obvious

Suicide();

end;

function Init()

RunScript ("BB1", 3000);

end;

------------------------------------Metafunctions------------------------------

function GetDistBetwUnits(unit1, unit2)

-- Script by Quintaxel 24-08-2015 (R1)

-- Calculates the distance between 2 units in scriptpoints.

-- Requires sqrt ()

-- Input parameters: unit1, unit2 ScripId's of units

-- Output parameters: dist, distance between 2 units

-- Callingprotocol: GetDistBetwUnits(unit1, unit2);

local dist;

local x1,y1 = GetObjCoord (unit1);

local x2,y2 = GetObjCoord (unit2);

local x = x1-x2;

local y = y1-y2;

dist = sqrt ((x*x) + (y*y));

return dist;

end;

function sqrt(x) -- Insert the function sqrt(x) here !!!!!!!!!!