Jump to content
Sign in to follow this  
JDog

Scripting a LaserTarget

Recommended Posts

(Sry if this is double posting didnt realize the older one I replied to wasn't in this forum.)

Ok so I've given up trying to make an accurate single-bomb airstrike script... since SOMEHOW in a script that never changes with targets that never move... there's still variance - sometimes it hits, sometimes it doesnt.

So I'm trying to get a laser target working now but can't seem to get it right for some reason and it wont show up when I'm flying. "LaserTarget" is the object name in CfgVehicles. This is what I've got going:

_laze = "LaserTarget" createVehicle getPos T1;
jet reveal _laze;
jet doTarget _laze;
jet doWatch _laze;

I tried camCreate and off-setting the mark also (in case it being inside the target is bad), that didn't work either.

Share this post


Link to post
Share on other sites

I don't know about the laser targeting, but have an idea for you single bomb airstrike. If it is an immobile target could you not set it like an IED so that when your attacking aircraft hits a certain waypoint or trigger the bomb will detonate? This way your bomb will never miss as it is already set at your desired target and is just waiting for the aircraft to hit the trigger point.

Share this post


Link to post
Share on other sites

Yea but... I don't want the thing to magically explode out of nowhere lol. The bomb's gotta fly!

Share this post


Link to post
Share on other sites

Maybe having a hidden AI who targets the tank with a laser would be easier than scripting it?

Share this post


Link to post
Share on other sites

Yea I might give that a shot. I'm getting closer though. I guess each side has it's own laser target class or something. Now that I'm using "LaserTargetW" instead of "LaserTarget"... it's creating the object. 'doTarget' highlights it for me but I still can't seem to get a lock reticle on it.

UPDATE: Ok... I can get the Laser Target thing to come up and get a lock now... but the laser target only exists for 5 seconds after it's created. I just activated a trigger that checks to see if it's still "alive" after it disappears from my HUD and it made my game go kaputt :(

Edited by JDog

Share this post


Link to post
Share on other sites

I just spawn a sam site behind me and set it above ground about 50meteres in the air so that it has good line of site. Just make it invisible, you just see the rocket trail but not the unit. I posted most the script a week or so back except that it is spawned on the ground and visible. I just can't remember what the thread was called.

You could easily change it to target anything you want.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Yea. I have it giving me hints now... the thing is definitely dying after 5 seconds for some reason. Here's what I'm at if anyone cares to take a shot at testing/explaining :)

_laze = "LaserTargetW" createVehicle getPos T1;
? alive _laze : hint "laze up"


#loop
? (alive _laze) : goto "loop";
hint "laze deaded, out of script";
exit;

T1 is the name of the target.

---------- Post added at 11:40 AM ---------- Previous post was at 11:38 AM ----------

I just spawn a sam site behind me and set it above ground about 50meteres in the air so that it has good line of site. Just make it invisible, you just see the rocket trail but not the unit. I posted most the script a week or so back except that it is spawned on the ground and visible. I just can't remember what the thread was called.

Don't mean to be rude, thanks for posting but not sure how this helps me :P I'm trying to get a bomb to hit an exact location. Actually that was all I cared about at first now I'm just trying to perfect setting up laser targets.

Share this post


Link to post
Share on other sites

Heh you musta thought that right as I was typing it in the script :P Yea that works, I just have it loops to recreate the laser when it dies. Wish I knew why it only existed for 5 seconds but this will suffice for now. If anyone wants to use it:

#create
  _laze = "LaserTargetW" createVehicle getPos T1;

#loop
  ~1
  ? (alive _laze) : goto "loop";

? (!alive Tank1) : exit;
goto "create";

Just sucks that if you're kinda far off on approach, it will die off and you gotta retarget it. Works, though.

---------- Post added at 12:02 PM ---------- Previous post was at 11:48 AM ----------

Is running this in a loop every second bad?

_laze = "LaserTargetW" createVehicle getPos T1;

just wondering if it will keep making copies of _laze (taking up more and more memory) or it will it replace it?

---------- Post added at 12:19 PM ---------- Previous post was at 12:02 PM ----------

ISSUE SOLVED

After much frustration, allowDamage and setVehicleArmor wouldn't keep it alive. It's the dumb class name.

Here's the end-all answer to setting up a laser designated target:

_laze = "LaserTargetWStatic" createVehicle getPos targetName;
#loop
~1
? (!alive targetName) : exit;
goto "loop"

That one will work perfect and not die on you every 5 seconds. Thanks, guys who gave their thoughts. Enjoy :)

---------- Post added at 01:05 PM ---------- Previous post was at 12:19 PM ----------

Now to figure out how to get the AI to actually "select" the laser target for the bomb instead of just "target" it, which does nothing but highlight it in a red circle.

Share this post


Link to post
Share on other sites

Hello again.

When I tried to pilot the Harrier and using the LaserTargetWStatic it became red.

I could "tabb" it but the AI pilot had problems

So not satisfied with the results I just "had" to make it work. And this works, and will follow the target if it moves. i.e. faking a unit painting the target.

LaserTargetFollow.sqf

private ["_target","_laze"];
_target = _this select 0;
_laze = "LaserTargetW" createVehicle getPos _target;
while{alive _target} do{
_pos = (getPos  _target);
_laze setPos [_pos select 0,_pos select 1,0.5]; //Must alter z since -0.0001 below ground wont work.
sleep 0.01;
};
deleteVehicle _laze;

Naturally the AI pilot must do the mandatory "flyby" before coming back and dropping the bomb.

