Modding, Mission Design, and Coding > The Scripting Workshop

Actually useful bomber turrets

(1/3) > >>

Wanderer:
So fighter/bomber turrets that actually track the closest enemy ship instead of targetting the bombers current target.


--- Code: ---#Global Hooks

$Simulation:

[

missiontime = mn.getMissionTime()

if missiontime > 0.5 then
   for r = 1,#mn.Ships do
      bomber = mn.Ships[r]
      stringBomberType = bomber.Class.Type.Name
      vectorBomberPosition = bomber.Position
      teamBomber = bomber.Team.Name
      if stringBomberType == "Bomber" or stringBomberType == "Fighter" then
         numberBomberSubsystems = #bomber
         for t =1,numberBomberSubsystems do
            subsystemBomber = bomber[t]
            stringBomberSubsystem = subsystemBomber:getName()
            if stringBomberSubsystem == "laser turret" then
               tableTargetDistance = nil
               tableTargetDistance = {}
               tableTargetOrder = nil
               tableTargetOrder = {}
               for g=1,#mn.Ships do
                  target = mn.Ships[g]
                  teamTarget = target.Team.Name
                  if teamTarget ~= teamBomber then
                     vectorTargetPosition = target.Position
                     numberTargetDistance = math.floor(vectorBomberPosition:getDistance(vectorTargetPosition))
                     tableTargetDistance[numberTargetDistance] = target
                     table.insert(tableTargetOrder,numberTargetDistance)
                  end
               end
               table.sort(tableTargetOrder)
               if tableTargetOrder[1] ~= nil then
                  numberNewTargetDistance = tableTargetOrder[1]
                  newtarget = tableTargetDistance[numberNewTargetDistance]
                  if newtarget ~= nil then
                     subsystemBomber.Target = newtarget
                  end
               end
            end
         end
      end
   end
end

]

#End
--- End code ---

Script can be easily changed into shipclass specific.

Grizzly:
LUA ERROR: [string "Simulation"]:13: attempt to call method 'getName' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

------------------------------------------------------------------
Could not find index 'getName' in type 'subsystem'

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

1: Userdata [subsystem]
2: String [getName]
------------------------------------------------------------------

LUA ERROR: [string "Simulation"]:13: attempt to call method 'getName' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

------------------------------------------------------------------
Could not find index 'getName' in type 'subsystem'

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

1: Userdata [subsystem]
2: String [getName]
------------------------------------------------------------------
LUA ERROR: [string "Simulation"]:13: attempt to call method 'getName' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

------------------------------------------------------------------
Could not find index 'getName' in type 'subsystem'

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   (null)
Function type:   (null)
Defined on:   0
Upvalues:   0

Source:      (null)
Short source:   
Current line:   0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

1: Userdata [subsystem]
2: String [getName]
------------------------------------------------------------------


and some more...

WMCoolmon:
You need to change

--- Code: ---            stringBomberSubsystem = subsystemBomber:getName()
--- End code ---
to

--- Code: ---            stringBomberSubsystem = subsystemBomber.Name
--- End code ---

Bob-san:
I never found anything wrong with my Ursa's turret--the Kayser works excellently. I have had so many kills with a turret when playing various bomber missions--I have received over 100% accuracy several times because of the turret making the annoying kills (like keeping a Ulysses above me, the turret takes care of it and keeps it from making a run).

Whatever-I'll look at this code I guess.

Bobboau:
I'll have to remember this BWO could probably use this for the Vanir.

Navigation

[0] Message Index

[#] Next page

Go to full version