OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Killzone on 16 Feb 2007, 21:54:16

Title: Help with Script
Post by: Killzone on 16 Feb 2007, 21:54:16
Hi,

I am getting an error on the screen everytime I use a script that follows a missile. the script works, it follows the missile until it impacts but I get this error and I dont know what it is or how to get rid of it.

Here is the error that displays on screen

-----

' _this |#| Select 4 != "M_sidewinder_AA" '
Error Zero Divisor

-----

Here is the line I use to call the script:


HAV8B2 addEventHandler ["fired",{_Missile = nearestObject [vehicle(player), _this select 4];[_missile] exec "onBomb2.sqs"}]


And finally here is the script:

_plane = _this select 0
?_this select 4 != "M_Sidewinder_AA" : exit
_bomb = NearestObject [_plane, "M_Sidewinder_AA"]

_camera = "camera" camCreate (getpos _plane)
_camera cameraEffect ["External", "Back"]
_camera camSetFov 0.2
showcinemaborder false

#loop
_camera camSetTarget _bomb
_camera camSetRelPos [0, -28, 1]
_camera camCommit 0
~0.001
?alive _bomb: goto "loop"



~2
_camera cameraEffect ["Terminate", "Back"]
camDestroy _camera

-------------
When I use it with the GBU's it does not get this error and works fine.
Thanks any help would be great.
Title: Re: Help with Script
Post by: Mandoble on 16 Feb 2007, 23:08:47
Try:
Code: [Select]
HAV8B2 addEventHandler ["fired",{_this exec "onBomb2.sqs"}]
Code: [Select]
_plane = _this select 0
_type = _this select 4
? _type != "M_Sidewinder_AA" : exit
_bomb = NearestObject [_plane, "M_Sidewinder_AA"]

_camera = "camera" camCreate (getpos _plane)
_camera cameraEffect ["External", "Back"]
_camera camSetFov 0.2
showcinemaborder false

#loop
_camera camSetTarget _bomb
_camera camSetRelPos [0, -28, 1]
_camera camCommit 0
~0.001
?alive _bomb: goto "loop"

~2
_camera cameraEffect ["Terminate", "Back"]
camDestroy _camera
Title: Re: Help with Script
Post by: Killzone on 16 Feb 2007, 23:24:14
Thanks for such a quick reply Mandoble

It works  :clap:



Thank you  :D
Title: New installment of help with a script
Post by: Sparticus76 on 13 Jan 2008, 06:25:22
Can anyone give me a hand with this error.

_one = _ver2 select _n0
Error zero divisor

here is the script

Code: [Select]
_Firer = _this select 0
_rng = _this select 1
_rng2 = 5000
_var = []
_var2 = []
_tgts = _Firer NearTargets _rng
_ntgts = count _tgts
?(_ntgts == 0) : [_Firer] exec "findtgt.sqs" ; exit
_v = 0
_n0 = 0
_n1 = 1
_tgtvar = ["DSHKM","AGS","D30","BRDM2","UAZMG","UAZ_AGS30","BRDM2_ATGM","BMP2","ZSU","KA50","MI17_MG","SU34B","RHIB","RHIB2Turret"]

;~~~~~~~~~~~~ screen for selected target types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Screen
_nt = _tgts select _v
_type = _nt select 1
?(_type in _tgtvar) : _var = _var + [_nt select 4]
_v = _v + 1
?(_v > _ntgts) : _v = 0 ; _idcount = count _var ; goto "Distance"
goto "Screen"

;~~~~~~~~~~~~ get range to every target matching _tgtvar variable and put them in an array ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Distance
_Fpos = getpos _Firer
_varid = _var select _v
_dis = _Fpos distance getpos _varid
_var2 = _var2 + [_dis]
_v = _v + 1
?(_v == _idcount) : goto "Whoisclosest"
goto "Distance"

;~~~~~~~~~~~~ find out what ID is closest ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#Whoisclosest
_v2count = count _var2
_one = _var2 select _n0                                     <----------------THE PROBLEM IS HERE
?(_v2count > 1) : _two = _var2 select _n1
?(_v2count == 1) : _two = _rng
?(_one < _two) && (_one < _rng) : _rng = _one
?(_two < _one) && (_two < _rng) : _rng = _two
_n0 = _n0 + 1
_n1 = _n1 + 1
?(_n1 == _v2count) : _v = 0 ; goto "end"
goto "Whoisclosest"

;~~~~~~~~~~~~~~~~~~~~end~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#end
~5
_Varid = _var select _v
_Fpos = getpos _Firer
_dis = _Fpos distance getpos _varid
? (_dis < _rng + 5)&&(_dis > _rng - 5) : [_firer,_varid] exec "tgt.sqs" ; exit
_v = _v + 1
?(_v == _idcount) : goto "Screen"
goto "end"


Now, the variable _n0  is equal to 0 so what's the problem? _var2 select 0 has to be there yeah?
EDIT : YES _VAR2 SELECT 0 WAS THERE, THE PROBLEM WAS THAT _N0 WENT ABOVE _IDCOUNT AND THAT IS WHAT WAS NOT PRESENT
          LOOK AT MY NEXT POST FOR THE FIX.
Title: Re: Help with Script
Post by: Mandoble on 13 Jan 2008, 10:29:33
Are you sure _var2 array is not empty when you try to get the first array element?
Title: Re: Help with Script
Post by: Sparticus76 on 13 Jan 2008, 10:43:03
Yes, you are right, I fount out with the help of a bit of "hint format....with a delay after".  I  fixed it by altering....

Code: [Select]
?(_v == _idcount) : goto "Whoisclosest"
goto "Distance"

to....

Code: [Select]
?(_v == _idcount) : goto "Whoisclosest"
?(_v < _idcount) : goto "Distance"

it was like, if one was in the bracket, it just didnt detect it and the counter _v + 1 just kept on ticking over and the loop kept on keeping on above the _idcount. I also had to alter ....

Code: [Select]
?(_v == _idcount) : goto "Screen"
goto "end"

to...

Code: [Select]
?(_v == _idcount) : goto "Screen"
?(_v < _idcount) : goto "end"