Jump to content

need help for artillery script!


nonplusultra

Recommended Posts

hey guys, I'm working on a mod and want to put an automated artillery in it like the boomers have. I've copied the NAFB script, changed some refs and deleted the quest stuff in the script.

when I'm entering the trigger the artillery is shooting - that's not the problem, but instead of one shot it shoots like a minigun without reload time :<

Here is the script, if u see any mistakes pls let me know:

 

scn AirportArtilleryScript

 

int iArtilleryFiring

float pangle

float rangle

float angle

float fRelativePos

float fRandom

float timer1

float timer2

int ActorCount ; Tracks the number of actors that have entered the trigger volume

int Boom ; Tracks whether to make the shooting sound

int Fire ; Tracks whether to shoot

int InCover ; This check to see if the player is in cover and make the artillery less accurate

int XOffset

int YOffset

int ZOffset

float Drift

float ActiveTime ; The amount of the time artillery has been active this cycle

float iVariance

 

ref CurrentActor1 ; These are holder variables for actors that enter the volume

ref CurrentActor2 ; They get cleared by spawned activators every couple of frames

ref CurrentActor3 ; There are 3 in case they don't get cleared before a new actor enters

ref SpawnedRef1 ; See NellisTargetPickerScript (Attached to NellisTargetPicker) for more associated scripting

ref SpawnedRef2

ref SpawnedRef3

ref LeavingActor1

ref LeavingActor2

ref LeavingActor3

ref rActor

ref rTarget

int iRandomTarget ; RandomTargetPicker

 

float fArtilleryFireRate ;Time between each shell

float fArtilleryFireDuration ;How long the player is shelled for before there is a pause

float fArtilleryReloadTime ;How long it takes the artillery to reload

 

begin onLoad

set fArtilleryFireRate to 5

set fArtilleryFireDuration to 10

set fArtilleryReloadTime to 15

set Drift to 1.2

end

 

;; Double comments are for temp fixes

 

Begin OnTriggerEnter

set rActor to GetActionRef ; Store the current actor in the trigger

if rActor.GetPlayerTeammate == 1 ; Do not run for player teammates

return

endif

if rActor.GetInFaction BoomerFaction

;do Nothing

; ;set iArtilleryFiring to 0

;ShowWarning "Actor is a Boomer Friend. Don't Fire"

; ;set rTarget to 0

; ;set ActorCount to ActorCount - 1

return

elseif CurrentActor1 == 0

set CurrentActor1 to GetActionRef

;set SpawnedRef1 to rActor.Placeatme AirportTargetPicker

elseif CurrentActor2 == 0

set CurrentActor2 to GetActionRef

;set SpawnedRef2 to rActor.Placeatme AirportTargetPicker

elseif CurrentActor3 == 0

set CurrentActor3 to GetActionRef

;set SpawnedRef3 to rActor.Placeatme AirportTargetPicker

endif

set iArtilleryFiring to 1 ; Sets the artillery to fire

set ActorCount to ActorCount +1 ; Track the number of actors in the trigger

;showWarning "Actor Entering"

End

 

Begin OnTriggerLeave

set rActor to GetActionRef

if rActor.GetPlayerTeammate == 1 ; Do not run for player teammates

return

endif

if rActor.GetInFaction BoomerFaction

;do Nothing

return

elseif (CurrentActor1 == rActor)

set CurrentActor1 to 0

;set LeavingActor1 to GetActionRef

elseif (CurrentActor2 == rActor)

set CurrentActor2 to 0

elseif (CurrentActor3 == rActor)

set CurrentActor3 to 0

;elseif LeavingActor2 == 0

; set LeavingActor2 to GetActionRef

;elseif LeavingActor3 == 0

; set LeavingActor3 to GetActionRef

endif

set ActorCount to ActorCount - 1

if ActorCount <= 0

set iArtilleryFiring to 0

set ActorCount to 0

set rTarget to 0

set ActiveTime to 0

set timer1 to 0

set timer2 to 0

set fire to 0

set boom to 0

endif

End

 

Begin GameMode

if ActorCount <= 0 && iArtilleryFiring == 1 ; Fallthrough to catch actors dying

set iArtilleryFiring to 0

set ActorCount to 0

set rTarget to 0

set ActiveTime to 0

endif

if iArtilleryFiring == 0 && (Timer1 || Timer2 || Fire || Boom)

