Home   Help Search Login Register  

Author Topic: cos & sin and setting Target  (Read 496 times)

0 Members and 1 Guest are viewing this topic.

M_S_Holder

  • Guest
cos & sin and setting Target
« on: 06 Jan 2004, 16:51:03 »
Recently I decided to make my Mortar script a little better by adding a mortar tube that would face the direction of the fire mission and fire *blank* rounds to simulate a real mortar tube.

In order to get the mortar to fire, I try to set up an invisible H (named IRTARGET) just a few hundred meters in front of the Mortar (FSO).  Since my mortar is already facing the direction of the fire mission, I use sin and cos, but I either am using them wrong, or my syntax is wrong.

Here's the script.  The problem line is marked:

;MFireAction request HE

player removeaction MSmokeaction
player removeaction MFlareaction
player removeaction Millumaction
player removeaction MFireaction
player removeaction MFFEaction
player removeaction MAdjustaction
player removeaction MEndaction


Player Globalradio "HEReqruest"
?(MortarHE <= 0):goto "Skip"

FSO doWatch getmarkerPos Firemarker
_ifdir= getDir FSO

;here's the problem
IFTarget setPos [ getpos FSO select 0 + 200 * sin _ifDir, FSO select 1 + 200 * cos _ifDir, FSO select 2 + 200]

_dist= FSO distance IFTarget
FSO doTarget IFTarget

FSO Globalradio "XShot"
FSO doFire ObjNull
_delay = _dist / 10
~_delay

FSO Globalradio "XSplash"

_dir = random 360
_dis = random 9
_Xx = Firex + sin (_dir) * _dis
_Yy = Firey + cos (_dir) * _dis
"MortarShell" createVehicle [_Xx, _Yy, 50]

_delay = random 5
_delay = _delay + 5
~_delay
MortarHe = MortarHe - 1
#TheEnd

MSmokeaction = player addAction ["Smoke Round", "FSO\Mortar\Smoke.sqs"]
MFlareaction = player addAction ["Flare", "FSO\Mortar\Flare.sqs"]
MIllumaction = player addAction ["Illuminate", "FSO\Mortar\Illuminate.sqs"]
MFireaction = player addAction ["Fire HE", "FSO\Mortar\Fire.sqs"]
MFFEaction = player addAction ["Fire For Effect", "FSO\Mortar\FFE.sqs"]
MAdjustaction = player addAction ["Adjust Fire", "FSO\Mortar\Adjust.sqs"]
MEndaction = player addAction ["End Mission", "FSO\Mortar\End.sqs"]
exit

#Skip
FSO sidechat "No more rounds left, over."
goto "TheEnd"
« Last Edit: 06 Jan 2004, 16:58:14 by M_S_Holder »

Unnamed

  • Guest
Re:cos & sin and setting Target
« Reply #1 on: 06 Jan 2004, 22:05:43 »
Perhaps its this:

Code: [Select]
getpos FSO select 0 + 200
It will return a division by zero error because it's trying to select element 200 out of a three element array.

Something like this works ok:

Code: [Select]
((getpos FSO) select 0) + 200
But if you just want the mortar to point in the direction your going to create your mortar shells, just give it the X & Y coordinate of your inital target. No maths required, OFP will handle all that.

You could remove all this:

Code: [Select]
FSO doWatch getmarkerPos Firemarker
_ifdir= getDir FSO

;here's the problem
IFTarget setPos [ getpos FSO select 0 + 200 * sin _ifDir, FSO select 1 + 200 * cos _ifDir, FSO select 2 + 200]

_dist= FSO distance IFTarget
FSO doTarget IFTarget

FSO Globalradio "XShot"
FSO doFire ObjNull

And replace it with:

Code: [Select]
FSO DOWatch [Firex,Firey,Firez+200]

FSO Globalradio "XShot"

FSO Fire <"Mortar Ammo Name goes here">

I'm guessing you can get Firez when you get the other X $ Y coordinates?

M_S_Holder

  • Guest
Re:cos & sin and setting Target
« Reply #2 on: 06 Jan 2004, 23:11:51 »
I thought that I needed a target for my mortar to shoot.