Modding, Mission Design, and Coding > The Scripting Workshop

Automatic gun convergence

(1/1)

Wanderer:
So here it is.. via scripting though and not directly via code... Ogg theora video clip to you first


--- Code: ---#Global Hooks

$Simulation:

[

missiontime = mn.getMissionTime()

if missiontime > 0.5 then
   tableAutoGunC = nil
   tableAutoGunC = {}
   for o = 1,#mn.Ships do
      vectorShipCenter = ba.createVector(0,0,0)
      ship = mn.Ships[o]
      stringShipClass = ship.Class.Name
      -- Set class specific convergence centers here with
      -- if shipclass == "shipclass" then
      --    vectorShipCenter = ba.createVector(x,y,0)
      -- end
      vectorShipPosition = ship.Position
      vectorTargetDistance = ba.createVector(0,0,500)
      if ship.Target ~= nil and ship.Target ~= false and ship.Target:getBreedName() ~= (null) then
         shipTarget = ship.Target
         vectorTargetPosition = shipTarget.Position
         numberDistance = vectorTargetPosition:getDistance(vectorShipPosition)
         if numberDistance > 1000 then
            vectorTargetDistance[3] = 1000
         elseif numberDistance < 100 then
            vectorTargetDistance[3] = 100
         else
            vectorTargetDistance[3] = numberDistance
         end
      end
      vectorConvergenceTarget = vectorTargetDistance + vectorShipCenter
      tableAutoGunC[o] = vectorConvergenceTarget
   end
   for k=1,#mn.Weapons do
      local weapon = mn.Weapons[k]
      local stringWeaponClass = weapon.Class.Name
      local numberWeaponLife = weapon.LifeLeft
      if stringWeaponClass == "Corona" and numberWeaponLife > 0.2 then
         local vectorWeaponPosition = weapon.Position
         tableShipList = nil
         tableShipList = {}
         tableShooterList = nil
         tableShooterList = {}
         for j = 1,#mn.Ships do
            local shooter = mn.Ships[j]
            local vectorShooterPosition = shooter.Position
            local vectorShooterRelativePosition = vectorWeaponPosition - vectorShooterPosition
            local numberShooterDistance = math.floor(vectorShooterRelativePosition:getMagnitude())
            table.insert(tableShipList,numberShooterDistance)
            table.insert(tableShooterList,numberShooterDistance,j)
            table.sort(tableShipList)
         end
         numberNewDistance = tableShipList[1]
         numberNewIndex = tableShooterList[numberNewDistance]
         newshooter = mn.Ships[numberNewIndex]
         orientationWeapon = weapon.Orientation
         vectorWeaponConvergenceTarget = tableAutoGunC[numberNewIndex]
         if vectorWeaponConvergenceTarget ~= "false" then
            orientationShooter = newshooter.Orientation
            vectorShooterPosition = newshooter.Position
            vectorWeaponTargetDirection = orientationShooter:unrotateVector(vectorWeaponConvergenceTarget)
            vectorWeaponConvergenceDirection = vectorShooterPosition - vectorWeaponPosition + vectorWeaponTargetDirection
            orientationWeapon = vectorWeaponConvergenceDirection:getOrientation()
         end
         weapon.LifeLeft = 0
         mn.createWeapon(tb.WeaponClasses["Halo"],orientationWeapon,vectorWeaponPosition,newshooter,-1)
      end
   end
end

]

#End
--- End code ---

Navigation

[0] Message Index

Go to full version