Home   Help Search Login Register  

Author Topic: Grenadier target position script (work in progress)  (Read 5531 times)

0 Members and 1 Guest are viewing this topic.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Grenadier target position script (work in progress)
« on: 29 Mar 2005, 09:15:47 »
POST EDITED WITH NEW VERSION

Greetings all :wave:. Here is a script that is very cool, if I do say so myself. This script allows AI infantry to shoot ANY indirect fire weapon and hit a specific location on the ground. It works best with slow-moving weapons like launched grenades, 'mortars' (rifle grenades), etc; although technically it could work with rockets and even bullets. There is just one small catch: you have to do a little bit of work to let the script work with each weapon. However, I've made that process as painless as possible (instructions are included).

Basically, it is like CoC's UA, only for infantry, if you know what UA is. You can adjust the accuracy (impact radius) of the shot--the script can put the round within a couple of meters of the target every time, if you wish.

The base script (inf_IF_launch.sqs) only does the above. It is up to other scripts to determine where/when/who to launch the grenades, so the script is very flexible for other scripters/editors to use. For example, I have written a script that allows the player to order his squad's grenadiers to fire by clicking on the map, which is included in the demo. This script could also easily be used like an artillery barrage script, by having a group of AI target a pre-determined position via a trigger (example also included in demo). Or this could be used by an AI script (not included), and so on and so forth.

Included in the download is a demomission, the tool to acquire data for other weapons, and instructions for that tool. The demomission gives you a few targets which you can order your squad to shoot. It also has an AI squad behind a hill, which you can order to bombard a pre-determined location by using the radio. Instructions on how to use the script is at the top of the script.


This script was made possible by Soultaker's "Indirect fire with all kind of vehicles" tutorial (although the process was slightly modified; ask me if you want an explaination).

The script requires Lester's Invisible Targets addon (which everyone should have anyway, since it is so darn useful).


[url removed]inf_IF_test.zip]DOWNLOAD THE SCRIPT & DEMO HERE[/url]
« Last Edit: 13 Apr 2005, 09:35:46 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline 456820

  • Contributing Member
  • **
Re:Grenadier target position script (work in progress)
« Reply #1 on: 29 Mar 2005, 11:05:10 »
this sound like one hell of a good script downloading now

Offline 456820

  • Contributing Member
  • **
Re:Grenadier target position script (work in progress)
« Reply #2 on: 29 Mar 2005, 11:09:54 »
now that is one amazing script took me a while to get it to work miss read where you must use alt key as well
but one thing they all say . 2. ammo low then 3. ammo low
then they all pound the target wich looks cool
shame it has an addon though i prefer addon free things but i dont mind getting an addon for this

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #3 on: 29 Mar 2005, 20:41:00 »
Thanks for the comments. I guess I should have mentioned that you must alt-click the map to target the grenadiers, but actually it does mention it when you use the action. The "ammo low" stuff comes from the fact that I am removing their rifle ammo, and *hopefully* will not be in the final version. True, it is nice to have addon free scripts, but there are many things which are not included in the game by default, and can only be added via addons.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Blanco

  • Former Staff
  • ****
Re:Grenadier target position script (work in progress)
« Reply #4 on: 30 Mar 2005, 03:18:13 »
An absolute great script, it's real pity about that ammo bug

As far as I can see in the GLaunch script, you removed all the magazines who are not from the grenades type and you store them in the _mags array to add them back after the barrage.

Quote
_unit addeventhandler [ "fired", format[{_unit = _this select 0; _targ = "LesICTA" camcreate [(getpos _unit select 0) + 10*sin getdir _unit, (getpos _unit select 1) + 10*cos getdir _unit, 0]; _unit dofire _targ; _unit dotarget _targ; _unit dowatch _targ; _unit setunitpos "auto"; _unit domove getpos _unit; deletevehicle _targ; {_unit addmagazine _x} foreach %2; _unit removeEventhandler ["fired", %1]}, _idx, _mags] ]

Now that's what I call a freaky eventhandler :p

Now, in this part :

Quote
_mags = []
{if(_x != _grenade) then {_unit removemagazine _x}} foreach magazines _unit

You remove the non-grenade mags, but you don't add them in the _mags array  ???

When I change that in to this :

Quote
_mags = []
{if(_x != _grenade) then {_unit removemagazine _x;_mags = _mags + [_x]}} foreach magazines _unit

...my men don't ran out of ammo after the barrage, they have their riflemags back with 2 grenades. So far so good and I thought I've solved something... :p

