Ravenfield

Ravenfield

114 ratings
automatic CIWS and Missile turret
   
Award
Favorite
Favorited
Unfavorite
Content Type: Vehicles
File Size
Posted
1.813 MB
21 May, 2022 @ 6:56pm
1 Change Note ( view )

Subscribe to download
automatic CIWS and Missile turret

Description
Modified attack boat with CIWS and Missile turret.

CIWS automically attacks neraby aircrafts, but when the missile is detected it tries to intercept it (not always successful due to bullet spread)

Missile turret automically launch missiles to nearby aircrafts.

Consider this as a teaser of the Vanilla+ battleship mod Sofa is going to make.






behaviour("ciwsship")
function ciwsship:Start()
self.vehicle = self.gameObject.GetComponent(Vehicle)
self.tgt=nil
self.msltgt=nil
self.cooldown=0
end

function ciwsship:Update()
if self.vehicle.hasDriver then

self.msltgt=nil
local ac=ActorManager.AliveActorsInRange(self.targets.mslturret.transform.position,900)
if #ac>0 then
for i = 1, #ac do
if ac.team~=self.vehicle.driver.team and ActorManager.ActorCanSeePlayer(ac) and ac.activeVehicle~=nil and (ac.activeVehicle.isHelicopter or ac.activeVehicle.isAirplane) and (self.msltgt==nil or Vector3.distance(ac.transform.position,self.targets.mslturret.transform.position)<Vector3.distance(self.msltgt.transform.position,self.targets.mslturret.transform.position) ) then
self.msltgt=ac.activeVehicle
end
end
end

local mslrot=self.vehicle.transform.rotation

if self.msltgt~=nil then
mslrot=Quaternion.LookRotation(self.msltgt.transform.position-self.targets.mslturret.transform.position,self.vehicle.transform.up)

if Vector3.Angle(self.msltgt.transform.position - self.targets.mslturret.transform.position, self.targets.mslturret.transform.forward) <= 1 then
local wep = self.vehicle.seats[1].weapons[1]
wep.Unholster()
wep.Shoot(false)
end

end

self.targets.mslturret.transform.rotation=Quaternion.RotateTowards(self.targets.mslturret.transform.rotation, mslrot, 180 * Time.deltaTime)

local ismsl=false
self.tgt=nil
if self.vehicle.isTrackedByMissile then
local msl = self.vehicle.GetTrackingMissiles()
for i=1,#msl do
if self.tgt==nil or Vector3.distance(msl.transform.position,self.targets.turret.transform.position)<Vector3.distance(self.tgt.transform.position,self.targets.turret.transform.position) then
self.tgt=msl
ismsl=true
end
end
else
local ac=ActorManager.AliveActorsInRange(self.targets.turret.transform.position,500)
if #ac>0 then
for i = 1, #ac do
if ac.team~=self.vehicle.driver.team and ActorManager.ActorCanSeePlayer(ac) and ac.activeVehicle~=nil and (ac.activeVehicle.isHelicopter or ac.activeVehicle.isAirplane) and (self.tgt==nil or Vector3.distance(ac.transform.position,self.targets.turret.transform.position)<Vector3.distance(self.tgt.transform.position,self.targets.turret.transform.position) ) then
self.tgt=ac
end
end
end
end

local gyrorot=self.vehicle.transform.rotation

if self.tgt~=nil then

local tgtpos=self.tgt.transform.position+self.tgt.transform.up*0.65
local tgtspd=self.tgt.velocity
local bulletspd=350

local gyroguidepos=tgtpos
for i=1,5 do
gyroguidepos=tgtpos + (Vector3.distance(gyroguidepos,self.targets.muzzle.transform.position)/bulletspd)*( tgtspd )
end

if self.cooldown==0 and Vector3.Angle(gyroguidepos - self.targets.muzzle.transform.position, self.targets.muzzle.transform.forward) <= 1 then
local blt=self.gameObject.Instantiate(self.targets.bullet, self.targets.muzzle.transform.position,Quaternion.Euler(self.targets.muzzle.transform.eulerAngles.x-1+2*math.random(),self.targets.muzzle.transform.eulerAngles.y-1+2*math.random(),self.targets.muzzle.transform.eulerAngles.z))
if ismsl==true then
local bltsc=self.script.GetScript(blt.gameObject)
bltsc.tgtmsl=self.tgt
end

blt=blt.gameObject.GetComponent(Projectile)
blt.source=self.vehicle.driver
local snd=self.targets.muzzle.gameObject.GetComponent(AudioSource)
snd.play()
self.cooldown=0.05
end

gyrorot=Quaternion.LookRotation(gyroguidepos-self.targets.turret.transform.position,self.vehicle.transform.up)

if self.cooldown>0 then
self.cooldown=self.cooldown-Time.deltaTime
if self.cooldown<=0 then
self.cooldown=0
end
end

end

self.targets.turret.transform.rotation=Quaternion.RotateTowards(self.targets.turret.transform.rotation, gyrorot, 180 * Time.deltaTime)

end
end
Popular Discussions View All (1)
2
30 Apr, 2024 @ 3:26am
Download my toolspack
Hijong park
34 Comments
Sir Pasta 25 Jul, 2024 @ 5:41pm 
This doesn't work anymore, the textures are missing and the CIWS only fires one shot ever few seconds.
SleepDeprivedJanitor :3 5 Sep, 2022 @ 5:04am 
You should collab with other content creators for modern ships like the type 55 destroyer
HonNguyn_ 9 Aug, 2022 @ 8:00pm 
mortar pls
Hijong park  [author] 11 Jul, 2022 @ 1:06am 
not that hard once you figure out the logic
Don'tknowwhattoput 11 Jul, 2022 @ 12:45am 
How long did it take for a automatic AI gunner to just shoot down missiles and planes, also how painful is it to make it
Hijong park  [author] 31 May, 2022 @ 1:50pm 
Not possible because changing engine value via script has no effect
Gazzer 31 May, 2022 @ 8:06am 
would it be possible to make the rotors and propellers on planes and helicopters continue spinning even after when the vehicle is disabled or there is no pilot and the vehicle is currently in the air? when a pilot ejects out of their vehicle the engine turns off automatically and it bothers me a tad bit
Hijong park  [author] 30 May, 2022 @ 3:46am 
The new rhino isn't in toolspack
Gazzer 30 May, 2022 @ 2:53am 
could you do a modded version of the vanilla rhino tank where its turret ejects into the air when destroyed? i tried out beta 5 earlier and wondered why steel didnt add it to the current rhino
Hijong park  [author] 28 May, 2022 @ 2:16am 
That's something map designers should improve