Minefields via LUA script

Kevin Caccamo

Rear Admiral
The code below is a script function that attempts to create a minefield. I call it at the beginning of a navpoint where I want the minefield.

Code:
function minefield()
 Mission_setDebugText("minefield function called")
 navseq = navseq + 1;
 mines = 30;
 while mines > 0 do
  xpos = math.random(-500,500);
  ypos = math.random(-500,500);
  zpos = math.random(-500,500);
  Mission_addShip("minelayer", "", "", false, "Mine", IFF_ENEMY, xpos, ypos, zpos, "amine", "", "", "");
  mines = mines - 1;
  Mission_setDebugText("mine created")
 end
 if mines == 0 then
  Mission_setDebugText("done")
 end
end

When I enter the navpoint, it just says "done" and does not create any mines or "minefield" ships. Am I doing something wrong here?
 
I haven't tried it, but here's what I see. The scriptid needs to be unique for each mine.

My suggestion is that you wait on the mines. You might be able to script in a small number, but I suspect that the engine performance will be terrible. I think I'd need to boost performance in a similar way to what I do for asteroids. Save these till later, there's plenty to do with the engine as it is. I'd love to see conversations. It would also be fun to see the proper movies scripted in after a
mission, depending on the damange and on which ship was flown. Also, showing a special debriefing movie for each mission would be fun.
 
Is it possible to manipulate a ship from a value in a variable?

Code:
whatever = "Ship1%"
float Ship_getHitPoints(whatever)

If true then it could be something like:

Code:
FOR Index 1 to 50 DO
Mission_addShip("minelayer, "", "", false, "Mine", IFF_ENEMY, xpos, ypos, zpos, index, "", "", "");
ENDFOR
 
Eddieb, even if I make an individual Mission_addShip function for each mine, it does not work.

And BTW, good idea, Kyran
 
The following code created the mines as expected:

But beware, they don't behave as you'd expect. They're ships after all, and behave like ships.

Code:
function createMines()
 mines = 20
 while mines > 0 do
  xpos = math.random(-500,500);
  ypos = math.random(-500,500);
  zpos = math.random(-500,500);
  Mission_addShip("minelayer", "bug1", "bug", false,  "Unknown", IFF_ENEMY,xpos,  ypos, zpos, "$mine" .. tostring(mines) , "", "", "");
  mines = mines - 1;
 end

end
 
Back
Top