No, I didn't...
When I order them  for a second barrage, they don't do it because they ran out of ammo...again   :'( Dunno why it doesn't work a second time.



 

« Last Edit: 30 Mar 2005, 03:24:26 by Blanco »
Search or search or search before you ask.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #5 on: 30 Mar 2005, 03:46:45 »
Yeah, I should have mentioned that... Originally I did exactly what you tried (that is, remove the magazines, store what mags were removed, then add them back again at the end). It didn't work, as you noticed, and so I removed that from the script. Well, not all of it, apparently.

Anyway, the problem seems to be that *somewhere* the wrong number of magazines is added or removed or counted. Can't remember why I decided this was the problem... but I seem to remember that being an issue. I suppose I should experiment with it more, perhaps by removing the weapon and then adding it back in or something...
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #6 on: 04 Apr 2005, 08:18:29 »
Okay, I fixed the problem with the removed magazines, so now units are given back their removed magazines after they shoot a grenade (or after a timeout delay). They still say 'out of ammo' when first ordered to shoot, and they will get full magazines back (no partials, so if they shoot off half a mag before this script, they gain rounds). But I don't know of any way to make this work, other than removing their non-grenade magazines like I am doing. Perhaps making a new invisible targets addon could solve this problem, but until then...

This version should be fairly usable in real missions now that I have fixed the major flaw. Please use it, and tell me if you can 'break it' in normal play conditions (meaning, cause it not to work right). This is still not the final version however, as I will include some of the improvements mentioned above.

Attatched is the updated script. Works exactly like the old script, only now it calls itself, so it MUST be in the mission's root directory.

EDIT

Attatchment removed; newer version posted.

« Last Edit: 13 Apr 2005, 08:54:14 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #7 on: 13 Apr 2005, 09:10:36 »
Major update.

I just made some major improvements to this script. It is just about 'finished', so I'm excited :). Anyway, here are the improvements from the last version:

8) Multiple rounds can be fired, although the unit often doesn't want to fire more than one, and the random impact dispersion is not changed from round to round. Calling the script multiple times is still the most reliable method.

8) Multiple magazine (grenade) types supported. Script automatically detects what magazine the unit has and uses it, unless you tell it otherwise.

8) A handy-dandy tool has been included to help you find the data required to add a new weapon to the script. Instructions have also been included, although I think I'll re-write them to make them clearer.

I've updated the FIRST POST with the current version. Attatched here is a screenshot of the tool to acquire the data for the script.

As always, comments are VERY welcome. Right now the only improvement I have planned for the final version is to make the script compensate for elevation.
« Last Edit: 13 Apr 2005, 09:35:13 by General Barron »
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:Grenadier target position script (work in progress)
« Reply #8 on: 13 Apr 2005, 20:17:44 »
Sounds great GB!

I can't wait to check it out. One typo though:

Quote
the random impact dispersion is not changed from round to round.

I think that you meant to type "oval" instead of round the second time. Please correct me if I misunderstood you therefore being wrong as to your intent.

On that note, although I do not have nearly enough scripting knowledge as you do, I think I see a way to get a more oval (longer or shorter) impact point in your script.

Could you change this line:

Code: [Select]
_toShoot setpos [(_pos select 0) + ((sin _dir)*50), (_pos select 1) + ((cos _dir)*50), _elev]

to something like:

Code: [Select]
_toShoot setpos [(_pos select 0) + ((sin _dir)*50), (_pos select 1) + ((cos _dir)*25), _elev]
I am not sure if this is the correct paramenter (1=y or is it x?), or even the right line to adjust (I think it is as you want it to fall long or short in line with the direction that the shooter is facing, correct?), but you should get the point that the area is twice as long (or wide) as it is wide (or long).

I would bet my left nut that you tried this (or somthing similar) and there is a problem that I cannot see, but just in case a set of fresh eyes on the subject will look at the problem a little differently, I thought that I would suggest this to you.

Wadmann
Check out my Camouflage Collection! New items added 31 July 2005.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #9 on: 13 Apr 2005, 20:29:55 »
Wadmann,

Thanks for the reply. I suppose I wasn't very clear about this:

Quote
the random impact dispersion is not changed from round to round.


This means that if you tell the script to shoot, say 3 rounds, then each of the three rounds will be aimed at the exact same point on the ground. Normally the script takes the inputted target and then slightly changes it to get a random impact area. But it does not do this between fired shots. I hope that is clearer....

Quote
_toShoot setpos [(_pos select 0) + ((sin _dir)*50), (_pos select 1) + ((cos _dir)*25), _elev]

Well, that should make an oval; however, the oval will always be along the east/west axis of the map, no matter which direction the unit is facing when he fires the grenade. The trick is to adjust it so that the long axis of the oval is always in the direction he is facing... although your suggestion is prolly much closer to a solution than what I was working on.

On a side note, I decided that the most realistic impact area would really be something like a trapezoid. Basically, the unit would have a random amount of error in the compass direction of his fire (azimut), and would also have a random amount of error in the distance he fires. This might be a little more complex to implement than a rectangle... but then again, I might be making it harder on myself.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:Grenadier target position script (work in progress)
« Reply #10 on: 13 Apr 2005, 21:34:51 »
*Wadmann LoL at himself!*

When is round not round? When it is a round!

