OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: RM-Dog on 05 Jan 2004, 05:36:00

Title: Enemy AI Supressing Fire
Post by: RM-Dog on 05 Jan 2004, 05:36:00
Ok I am a newbie at all this scripting stuff - I have been trying to make a script where the enemy M2 mg's lay down supressing fire over a certain arc while the enemy AI units move up. Tried the DoFire and CommandFire but does not have the effect required as they are firing at a specified target. Need some idea as how to get them to fire randomly in a certain direction for a certain time.

RM-Dog
  :-\
Title: Re:Enemy AI Supressing Fire
Post by: dmakatra on 05 Jan 2004, 17:40:25
You might consider only posting one topic. You're breaking the OFPEC law. :P

:beat: *Gets Shot* :beat:
Title: Re:Enemy AI Supressing Fire
Post by: General Barron on 05 Jan 2004, 20:58:12
Here's some short scripts from a mission I was working on:

fire.sqs

Code: [Select]
_gun = _this select 0
_target = _this select 1
_dir = 0
_radius = 0

#Top
@_gun ammo "browning" > 0
_radius = (random 10) + 15
_dir = _dir + random 45
_gun dowatch [(getmarkerpos _target select 0) + _radius * cos _dir, (getmarkerpos _target select 1) + _radius * sin _dir, random 10]
_gun fire["browning","browning"]
~.1
goto "Top"

wigglemarker.sqs:

Code: [Select]
_mark = _this select 0
_theta = -1 * (_this select 1) + 90
_dist = (_this select 2) * 125
_speed = (_this select 3) * 10
_center = getMarkerPos _mark

_adjust = 0
_dir = 1

#Top
_mark setMarkerPos [(_center select 0)  + (cos _theta) * _adjust, (_center select 1)  + (sin _theta) * _adjust]
?_adjust >= _dist OR _adjust <= -1 * _dist : _dir = _dir * -1
_adjust = _adjust + (_dir * _dist / _speed)
~.001
goto "Top"

     Okay, first place a marker, of type "empty" (they are invisible). Call it something like "target1". Now make the marker wiggle back and forth on the map, using wigglemarker.sqs. Call it with this line in an init field/script/trigger: ["target1", direction, distance, speed] exec "wigglemarker.sqs". "Target1" is the name of the marker (remember the quotes!). Direction is the compass direction you want it to start wiggling (0 is north, 180 south, 90 east, 270 west, etc.). Distance is the approximate distance the marker will move in that direction before moving back to it's origin. Putting a 1 will make it move about 1 map square, 2=2map squares, etc. Speed is how many seconds it takes for the marker to travel half its path (1 means it will travel out for 1 second, then travel back for 1 second).

     Now to make the gun fire. When you are ready for them to fire, call the script like this: [gun, "target"] exec "fire.sqs". Gun is the name of the MG to fire, and "target" is the name of the marker it will fire at (remember the quotes!). This script will make the MG fire in sort of a circular pattern around the target, with a varying radius. The bulets will land anywhere from 10-25 meters from the marker. To change this distance, edit the _radius variable in fire.sqs. Since the markers are moving, the center of the "circle" the gun is firing at will also move, and you will get a nice effective spray along a rectangle of ground.

     Oh yeah, you also should add some more ammo to the guns, or else they will run outta ammo quick. Put this in their init line:

this addmagazine "browing"; this addmagazine "browing"

  Add more magazines as needed. Have fun!
Title: Re:Enemy AI Supressing Fire
Post by: RM-Dog on 06 Jan 2004, 03:08:21
Sorry about the double post - Didn't know rules also a newb at these forums. Thanks for that script i will give it a shot and let you know if i come up with anything extra.
Title: Re:Enemy AI Supressing Fire
Post by: DBR_ONIX on 15 Jan 2004, 14:59:01
Tried the script, the gun fires, but turns as far round as it can, to the left, and keeps firing.. Wth out moving..
I'll try when I fix OFP..
Tonight :)
- Ben
Title: Re:Enemy AI Supressing Fire
Post by: General Barron on 15 Jan 2004, 21:54:12
Hmm... well, when I wrote that script, I was using v1.46, but now that I've gone back and played the mission again using resistance, it doesn't quite work the same. For me, the guns don't fire as fast as they should/used to. Not sure about the firing to the side thing, except I remember that happening before if the gunner got killed. The gun would turn left and fire on its own. Not sure if that's whats happening to you though.