Sorry about the .sqf format.

You really should get to learn the .sqf format, read up on it on the Wiki, thats how I learned to use it.

And after a while you will see that its more structured. :)

edit.gif

BTW, I had this running for over one minute, so the lasertarget doesn't die, dunno if its because it's moved or updated :confused:

Edited by Taurus

Share this post


Link to post
Share on other sites

Oops didnt realize mine didn't track. All I'd have to do is add a setPos loop for it to do the same thing as yours.

And yes, I should learn .sqf, it seems a lot more like what I'm used to. I've kinda just been going off other people's scripts and adapting from those, since I haven't scripted in games since OFP when I was like... 12 or 13 lol.

As for your script... I don't see how I get the AI to fire at it and lock onto it? Do I just set a Destroy waypoint? Use any of doTarget, selectWeapon, etc? Right now I just changed it so that some SADARMs come in instead of the LGB.

Thanks again, Taurus

Share this post


Link to post
Share on other sites

No problem :)

Ye I forgot to say, I used a "search and destroy" wp for the harrier.

I guess a "destroy" wp will do the trick too.

Part from that I didn't do anything to force the AI to drop the bombs.

Share this post


Link to post
Share on other sites

While were at getting AI to target laser designators, does anyone have a good script or have a way to keep AI flying a curtain altitude and not kamikaze dive before dropping their LGB? I'm pulling my hair out here..

Share this post


Link to post
Share on other sites

Not sure if you can force them not to Stuka dive, but you could try:

this flyInHeight x

Where x is in meters.

Share this post


Link to post
Share on other sites

So I figured I would try this out, but I am confused about where to put everything. I want to use Taurus' script, but don't know what to put into the INIT file, and at that the INIT file for what unit? Or maybe there is no INIT file? Hah. Help please :)

Share this post


Link to post
Share on other sites

Hi Grimes,

So Tarus's script would have to be a text file within your mission folder called "LaserTargetFollow.sqf".

Then you would have to call that script from within the game/editor. You can either:

1) Put it in the init field of the thing you want to be lazed, or

2) Put it in the On Activation field of a trigger, waypoint, etc.

The script execution would be something like this:

nul=[] execVM "LaserTargetFollow.sqf"

if it was in the same folder as your mission.sqm. If you place it in the On Activation field on a trigger/waypoint, include the name of the target within the brackets "...nul=[targetName] execVM...."

It's good practice to have a "scripts" folder within your mission folder though, for organization purposes :P Then you'd just change the path in the execution line to "scripts\LaserTargetFollow.sqf"

Edited by JDog

Share this post


Link to post
Share on other sites

Thanks for the quick response. So I tried a few things, but I still am not able to track and lock on to the laser target (T-72). I tried both the INIT and Trigger methods :/

Share this post


Link to post
Share on other sites

Hm yea doesn't work for me either. I'll get something going and post it here for ya.

---------- Post added at 03:03 PM ---------- Previous post was at 02:39 PM ----------

Here ya go, I edited my script so it's SQF instead of SQS. This works, for moving targets also, and will terminate when the target its tracking does:

laserTarget.sqf

// Usage: 
// nul=[[i]targetName[/i]] execVM "laserTarget.sqf"

_target = _this select 0;
_laze = "LaserTargetWStatic" createVehicle getPos _target;

while{alive T1}do{
_laze setPos getPos _target;
sleep 0.25;
};
deleteVehicle _laze;

Share this post


Link to post
Share on other sites

Still not working for me :/ Sorry, I am pretty new at all of this scripting stuff. Is the T1 supposed to be in there? Is there supposed to be a trigger?

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

oops my bad, accidentally left that in there. replace "T1" with "_target" and it'll work!

basically, at the beginning of the script, it takes whatever unit name you have in the brackets [here], and saves it as another name the script can use, in this case "_target". so whenever you want to do something with that unit you refer to it as "_target" in the script.

Share this post


Link to post
Share on other sites

So, it's still not working lol.

This is the exact script that I used, name included.

_target = _this select 0;
_laze = "LaserTargetWStatic" createVehicle getPos _target;

while{alive _target}do{
_laze setPos getPos _target;
sleep 0.25;
};
deleteVehicle _laze;

And this is what I put into the INIT line

nul=[targetLaser] execVM "lasertarget.sqf"

And I named the tank 'Laser'. Something missing?

Share this post


Link to post
Share on other sites

Yes lol. In the init line, between the brackets... that's where you put the name of the target. So for you do it like this:

nul=[Laser] execVM "lasertarget.sqf";

alsomake sure your filename is "lasertarget.sqf" and not "laserTarget.sqf"... pretty sure it matters.

but yea main issue... in the case of this script, what goes between the brackets is the name of the target. so if u named ur tank "tank1", you'd put that between the brackets like [tank1].

Share this post


Link to post
Share on other sites

Okay, got that to work. But the Laser disappears after about 5 seconds. Any way to fix it?

This is what I want to do. I am making a training map and I would like to have an 'Air-To-Ground Ordnance Range' as a part of it. I've got the scripts for vehicle respawn and weapons and such, so this range works for the Maverick, Hydra, and Hellfire missiles, but it doesn't work for the GBUs (accurately). This is why I want to use this laser targeting script. I want a certain vehicle to have an unlimited laser on it, and the laser disappears when the target is destroyed, then the laser respawns when the target respawns. I believe this is possible and can be done with a trigger, I am just not sure of the proper script. Hopefully that helps a little.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×