Post by Quintaxel on Nov 3, 2021 14:05:21 GMT 1
A while ago, quite a while ago, I scripted a function to make units follow certain waypoints on that are placed on a map. These waypoints are actually script areas.
The idea was to create a user friendly function to make units to move along these waypoints in 2 different directions.
So suppose you have put a number of waypoints on the map, let’s say P1, P2, P3,…, P10, P11, P12 and you want to make a unit with iscriptID 301 to follow these points then this can be done by one function only.
FollowWaypointsTrail (1, 0, 301, "P", 12);
- The first argument is the direction. 1 moves the unit from P1 to P12. Changing the value to -1 will move the unit from P12 to P1.
- The second argument can have the values 0 = MOVE_TO or 3 = SWARM_TO
- The third argument is, you guessed it the iScriptId of the unit.
- The fourth argument of the function is a string variable. In this case “P”. The string should contain the values of the waypoint name before the number. So is your waypoints are called “WP1”, WP2”, “WP3” then the value of the string should be “WP”
- The last argument is the number of point you want the unit to follow. In most cases you want the unit to follow all waypoints but if you enter the value 8 here then the unit will only follow 8 waypoints. Depending on the direction this would be P1 to P8 or P12 to P5.
Now the fun part is that this function can also be used to make a unit patrol on the map.
This can be done by checking if the unit reached the last waypoint and then call the function again with a changed direction. Remember you will have to put a Suicide () instruction in the function that called the FollowWaypointsTrail (…) function.
Another option is to put the last waypoint close to the first one. When then units reaches the last waypoint then it can start another patrol round. To do this you must not put Suicide () instruction in the function that is calling the FollowWaypointsTrail (…) function. If you opt to do this then you should run the function at intervals that are longer then the time it takes for the unit to patrol.
Should there be any interest then I can demonstrate the different methods. The function is free to use but I would appreciate it if you just let me know that you used it in a map.
Here's the function. 14 lines in total
The idea was to create a user friendly function to make units to move along these waypoints in 2 different directions.
So suppose you have put a number of waypoints on the map, let’s say P1, P2, P3,…, P10, P11, P12 and you want to make a unit with iscriptID 301 to follow these points then this can be done by one function only.
FollowWaypointsTrail (1, 0, 301, "P", 12);
- The first argument is the direction. 1 moves the unit from P1 to P12. Changing the value to -1 will move the unit from P12 to P1.
- The second argument can have the values 0 = MOVE_TO or 3 = SWARM_TO
- The third argument is, you guessed it the iScriptId of the unit.
- The fourth argument of the function is a string variable. In this case “P”. The string should contain the values of the waypoint name before the number. So is your waypoints are called “WP1”, WP2”, “WP3” then the value of the string should be “WP”
- The last argument is the number of point you want the unit to follow. In most cases you want the unit to follow all waypoints but if you enter the value 8 here then the unit will only follow 8 waypoints. Depending on the direction this would be P1 to P8 or P12 to P5.
Now the fun part is that this function can also be used to make a unit patrol on the map.
This can be done by checking if the unit reached the last waypoint and then call the function again with a changed direction. Remember you will have to put a Suicide () instruction in the function that called the FollowWaypointsTrail (…) function.
Another option is to put the last waypoint close to the first one. When then units reaches the last waypoint then it can start another patrol round. To do this you must not put Suicide () instruction in the function that is calling the FollowWaypointsTrail (…) function. If you opt to do this then you should run the function at intervals that are longer then the time it takes for the unit to patrol.
Should there be any interest then I can demonstrate the different methods. The function is free to use but I would appreciate it if you just let me know that you used it in a map.
Here's the function. 14 lines in total
function FollowWaypointsTrail (Direction, IAction, ScriptId, WayPoint, TotWayPoints)
-- Script by Quintaxel 18-12-12
-- Makes unit follow waypoints
-- Requires none
-- Callingprotocol: FollowWaypoint (Direction, IAction, ScriptId, WayPoint, TotWayPoints);
-- Variables
-- Direction 1 to follow the waypoints in ascending order or -1 to follow waypoints in decending order.
-- IAction: 0 = MOVE_TO or 3 = SWARM_TO
-- ScriptId: ScriptId of unit that needs to follow Waypoints
-- Waypoint: Name of the waypoint without waypoint number
-- TotWayPoints: Total number of wayopoints to follow.
local i, s, e;
if Direction == 1 then
s = 1;
e = TotWayPoints;
else
s = TotWayPoints;
e = 1;
end;
for i = s,e,Direction do
local x, y = GetScriptAreaParams (WayPoint.. i);
QCmd(IAction, ScriptId, x, y);
end;
end;