Ravenfield

Ravenfield

Ghost of raven
Hijong park  [developer] 4 May, 2022 @ 10:56pm
Source code
behaviour("dogfighttrain") function dogfighttrain:Awake() GameEvents.onActorSpawn.AddListener(self, "OnActorSpawn") GameEvents.onActorDied.AddListener(self, "OnActorDied") GameEvents.onVehicleDestroyed.AddListener(self, "OnVehicleDestroyed") GameEvents.onVehicleDisabled.AddListener(self, "OnVehicleDisabled") local ally=ActorManager.GetActorsOnTeam(Player.enemyTeam) if #ally<30 then for i=1,30-#ally do ActorManager.CreateAIActor(Player.enemyTeam) end end local ally=ActorManager.GetActorsOnTeam(Player.team) if #ally<10 then for i=1,10-#ally do ActorManager.CreateAIActor(Player.team) end end for i=1,#ActorManager.actors do if ActorManager.actors[i].isBot then ActorManager.actors[i].Deactivate() end end self.text=self.targets.text.GetComponent(Text) self.enemy=ActorManager.GetActorsOnTeam(Player.enemyTeam) self.wave=0 self.begindelay=-1 self.allyplus=0 end function dogfighttrain:OnActorSpawn(actor) if actor.isPlayer then self.text.text="get on the aircraft to start" self.wave=0 for i=1,#self.enemy do if self.enemy[i].isDead==false and self.enemy[i].activeVehicle~=nil then self.enemy[i].activeVehicle.Damage(nil,10000) self.enemy[i].KillSilently() end end end end function dogfighttrain:OnActorDied(actor) if actor.isPlayer then self.text.text="killed in action" self.begindelay=-1 end end function dogfighttrain:OnVehicleDestroyed(vehicle,info) for i=1,#self.enemy do if self.enemy[i].isDead==false and self.enemy[i].activeVehicle==nil then self.enemy[i].Damage(Player.actor,500,100,true,true) end end end function dogfighttrain:OnVehicleDisabled(vehicle,info) for i=1,#vehicle.seats do if vehicle.seats[i].isOccupied then vehicle.seats[i].occupant.Damage(info.sourceActor,500,100,true,true) end end end function dogfighttrain:Update() if Player.actor.activeVehicle~=nil and self.allyplus==0 then self.allyplus=1 local passengers = {} local passengerCount = 0 local allys=ActorManager.GetActorsOnTeam(Player.team) for i = 2, #Player.actor.activeVehicle.seats do if #Player.actor.activeVehicle.seats[i].weapons ~= 0 then passengerCount = passengerCount+1 end end for i = 1, #allys do if passengerCount>0 and allys[i].isDead then passengerCount = passengerCount-1 passengers[#passengers+1] = allys[i] end end for i = 1, #passengers do passengers[i].SpawnAt(Vector3(0,0,0)) Player.actor.squad.AddMember(passengers[i]) passengers[i].EnterVehicle(Player.actor.activeVehicle) end end if Player.actor.activeVehicle==nil and self.allyplus~=0 then self.allyplus=0 local allys=ActorManager.GetActorsOnTeam(Player.team) for i=1,#allys do if allys[i].isBot then allys[i].KillSilently() end end end if self.begindelay==-1 and Player.actor.activeVehicle~=nil and (Player.actor.activeVehicle.isAirplane or Player.actor.activeVehicle.isHelicopter) then self.begindelay=3 self.wave=self.wave+1 self.text.text="ATTACK WAVE "..self.wave local planenum=0 local bombernum=0 local helinum=0 if self.wave==1 then planenum=1 end if self.wave==2 then planenum=2 end if self.wave==3 then planenum=2 helinum=1 end if self.wave==4 then planenum=2 helinum=2 end if self.wave==5 then planenum=3 helinum=2 end if self.wave==6 then planenum=3 helinum=2 bombernum=1 end if self.wave==7 then planenum=4 helinum=3 bombernum=1 end if self.wave==8 then planenum=4 helinum=4 bombernum=2 end if self.wave==9 then planenum=4 helinum=4 bombernum=3 end if self.wave>=10 then planenum=4 helinum=4 bombernum=4 end if planenum>0 then for i=1,planenum do self:spawnenemy(0) end end if bombernum>0 then for i=1,bombernum do self:spawnenemy(2) end end if helinum>0 then for i=1,helinum do self:spawnenemy(1) end end end if self.begindelay==0 and ActorManager.IsTeamDead(Player.enemyTeam) then self.begindelay=-4 self.text.text="ATTACK WAVE COMPLETED" if Player.actor.activeVehicle~=nil then Player.actor.activeVehicle.Repair(Player.actor.activeVehicle.maxHealth/2) end end if self.begindelay>0 then self.begindelay=self.begindelay-Time.deltaTime if self.begindelay<=0 then self.begindelay=0 self.text.text="" end end if self.begindelay<-1 then self.begindelay=self.begindelay+Time.deltaTime if self.begindelay>=-1 then self.begindelay=-1 self.text.text="" end end end function dogfighttrain:spawnenemy(t) local ty=VehicleSpawnType.AttackPlane if t==1 then ty=VehicleSpawnType.AttackHelicopter end if t==2 then ty=VehicleSpawnType.BomberPlane end local spawnpos=Vector3(0,0,0) local colck=false local vtype=VehicleSpawner.GetPrefab(Player.enemyTeam,ty).gameObject.GetComponent(Vehicle) local spheight=150 if vtype.isHelicopter then spheight=75 end while spawnpos==Vector3(0,0,0) or colck==true do spawnpos=Vector3(Minimap.camera.transform.position.x+500-(1000*math.random()),Minimap.camera.transform.position.y,Minimap.camera.transform.position.z+500-(1000*math.random())) local spray = Physics.Raycast(Ray(spawnpos,Vector3(0,-1,0)), 5000, RaycastTarget.ProjectileHit) local spdst=5000 if spray ~= nil then spdst=spray.distance end spawnpos=spawnpos-Vector3(0,spray.distance-spheight-(50*math.random()),0) colck=false for i=1,#ActorManager.actors do if ActorManager.actors[i].isDead==false and Vector3.distance(spawnpos,ActorManager.actors[i].transform.position)<=10 then colck=true end end end local plane=VehicleSpawner.SpawnVehicle(Player.enemyTeam,ty,spawnpos,Quaternion.Euler(0,math.random(360),0)) plane.rigidbody.AddForce(plane.transform.up*3000,ForceMode.Acceleration) plane.engine.powerGainSpeed=50 plane.engine.pitchGainSpeed=50 plane.engine.throttleGainSpeed=50 for i=1,#plane.seats do if #plane.seats[i].weapons>0 then for i2=1,#plane.seats[i].weapons do if plane.seats[i].weapons[i2].effectivenessAir==Effectiveness.No then plane.seats[i].weapons[i2].effectivenessAir=Effectiveness.Yes end if plane.seats[i].weapons[i2].effectivenessAirFastMover==Effectiveness.No then plane.seats[i].weapons[i2].effectivenessAirFastMover=Effectiveness.Yes end end end end local passengers = {} local passengerCount = 0 for i = 1, #plane.seats do if #plane.seats[i].weapons ~= 0 then passengerCount = passengerCount+1 end end for i = 1, #self.enemy do if passengerCount>0 and self.enemy[i].isDead then passengerCount = passengerCount-1 passengers[#passengers+1] = self.enemy[i] end end local tgtpoint=math.random(1,#ActorManager.spawnPoints) local tgtpoint2=tgtpoint local ran=math.random(1,#ActorManager.spawnPoints-1) for s=1,ran do tgtpoint2=tgtpoint2+1 if tgtpoint2>#ActorManager.spawnPoints then tgtpoint2=1 end end for i = 1, #passengers do passengers[i].SpawnAt(Vector3(0,0,0)) end local sq=Squad.Create(passengers) for i = 1, #passengers do passengers[i].EnterVehicle(plane) end sq.AssignOrder(Order.Create(OrderType.Roam, ActorManager.spawnPoints[tgtpoint], ActorManager.spawnPoints[tgtpoint2])) end
Last edited by Hijong park; 5 May, 2022 @ 4:57am