From The Depths

From The Depths

评价数不足
Basic Top-Attack Lua Missiles
   
奖励
收藏
已收藏
取消收藏
Blueprints: #blueprint, Lua, Missile
标签: fortress
文件大小
发表于
13.820 KB
4 月 26 日 下午 5:45
1 项改动说明 ( 查看 )

订阅以下载
Basic Top-Attack Lua Missiles

描述
Basic Lua script for top attack missiles. It is made to be as light as possible, so it doesn't have a lot of bells and whistles. Perfect for Lua missile spam without being too laggy. It has basic prediction guidance and the option of spreading the missiles out over a large area for resistance against CIWS and interceptors.

This was made for the Chorus CC but I'm uploading it to the workshop out of popular demand.

Here is the script itself if you don't want to go through the hassle of downloading the craft:

-- CONFIG OPTIONS --

turnrate = 50
--put the missile turnrate here
--it is a really good idea to lowball your turn rate

--turnrate controls how aggressively it handles the top-down attacks
--low turnrate = less topdown, more turnrate = more topdown

padnames = "the"
--the name of EACH CONTROLLED MISSILE LAUNCH-PAD
--remember to leave '' around the name 'like so'

maxspread = 500
--the missile spread distance in meters
--this is evasive spread, not aimpoint spread

mainframeindex = 0
--leave this at 0 unless you have multiple AIs
--afaik index goes from 0 up with the priority of mainframes (prio 500 is 0, prio 100 is 1, prio -300 is 2, etc)
--it could also be the order of placement, idk for sure


-- END OF CONFIG --


function Update(I)
I:Log('tachyon6271 was here')
for a = 0, I:GetLuaTransceiverCount()-1 do

if I:GetLuaTransceiverInfo(a).CustomName == padnames
then --only control missiles if they match the launchpad name

for b = 0, I:GetLuaControlledMissileCount(a)-1 do
-- going through each missile (provided they match the name)
-- and telling them where to go

local missileinfo = I:GetLuaControlledMissileInfo(a, b)


turnrate = Mathf.Clamp(turnrate, 0, 70)
local aimpoint = I:GetTargetInfo(mainframeindex, 0).AimPointPosition
local missilepos = I:GetLuaControlledMissileInfo(a,b).Position
local missilespeed = I:GetLuaControlledMissileInfo(a,b).Velocity
local enemyspeed = I:GetTargetInfo(mainframeindex,0).Velocity
local mypos = I:GetConstructPosition()

if enemyspeed.magnitude > 170 then enemypos = I:GetTargetPositionInfo(mainframeindex, 0).Position
else enemypos = I:GetTargetInfo(0,0).AimPointPosition
end --if the enemy is really fast, aim at their COM rather than ai aimpoint

local relativepos = missilepos - enemypos
local relativespeed = missilespeed - enemyspeed
local time = math.min((relativepos.magnitude / relativespeed.magnitude), 5)
local predictedaimpoint = enemypos + enemyspeed * time - ((missilespeed / 5) * time)
local turnrateovertime = turnrate * time
local angle = math.abs(90 - math.acos((predictedaimpoint - missilepos).y / (predictedaimpoint - missilepos).magnitude) * (180 / math.pi))
local posmodifier = 0
local posmodifer2 = 0
local spreadterm = 0


if predictedaimpoint.y > 400 then posmodifier2 = -200
else posmodifier2 = 600
end--top-attack if enemy is low, bottom-attack if they are high

if posmodifier2 == -200 then angle = angle + 90 end
-- if we are in bottom attack mode, then measure angle differently

if (turnrateovertime - (turnrateovertime / 1.3) < angle) or (angle > 65) then posmodifier = 0
else posmodifier = posmodifier2
end--top attack until we can no longer manage it


if (mypos-enemypos).magnitude > relativepos.magnitude*2
or I:GetLuaControlledMissileInfo(a, b).TimeSinceLaunch > 10

then spreadterm = 0
else spreadterm = maxspread / (I:GetLuaTransceiverCount() * I:GetLuaControlledMissileCount(a)) end
--dividing the missiles evenly over the max spread area

if spreadterm == 0
then spread = 0
else spread = (spreadterm - (spreadterm * ( (a+1) * (b+1) ) - maxspread))
end --each subsequent missile is +1 spreadterm away from the last


vector = Vector3(predictedaimpoint.x + spread * math.sin(missileinfo.Azimuth), predictedaimpoint.y + posmodifier + spread / 10, predictedaimpoint.z + spread * math.cos(missileinfo.Azimuth))
--predicted aimpoint + spread + altitude modifier

I:SetLuaControlledMissileAimPoint(a, b, vector.x, vector.y, vector.z)

end
end
end
end
15 条留言
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 6:14 
oh
nevermind then
Tachyon  [作者] 7 月 13 日 上午 6:12 
That is what this Lua does. Just set the turn rate to really low (like 5-10) and it will do that

(This Lua bases trajectory on time until impact rather than distance though, but it should not make a difference)
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 6:10 
it basically controld the trajectory of the missile according ro target distance etc
Tachyon  [作者] 7 月 13 日 上午 6:07 
what does ballistic missile Lua do
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 6:06 
would it be possible for ya to make a Ballistic missilu LUA?
the only one i found is only kinda working and quite hard to understnad
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 6:05 
yeah i found that out quite quickly by just looking at the keybind list but thx anyways
Tachyon  [作者] 7 月 13 日 上午 5:57 
lol

press shift + n on the launchpad and change the name to whatever you made the name in the lua (spaces and caps included)
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 4:30 
nvm my brain is just smooth like a mirror
𝖍𝖆𝖓𝖘 (hans) 7 月 13 日 上午 4:25 
how do i change the name of launchpads tho
i cant for the love of god figurethat out
Tachyon  [作者] 6 月 9 日 上午 5:31 
These are designed to be absolutely as computationally cheap as possible- the only FPS loss you get from it are the rendered missiles.