bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,362
|
Post by bb on Apr 12, 2024 13:59:52 GMT 1
Hello script masters.
Anyone here has a simple script to make a number of units to follow a path patrolling an area? Thanks, BB
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Apr 12, 2024 22:45:19 GMT 1
I often use the following, copied from someone i can't remember:
function Patrol1() local i = GetIGlobalVar("temp.points1", 0); if (GetNUnitsInScriptGroup(110) > 0) then if (GetNScriptUnitsInArea(110, "Patrol1" .. i) > 0) then RunScript("Patrol1I", RandomInt(5000) + 3000 ); Suicide(); end; else Suicide(); end; end; function Patrol1I() local i = GetIGlobalVar("temp.points1", 0) + 1; if (i > 4) then i = 1; end; if (GetNUnitsInScriptGroup(110) > 0) then Cmd(3, 110, GetScriptAreaParams("Patrol1" .. i )); RunScript("Patrol1", 2000); SetIGlobalVar("temp.points1", i); end; Suicide(); end; function Patrol2() local i = GetIGlobalVar("temp.points2", 0); if (GetNUnitsInScriptGroup(111) > 0) then if (GetNScriptUnitsInArea(111, "Patrol2" .. i) > 0) then RunScript("Patrol2I", RandomInt(5000) + 3000 ); Suicide(); end; else Suicide(); end; end; function Patrol2I() local i = GetIGlobalVar("temp.points2", 0) + 1; if (i > 4) then i = 1; end; if (GetNUnitsInScriptGroup(111) > 0) then Cmd(3, 111, GetScriptAreaParams("Patrol2" .. i )); RunScript("Patrol2", 2000); SetIGlobalVar("temp.points2", i); end; Suicide(); end;
The above shows 2 patrols, just to show you have to change temp.points as well.
So for Patrol1, you can draw areas in the MapEditor, which you name Patrol11, Patrol12, Patrol13 and Patrol14. Why 4? > because 'if (i > 4) then' is set to 4. If you change it f.i. to 9, you could draw 9 areas (up unto Patrol19).
When you want to start the patrol, i rather use the RunScript("Patrol1I"); instead of RunScript("Patrol1"); to avoid starting problems. In the first case, you can place the unit anywhere and will go to Patrol11 and then proceed. In the latter, i think you have to place the unit already precisely in the Patrol11 area, i think... i should test it, but i remember having problems when i used RunScript("Patrol1");.
Units have ScriptID's of course, in this case 110 for Patrol1 and 111 for Patrol2. I always tend to use 1 unit instead of a number of units, because when using multiple, they will all go to the center of the area (where the area name shows) and that's creating a mess. Moreover, if some units get behind or stuck, the first unit(s) arriving in the area will go to the next, but the others will just stop moving.
As you can see, the above script is very mathematical as it checks where the unit is and goes to the following area number. In your case, for a number of units, i would advice to copy the script for each single unit with a different ScriptID. I know, it's more work, but your units will behave less prone to errors.
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,362
|
Post by bb on Apr 13, 2024 2:22:57 GMT 1
Wonderful, that's exactlty what I want to do do. By the way, this is for a new version for my old and poorly designed chapter Operation Uranus for PZWF (or PW, LOL). I hope you will find it decent enough for your site, Kaoz.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Apr 14, 2024 0:10:34 GMT 1
On second thought, i believe it comes from a lua script generated by BK itself when you create a random map...
I guess it's an upgrade of Uranus Aftermath, right? Your work has always been decent enough, bb, i do not doubt that. If some of your maps/chapters are not on the site, i think it's because i didn't have the correct mod or else i might have missed it...
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,362
|
Post by bb on Apr 16, 2024 0:39:25 GMT 1
On second thought, i believe it comes from a lua script generated by BK itself when you create a random map...I guess it's an upgrade of Uranus Aftermath, right? Your work has always been decent enough, bb, i do not doubt that. If some of your maps/chapters are not on the site, i think it's because i didn't have the correct mod or else i might have missed it... I think the original Operation Uranus is not in the site. But dont worry, that version was awful. The new version is lot better (I promisse), maps and scripts were improved and I changed two of the original maps for new ones.
|
|