I got you now. Of course I was referring to the original problem of the impact point that is no longer mentioned as a problem in the first post. :-[

I remember seeing this topic in which bedges mentions:

Quote
as far as i know, tyger's solution for the first problem will indeed work, but only if the player is facing north. to place something behind the player irrespective of what direction s/he is facing, use some trig - thanks THobson

_dir = getdir player
_x = getpos player select 0
_y = getpos player select 1

object setpos [_x + (-5*sin(_dir)), _y + (-5*cos(_dir))]

off the top of my head, that should work.

I just figured that you were coding it differently to get the same effect. Like I said, I can't script worth squat and I have just enough knowledge to make me dangerous! ;D

Wadmann

Edit: I knew it was out there somewhere! Take a look at this function by Igor Drukov. It returns a position relative to an object.

I suppose that you would need to make a temp marker at the onsinglemapclick location and then place the invis target with the returned value of the function relative to the temp marker after setting the invis target direction in the direction of the firing unit. I do not know if you can use a random value in the function's calling array, but I guess you could set that value elsewhere and plug it into the array in order to get a range of 10m  in front of or behind the location of the invis target.

I am sure that I am simplifying the process and it will be alot harder than my above description of the solution, but as sharp as you are, I believe that you could make it work!
« Last Edit: 14 Apr 2005, 19:38:29 by Wadmann »
Check out my Camouflage Collection! New items added 31 July 2005.

Offline 456820

  • Contributing Member
  • **
Re:Grenadier target position script (work in progress)
« Reply #11 on: 02 Jul 2005, 10:50:05 »
would it be possible to check if there are any units around where you clicked on the map then randomly make all the ai target the soldiers then they fire the greande rounds that might work with a few changes then it would be addon free

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #12 on: 02 Jul 2005, 22:48:04 »
would it be possible to check if there are any units around where you clicked on the map then randomly make all the ai target the soldiers then they fire the greande rounds that might work with a few changes then it would be addon free

Well, that would be possible, but you could just as easily select your men and tell them to fire via the command menu--no scripting required.

However, the AI isn't always very good at using their grenade launchers. I don't think I've ever seen them fire GLs at their maximum range (~300 meters). Also, the purpose of this script is to get the AI to target a specific point on the GROUND, not a specific unit.

Think of it like getting tanks to shoot an artillery barrage instead of shooting directly at a specific unit.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline 456820

  • Contributing Member
  • **
Re:Grenadier target position script (work in progress)
« Reply #13 on: 04 Jul 2005, 20:21:04 »
Quote
Well, that would be possible, but you could just as easily select your men and tell them to fire via the command menu--no scripting required.
i never knew you could order your men to launch their grenades at targets

couldnt you create instead an invisible target something like a small object like a radio wich you wouldnt be able to see from a far distance
i would love this to be addon free as it would fit perfectly in one of my missions for my campaign but im making an addons free campaign
how about a script but with mortars aswell.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #14 on: 04 Jul 2005, 20:31:04 »
It might be possible to use an object, such as a radio/etc, but I don't think any BIS object is small enough to really work.

If you want to try another object, just open up the "inf_IF_launch.sqs" script, and search for this string (it should be there 2 times): "LesICTA". Just replace that with the classname of whatever object you want to try.

However, I really doubt that you will be able to get it to look good. I'm afraid that one of the limitations of the OFP engine is that you just can't get a unit to shoot at empty air, and an invisible target (addon) is the only way to get around it. I always try to make scripts addon free, but this one just can't be done like that I'm afraid. Luckily the addon required is extremely small, and is very useful for other purposes as well ;).

Quote
how about a script but with mortars aswell.

I am planning on making a script similar to this that will work with any vehicle (tanks, mortars, MGs, etc). The best part about it is that the script would be addon free, since vehicles work a little differently than units.

However, I first want to fix the math involved in this script, and allow it to adjust for terrain elevation. This current script still isn't "complete" because of those two issues. I just haven't gotten around to completing it yet (although your interest does help). :)

HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Grenadier target position script (work in progress)
« Reply #15 on: 30 Sep 2005, 21:31:53 »
Any progress in this awesome script? :)

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Grenadier target position script (work in progress)
« Reply #16 on: 29 Oct 2005, 02:59:41 »
Well, I've picked up this script again, and am in the process of a total overhaul. I've completely changed the mathematical model behind it, and now the script compensates just great for changes in elevation between the shooter and target.

I still have a lot of work to do to make this into a usable product, but for now I figured I'd post a little test mission of what I have so far. Play the mission, and click on the map to make the grenadier shoot at that position. Some debug hints will pop up telling you things like distance to target, etc, but just ignore them. Anyway, as long as the location you clicked on can be targetted by the script (roughly 300m range, but depends on elevation differences), the grenadier will shoot a grenade pretty darn close to it. The script will teleport you and a jeep to that location, so you can see where he is supposed to hit.

Like I said, this is still a total work-in-progress, but I'm starting to lose steam when I've already done so much, so hopefully this will get me motivated again. A usable version will hopefully be released in 2 weeks or less *crosses fingers*.

HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!