Home   Help Search Login Register  

Author Topic: LaserDesignator position  (Read 731 times)

0 Members and 1 Guest are viewing this topic.

Lt_Frosty

  • Guest
LaserDesignator position
« on: 10 May 2004, 02:40:46 »
I'm using the origional OFP game, with all updates installed (1.42). I want to know how can I obtain the position of the LaserTarget of the Laser Designator so that I can use it in an artillery mission,  this is what I have so far:

Code: [Select]
;Artillery with Laster Designator
;May 9th, 2004

_Laser = _this select 0
_area = _this select 1
_shells = _this select 2
_ArtyPiece = _this select 3


_LaserPos = [GetPos _Laser select 0, GetPos _Laser select 1]

_xcoor = _LaserPos select 0
_ycoor = _LaserPos select 1
_zcoor = 0

_areaX2 = _area * 2

~2

_ArtyPiece SideChat "Artillery Incoming, stand your ground."

~4

_ammo = _shells

#fire

_shot1 = "mortar" camCreate [_xcoor + Random(_areaX2) - _area,_ycoor + Random(_areaX2) - _area,_zcoor + 150]

~3

_shot2 = "mortar" camCreate [_xcoor + Random(_areaX2) - _area,_ycoor + Random(_areaX2) - _area,_zcoor + 150]

_ammo = _shells - 2

?(_ammo > 0) : goto "fire"

_ArtyPiece SideChat "Rounds complete, I repeat, rounds complete."

Exit

I got most of the code from the beginners guide to scripting. I have it setup so that, when you have your laser designator targeted on something, u call the radio and it will enable the trigger with the following activation:

["LaserTarget",20,6,arty1] exec "artillery.sqs"

When that is called to run, I get the following error message at the top of my screen:

'_LaserPos = [GetPos _Laser select |#| 0, GetPos _Laser select 1]': Error type String, expected Object.

I may (most likely) have all of this code wrong or jumbled up. Could you tell me either how to get the coordinates of the LaserTarget, or how to fix my mess? (which ever is easier) thanks in advance, Frosty.

Kammak

  • Guest
Re:LaserDesignator position
« Reply #1 on: 10 May 2004, 10:26:02 »
The error is because you are just passing the *word* LaserTarget to the script, not the actual object in the 3d world.

You have to run a script that looks for a "LaserTargetW" (if you are using the typeOf function) or just "LaserTarget" (if you are using CountType instead).

Once you pull the LaserTarget object out of an array of all objects on the map, then you can pass *that* object to your script above and it should work.

Do a search on "Laser Designator" in the Editor Depot and you will find a script by Snyper showing how to find the target.  Note that his script doesn't work as advertised in some parts, I guess due to changes in later versions.   Specifically the get nearest object stuff doesn't work, as nearestobject[(lasertarget variable),""] always returns THE LASER TARGET itself!! Rather useless!  :)

I find it easiest to just loop through the trigger list until I find an object with typeOf="LaserTargetW".  Tactician's example doesn't work either, and I'll be damned if I can figure out how to fix it!  So a simple loop did the trick for me.


Lt_Frosty

  • Guest
Re:LaserDesignator position
« Reply #2 on: 10 May 2004, 19:24:00 »
That script is used for V 1.90 of OFP:R. But I was wondering if some of that script could still be used in v1.42. Mainly the first part SnYper talks about, Detecting "LaserTarget". In all honesty, I looked at this script before I posted on the forum. I was getting errors with the script (mainly this part:)

Code: [Select]
if (format["%1", ld_logic] == "scalar bool array string 0xfcffffef") then {ld_logic = "logic" camCreate [0,0,0];};

Would it be able to just not use that, and use the rest of the code in the section? (the script can be found here: http://www.ofpec.com/editors/resource_view.php?id=438

While reading the script it seems to all make sense, except I dont understand that first line (placed above). Also, he states that the player needs to have the LD (Laser Designator) for it to track the laser, or it will search the array of objects in the world until it finds it. So if I have some other person besides the player use it, it would detect it through the array? Sorry if these questions seem stupid, but its all helping me learn more about scripting.

ADD: I've just noticed what you mean about haveing a looping trigger find the dot. (Dinger has posted it as a comment to SnYper's script.) So if I run a trigger with his given information, I would be able to call the variable "LaserTarget1" for the laser dot in a script? So instead of having
Code: [Select]
["LaserTarget", 20, 6, arty1] exec "artillery.sqs"I would have:
Code: [Select]
[LaserTarget1, 20, 6, arty1] exec "artillery.sqs"or, would I just get rid of the first data block and have
Code: [Select]
[20, 6, arty1] exec "artillery.sqs"and then in the artillery.sqs just call the variable LaserTarget1 that way. Which do you think would cause less problem.. I think just calling the variable in the artillery.sqs would be easier so that the user doesnt have to put LaserTarget1 in their data-array for the trigger everytime.

