Mines Script converstion to JS

For AI and campaign script related discussions and questions
Post Reply
User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 269
Joined: 15 Apr 2018, 17:25
Location: United States.

Mines Script converstion to JS

Post by WZ2100ModsFAn » 14 Aug 2018, 23:20

I'm converting the landmine.vlo and landmine.slo to js.

And i need help with it @Berserk Cyborg

here's the conversion so far

Code: Select all

  /* Set debug value (below) to 1 only if this script has problems needing to be fixed
   *
   * When active, player's power level will hover around a value reflecting
   * the status of the script:
   *
   * 1000 -- no active mines on field
   * 1200 -- active mines nearby
   * 1300 -- player's VTOL flew over an active mine
   * 7770 -- Minesweeper removed a mine just now
   * 6660 -- KA-BOOM! Heh heh heh...
   *
   * 2000...2700 -- A certain type of mine didn't go off when stepped on
   * 2800...3000 -- Unable to determine type of mine player stepped on,
   *                (usually an error encoding the health stat of mine)
   *
   */

// ???
  actRange     INT   50

// ???
  setRange  INT   600

var Miner = "Cyb-Bod-MineSweep";

var Mine = "ContaMine";

var BuildMine = "ContaMine1";

var BuildMine = "ContaMine2";

var BuildMine = "ContaMine3";

var BuildMine = "ContaMine4";

var BuildMine = "ContaMine5";

var BuildMine = "ContaMine6";

var BuildMine = "ContaMine7";

var BuildMine = "ContaMine8";

var Fizzle = "ZNULLWEAPON";

var Blip = "ZNULLMINE";

var Explosion = "WepMine1";

var Explosion = "WepMine2";

var Explosion = "WepMine3";

var Explosion = "WepMine4";

var Explosion = "WepMine5";

var Explosion = "WepMine6";

var Explosion = "WepMine7";

var Explosion = "WepMine8";
The ??? means i don't understand how to convert that part of it.

and here's the landmines part of the .slo

Code: Select all

// Must do this to all players, for MP compatibility
player = 0;
while (player < 11)
{
  initGetFeature(Mine, player, selectedPlayer);
  testMine = getFeature(selectedPlayer);
  while (testMine != NULLOBJECT)
  {
    // Retrieve type & player info from the mine
    temp = testMine.health / 10;
    tempp = testMine.health - 10 * temp;

    // The player can see their own mines only.
    if (tempp > 4)
      {fireWeaponAtLoc(Blip, testMine.x, testMine.y);}

    target = droidTargetInArea(player, player, (testMine.x - actRange), (testMine.y - actRange), (testMine.x + actRange), (testMine.y + actRange));
    if (target != NULLOBJECT)
    {

      // Rule 1: Only ground units may detonate land mines.
      // (Also note that the mine layer borg does not "trip" them ;) )
      if ((target.z < testMine.z + 96) and (target.body != Miner[0]))
      {

        // Make sure only a mine can go boom.
        if (temp < 8)
        {
          if (target.body == Miner[1])
          {
            // Mine Sweeper 'borg gets lucky!
            fireWeaponAtObj(Fizzle, testMine);
          }
          else
          {
            // Anyone else, well... >B}
            fireWeaponAtObj(Explosion[temp], target);
          }
          destroyFeature(testMine);
        }
      }
    }
    testMine = getFeature(selectedPlayer);
  }
  player = player + 1;
}
the rest of .slo

Code: Select all

// Static variables defined in the VLO
private FEATURESTAT Mine;
private STRUCTURESTAT BuildMine[8];
private WEAPON Explosion[8];
private WEAPON Fizzle, Blip;
private BODY Miner[2];

// Used for tweaking and debugging
private  INT  setRange, actRange;

// Temporary script variables
private  INT  player;
private  INT  count;
private  INT  temp, tempp;
private  BOOL  NotReady;
private  STRUCTURE strucMine;
private  FEATURE testMine;
private  DROID target;

event CheckMines(every, 10)
i need to combine all of these into one js file.
Apologies if i dont see your post
central time usa

User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 626
Joined: 26 Sep 2016, 19:56

Re: Mines Script converstion to JS

