This is split off from a posting in the forums for the Homeworld mod.
I'm trying to use scripting to figure out the best way to make a proximity mine that doesn't just detonate, but will move in to chase a target if it gets too close. I was pointed to
this script as a starting point. None of the functions in that script work as they're all outdated.
Wondering what I missed, I then went to the scripting tutorial and that too is out of date. This is frustrating as without the examples working, I can't seem to make sense of the scripting output for the 3.6.12 build and 3.6.13 update.
Basically, here's what I would like the following script to do, and I've posted it here from the wiki page.
1) When a mine is dropped off from a player ship, it waits until it is armed (either by arming in the table or in the script)
2) If the mine is armed, get the name of it to see if its a homing mine
3) If it's a mine, see what team it's on
4) Check the distance from it to other ships
5) If a target ship is within 1200 meters and on the enemy team, set the lifetime of the mine to 60 seconds and have it lock on to whatever triggered it
If that can't be done, I would settle for setting the weapon's target to the ship, and then detonating it so a spawn weapon could go chase it using the "inherit parent target" flag in the table.
#Global Hooks
$Simulation:
[
--Get all weapons
for i=1,mn.getNumWeapons() do
weapon = mn.getWeaponByIndex(i)
weapontype = weapon.Class.Name
--Select only mines
if weapontype == "Helios" then
weaponlife = weapon.LifeLeft
--Select only those mines that have been activated (time activation)
if weaponlife < 25 then
weaponteam = weapon.Team
--Start building distance array
for m=1,mn.getNumShips() do
ship = mn.getShipByIndex(m)
shipteam = ship.Team
weaponposition = weapon.Position
shipposition = ship.Position
shipdistance = weaponposition:getDistance(shipposition)
if shipteam ~= weaponteam and shipdistance < 1000 then
weapon.LifeLeft = 0
end
end
end
end
end
]
#End
I'm just learning how to script but the wiki as it stands is much more confusing than helpful