set timer1 to 0

set timer2 to 0

set fire to 0

set boom to 0

endif

if iArtilleryFiring == 0

set timer1 to -5

set rTarget to 0

elseif iArtilleryFiring ==1

set ActiveTime to GetSecondsPassed + ActiveTime

if ActiveTime <= 3

set Drift to 5

elseif ActiveTime <= 10

set Drift to 4

elseif ActiveTime <= 12

set Drift to 3

elseif ActiveTime <= 15

set Drift to 2

elseif ActiveTime <= 30

set Drift to 1

else

set Drift to 0

endif

set iRandomTarget to GetRandomPercent

if iRandomTarget >= 0 && CurrentActor1 != 0 && CurrentActor1.GetDead == 0

set rTarget to CurrentActor1

endif

if iRandomTarget >= 33 && CurrentActor2 != 0 && CurrentActor2.GetDead == 0

set rTarget to CurrentActor2

endif

if iRandomTarget >= 67 && CurrentActor3 != 0 && CurrentActor3.GetDead == 0

set rTarget to CurrentActor3

endif

if rTarget == 0 || rTarget.GetDead

set iArtilleryFiring to 0

set ActorCount to 0

set rTarget to 0

set ActiveTime to 0

return

endif

 

set timer1 to GetSecondsPassed + timer1

set timer2 to GetSecondsPassed + timer2

 

if timer2 < fArtilleryFireDuration

if boom == 0

set Boom to 1

elseif timer1 >= fArtilleryFireRate && fire == 0

set fire to 1

elseif timer1 > fArtilleryFireRate && fire == 2

set timer1 to 10

set boom to 10

set Fire to 0

endif

elseif timer2 > (fArtilleryReloadTime + fArtilleryFireDuration)

set timer1 to 10

set timer2 to 10

endif

if Boom == 1

set Boom to 2

ArtillerySoundMarker2REF.MoveTo Player

ArtillerySoundMarker2REF.playsound FXExplosionArtilleryMortar

endif

if Fire == 1 && rTarget != 0

set fRandom to GetRandomPercent

if fRandom <= 50

set fRandom to getRandomPercent * 3.0 * Drift ; Was 10* drift

else

set fRandom to getRandomPercent * -3.0 * Drift ; Was 10 * drift

endif

 

if iVariance > 75

set fRelativePos to rTarget.GetPos Y - fRandom

ArtillerySourceMarker2.setPos Y fRelativePos

set fRelativePos to rTarget.GetPos X - fRandom

ArtillerySourceMarker2.setPos X fRelativePos

elseif iVariance > 50

set fRelativePos to rTarget.GetPos Y + fRandom

ArtillerySourceMarker2.setPos Y fRelativePos

set fRelativePos to rTarget.GetPos X - fRandom

ArtillerySourceMarker2.setPos X fRelativePos

elseif iVariance > 25

set fRelativePos to rTarget.GetPos Y - fRandom

ArtillerySourceMarker2.setPos Y fRelativePos

set fRelativePos to rTarget.GetPos X + fRandom

ArtillerySourceMarker2.setPos X fRelativePos

else

set fRelativePos to rTarget.GetPos Y + fRandom

ArtillerySourceMarker2.setPos Y fRelativePos

set fRelativePos to rTarget.GetPos X + fRandom

ArtillerySourceMarker2.setPos X fRelativePos

endif

set angle to ArtillerySourceMarker2.GetHeadingAngle ArtillerySourceMarker3

ArtillerySourceMarker2.SetAngle Z angle

ArtillerySourceMarker2.PlaceAtMe FXNellisArtilleryStrike01

else

set Fire to 3

set fRelativePos to rTarget.GetPos Z + 100

ArtillerySourceMarker2.setPos Z fRelativePos

set fRelativePos to rTarget.GetPos Y + fRandom

ArtillerySourceMarker2.setPos Y fRelativePos

set fRelativePos to rTarget.GetPos X - fRandom

ArtillerySourceMarker2.setPos X fRelativePos

set angle to ArtillerySourceMarker2.GetHeadingAngle ArtillerySourceMarker3

ArtillerySourceMarker2.SetAngle Z angle

ArtillerySourceMarker2.PlaceAtMe FXNellisArtilleryStrike01

endif

endif

endif

End

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...