It seems to make sense in my mind.. but my mind is a scarey place when I am trying to code something  8) .
« Last Edit: 10 May 2004, 19:37:38 by Lt_Frosty »

Kammak

  • Guest
Re:LaserDesignator position
« Reply #3 on: 10 May 2004, 23:32:26 »
Dinger's (I thought it was Tacticians?) example doesn't work for me, just errors out on this trigger condition line...which is why I finally just wrote a simple loop looking at the typeOf for each object in the trigger list.  That's of no use to you as the typeOf function is 1.91 or higher...

*If* Dinger's example works on your version, then yes LaserTarget1 would be object variable, and personally I would pass it to the arty script but that's just a preference.

RE: That line in Snyper's example:  I know what its doing but don't really know *why* he does it.  :)  There are a few places where that script seems overworked, but again that may be an issue of previous versions of OFP.

Of the top of my head, here's what I would try given your version.   Have the trigger call a script and pass the trigger list to it.  Loop through the list, then do a countType on each object and if it returns one, you found your spot - exit the loop, assign that object to a global var and then call your arty script and pass it on.

Code: [Select]
;LookForDot.sqs
_arrThings=_this select 0
_max=count _arrThings
_i=0

#loop
?("LaserTarget" countType[_arrThings select _i]==1):goto "foundit"
_i=_i+1
?_i<_max:goto "loop"
hint "Didn't find it"
exit

#foundit
varLaserTarget=_arrThings select _i
exit

varLaserTarget should then be the laser dot.  In the "foundit" section you could do whatever you want - probably call your arty script and pass varLaserTarget to it.

The script would be called by the trigger, as

[thislist] exec "LookForDot.sqs"

in the activation field after LaserOn is set to true.

Lt_Frosty

  • Guest
Re:LaserDesignator position
« Reply #4 on: 11 May 2004, 01:08:42 »
Thanks for that script, I can fully understand how it works, and what goes on in it. I will try it out in a few, right now I'm playing around with a carbomb script (that will include a speedometer). But thank you, and by any chance, do you know how to turn of the Hint "BING" noise?  ;D

ADD: OK still am having just 1 more minor problem. I am not getting an error message, so that is (kinda) good. I just get the "Didnt find it" hint that was in your code. This is my procedure, tell me if u see something wrong:

Activate the LaserDesignator on the ground.
Activate the trigger by calling to it over the radio.
(In the trigger's edit prefrences i have the codition to wait for a radio call by alpa,then in the activation field I have:
Code: [Select]
LaserOn = True, [thislist] exec "laser.sqs" and then in the DeActivation i have "LaserOn = False".

All plays out well (and incase you are wondering, in the bottom of your script I am calling to the artillery script. but it doesnt get that far.) After failing, I tried, just to say I tried it, putting "LaserTarget" to "LaserTargetW" but to no luck. I'm kind of doubting this whole laser designator thing, but I really want it to work. Sorry for the questions, but you've been a great help so-far  ;D
« Last Edit: 11 May 2004, 01:49:33 by Lt_Frosty »

Kammak

  • Guest
Re:LaserDesignator position
« Reply #5 on: 11 May 2004, 17:59:52 »
When you pass "thislist" is that from a Radio command trigger?  If so, I believe that is the problem.

The list must come from a trigger covering the battle area, activation:Anybody,Repeatedly,Present.

Give the trigger a name, then pass *that* list to the script that looks for the dot. Example, the trigger is named "triggerGlobal", the call from the radio trigger would then be

[list triggerGlobal] exec "laser.sqs"

In fact I just tried it that way too, and it works on my end.  :)



Lt_Frosty

  • Guest
Re:LaserDesignator position
« Reply #6 on: 11 May 2004, 21:03:17 »
Ah yes! finally success. It works completey like I wanted it to. Thank you a ton! I owe you, hopefully I can repay you with something sometime. Thanks again  ;D