Post by Berserk Cyborg » 16 Aug 2018, 17:12

Interesting idea. Well, here is what I made (not multiplayer safe). The mines will trigger if anything but a mine sweeper or vtol unit passes by one. And then a small amount of health is taken away from everything in range and a ground shaker shell is fired out of them for some potential splash damage.

Create a custom cyborg body and constructor weapon, a new template for the mine sweeper cyborg, and enable the components and mine structure through whatever research you choose. Then include the file in rules.js and add a setTimer("checkMines", 800) next to the other timers in eventGameInit. Timers are in milliseconds so be sure to experiment with that.
Mines.wz
(1.49 KiB) Downloaded 9 times

User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 269
Joined: 15 Apr 2018, 17:25
Location: United States.

Re: Mines Script converstion to JS

Post by WZ2100ModsFAn » 16 Aug 2018, 21:50

Berserk Cyborg wrote:Interesting idea. Well, here is what I made (not multiplayer safe). The mines will trigger if anything but a mine sweeper or vtol unit passes by one. And then a small amount of health is taken away from everything in range and a ground shaker shell is fired out of them for some potential splash damage.

Create a custom cyborg body and constructor weapon, a new template for the mine sweeper cyborg, and enable the components and mine structure through whatever research you choose. Then include the file in rules.js and add a setTimer("checkMines", 800) next to the other timers in eventGameInit. Timers are in milliseconds so be sure to experiment with that.
Mines.wz
So how do i var multiple mines at once?

Like this?

var mines = enumStruct(i, MINE_01.structure && MINE_01.structure);

there's 8 mines in total.
Apologies if i dont see your post
central time usa

User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 626
Joined: 26 Sep 2016, 19:56

Re: Mines Script converstion to JS

Post by Berserk Cyborg » 16 Aug 2018, 22:36

If there are multiple mines I would then turn MINE_01 into an array of objects, rename it to MINES, loop through the MINES array, and enumerate the structure property of each object via enumStruct(). By doing that it allows for easier modding. Probably should have done that in the first place since I did that with the mine sweeper cyborgs.
Mines.wz
(1.62 KiB) Downloaded 7 times

User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 269
Joined: 15 Apr 2018, 17:25
Location: United States.

Re: Mines Script converstion to JS

Post by WZ2100ModsFAn » 17 Aug 2018, 00:31

Berserk Cyborg wrote:If there are multiple mines I would then turn MINE_01 into an array of objects, rename it to MINES, loop through the MINES array, and enumerate the structure property of each object via enumStruct(). By doing that it allows for easier modding. Probably should have done that in the first place since I did that with the mine sweeper cyborgs.
Mines.wz
The explosion is actually using the wepmine

for example

const EXPLODE_WEAPON = [
{weapon: "WepMine1"},
{weapon: "WepMine2"},
{weapon: "WepMine3"},
{weapon: "WepMine4"},
{weapon: "WepMine5"},
{weapon: "WepMine6"},
{weapon: "WepMine7"},
{weapon: "WepMine8"},
];

but will this use these for each mine instead of randomly?
Apologies if i dont see your post
central time usa

User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 626
Joined: 26 Sep 2016, 19:56

Re: Mines Script converstion to JS

Post by Berserk Cyborg » 17 Aug 2018, 01:38

You would need to pair it with the variable used to loop through the mines array which would be unnecessary. I made the script better so that you can modify the alert and trigger distances, choose the mine weapon, choose the fizzle/blip weapon, and percentage of health that is automatically removed from units for as many type of mines you create.
Mines.wz
(1.87 KiB) Downloaded 7 times

User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 269
Joined: 15 Apr 2018, 17:25
Location: United States.

Re: Mines Script converstion to JS

Post by WZ2100ModsFAn » 17 Aug 2018, 02:08

Berserk Cyborg wrote:You would need to pair it with the variable used to loop through the mines array which would be unnecessary. I made the script better so that you can modify the alert and trigger distances, choose the mine weapon, choose the fizzle/blip weapon, and percentage of health that is automatically removed from units for as many type of mines you create.
Mines.wz
Thanks that'll do for now :)
Apologies if i dont see your post
central time usa

Post Reply