Home   Help Search Login Register  

Author Topic: Noob here, need a tiny bit of help  (Read 2367 times)

0 Members and 1 Guest are viewing this topic.

Offline D-scythe

  • Members
  • *
Noob here, need a tiny bit of help
« on: 12 Jul 2007, 08:38:49 »
Decided to give making an airstrike script a go, but I keep getting this error. goto|#|:"Check"': Error invalid number in expression

The code is this...I'll try to make it as quick and easy to understand as possible (bolded indicates the new code I implemented that started to cause problems, italics has been tested to be fine):


?(airstrikecounter>=3): hint "Negative, no assets available are available at the moment"; exit
_keep = airstrikecounter+1
airstrikecounter = 3


This part tries to keep OFP from running the script a second time as a previous one is running. The global airstrikecounter variable is changed to 3 so that if the player decides to run the script again, the script will exit after the first line. Instead of airstrikecounter, the script uses the local variable _keep instead.
Code: [Select]
[i]
_pos = _this select 0

a = 0
b = 0
c = 1000

hint "AIR SUPPORT\n\nSingle-click on the map to set the enemy's position for friendly strike fighters"

onMapSingleClick {a = (_pos select 0); b = (_pos select 1); c = (_pos select 2); hint "AIR SUPPORT\n\nGPS co-ordinates uploaded, vectoring strike fighters to your position - weapons hot, ETA 30 seconds"}
~30
? (c > 999) : hint "AIR SUPPORT\n\nUnable to comply, airstrike cancelled"; [b]airstrikecounter=_keep[/b]; exit[/i]

Cancellation of airstrike, with the penalty of one airstrike.
Code: [Select]
[i]goto "Strike"

#Strike
playsound "Flyby"
_amount = 86 [/i] (is the number of cluster bomblets, to be used later on)[i]
_randomX = 90
_randomY = 90
_offsetX  = _randomX / 2
_offsetY  = _randomY / 2
; X,Y co-ordinates for CBU-103 CEM
_tX = a
_tY = b
[/i]

Some targeting details, getting the position of the mapclick and some cluster munition details. The script is to choose between either a laser-guided bomb strike, or a cluster bomb strike, depending on whether the closest target within 50m of the Mapclick point is a tank or not. If it is a tank, then the script checks 4 spots around the Mapclick point, and if any tank is close enough to each of these positions, an LGB gets dropped onto it (I know, JDAMs are more realistic since they can be multi-targeted....)

If the closest target isn't a tank, then the airstrike is supposed to execute a cluster bomb attack, to take out softer targets.
Code: [Select]
[i]; Finding armored target for laser-guided bombs
_Target = NearestObject [a,b,c]
_Tank = "Tank" CountType [_Target]
? (_Tank > 0) : _TargetPos = GetPos _Target; _tX = _TargetPos Select 0; _tY = _TargetPos Select 1; goto "LGB"
? (_Tank < 1) : goto "CEM"

; GBU-12D Paveway II release
#LGB
_Target = NearestObject [(a+45),(b+5),c]
_Tank = "Tank" CountType [_Target]
? (_Tank > 0) : _TargetPos = GetPos _Target; _tX = _TargetPos Select 0; _tY = _TargetPos Select 1;_obj = "DSL_a10_GBUBomb" camcreate [(_tX+Random 2),(_tY-Random 2),c+180]
~0.3
_Target = NearestObject [(a-42),(b-10),c]
_Tank = "Tank" CountType [_Target]
? (_Tank > 0) : _TargetPos = GetPos _Target; _tX = _TargetPos Select 0; _tY = _TargetPos Select 1;_obj = "DSL_a10_GBUBomb" camcreate [(_tX+Random 2),(_tY-Random 2),c+180]
~0.3
_Target = NearestObject [(a+8),(b+45),c]
_Tank = "Tank" CountType [_Target]
? (_Tank > 0) : _TargetPos = GetPos _Target; _tX = _TargetPos Select 0; _tY = _TargetPos Select 1;_obj = "DSL_a10_GBUBomb" camcreate [(_tX+Random 2),(_tY-Random 2),c+180]
~0.3
_Target = NearestObject [(a-10),(b-40),c]
_Tank = "Tank" CountType [_Target]
? (_Tank > 0) : _TargetPos = GetPos _Target; _tX = _TargetPos Select 0; _tY = _TargetPos Select 1;_obj = "DSL_a10_GBUBomb" camcreate [(_tX+Random 2),(_tY-Random 2),c+180]

~10
hint "AIR SUPPORT\n\nStrikers report hits in target area, returning back to CAP station. Standby."
[b]goto: "Check"[/b]

#CEM
~3
; Bomblet release
#Loop2
_obj = "BLU97" camcreate [(_tX+Random _randomX-Random _offsetX),(_tY+Random _randomY-Random _offsetY),c+200]
_amount = _amount - 1
~0.005
? (_amount > 0 ) : goto "Loop2"
~10
hint "AIR SUPPORT\n\nStrikers report hits in target area, returning back to CAP station. Standby."
[b]goto: "Check"[/b][/i]

Unfortunately, after the new code was written in, the script doesn't work as described above anymore. The goto: "Check" line seems to be screwing things up - both attacks are executed when only laser guided bombs are supposed to.

The following is the "Check" section...

#Check
~10
airstrikecounter = _keep
?(_keep>=3): hint "AIR SUPPORT\n\nStrikers now winchester on weapons and returning to base. Good luck."; exit
?(_keep<3): hint "AIR SUPPORT\n\nStrikers back on station, ready for another run. Awaiting instructions."; exit


Any help would be greatly appreciated.

Try to enclose code between code tags please, it makes it easier to read if you separate normal text from the code.  Planck
« Last Edit: 12 Jul 2007, 13:55:13 by Planck »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Noob here, need a tiny bit of help
« Reply #1 on: 12 Jul 2007, 11:26:45 »
The error message means basicly the same as the old 'syntax error' I guess..  :scratch:

There is no such thing as goto: "label".
Try changing it to goto "label", just like you have elsewhere in the script.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline D-scythe

  • Members
  • *
Re: Noob here, need a tiny bit of help
« Reply #2 on: 12 Jul 2007, 19:09:57 »
Duh  :scratch: Thanks a lot.

Offline D-scythe

  • Members
  • *
Re: Noob here, need a tiny bit of help
« Reply #3 on: 19 Jul 2007, 02:31:17 »
Wow, this nearestObject thing is killing me. I searched the forums and looked at the COMREF stuff, but for the life of me I don't know why it works sometimes and not other times.

In the desert island, the following script works fine. On any other island with trees and crap, the thing just falls apart.

Code: [Select]
;To find Tank targets
_gps = "ffur_CASTarget" camcreate [a,b,c]
_T80 = nearestObject [_gps,"T80"]
_Tank = "Tank" CountType [_T80]
deleteVehicle _gps
?(_Tank > 0) : goto "LGB"; hint "Attacking with LGBs."

I put a platoon of T-80s on a hill-top, with like 1 tree and 1 bush within the 50 m radius of [a,b,c], and it's just not working. It won't even give me the "Attacking with LGBs" message.

EDIT: Nevermind, fixed it. Seems my problem wasn't with NearestObject, but rather "OnMapsingleclick" z-value for position was screwing things up. Set up the z's to 0 and that solved things.
« Last Edit: 19 Jul 2007, 04:16:02 by D-scythe »

Offline D-scythe

  • Members
  • *
HARM script
« Reply #4 on: 21 Jul 2007, 20:44:06 »
If anyone's interested, I put together a very basic anti-radiation missile script, based on a lot of other people's work/stuff I found here (like Franze and Sefe's). I did a search, and didn't find any ARM script (lots of guided missile scripts though), so what the heck.

Basically, it first scans a set distance ahead of the missile, and when it finds a target it starts the anti-radar tracking code. The script makes the missile track that target by looking looking at the x-y and z angle differences between the positions of the missile and the target, then adjusts the missile's speed vector accordingly. Also, right off the bat, it deletes the original missile fired by the player so that the script can run missile attacks against valid SAM/AAA targets without worrying about the missile attacking/locking other targets.

Deleting the original missile and replacing with a new, unguided one.
Code: [Select]
_ah64d = _this select 0
_hellfire = _this select 1
_vel = (velocity _hellfire)
_mPos = getPos _hellfire
_dirmis = (getDir _hellfire)

deleteVehicle _hellfire
_missile = "ffur_lbhf" camcreate _mPos
_missile setvelocity [(_vel select 0),(_vel select 1),(_vel select 2)]
_missile setdir _dirmis

The "Scan" code is rather primitive and crude, and only looks for BIS Shilkas.

Code: [Select]
#ScanPoint
?(!alive _missile): exit
~0.01
_vel = (velocity _missile)
_mPos = getPos _missile

;Scan point, 270m ahead of missile
_xScan = (_mPos select 0) + (_vel select 0)*0.9
_yScan = (_mPos select 1) + (_vel select 1)*0.9

;Search for targets in five ~50x50m killboxes around scan point
; Killbox I
_harmtarget = "ffur_HARMTarget" camcreate [(_xScan-50),(_yScan-50),0]
_Target = nearestObject [_harmtarget,"ZSU"]
_radar = "ZSU" CountType [_Target]
deleteVehicle _harmtarget
?(_radar > 0) : goto "ARMtrack"
; Killbox II
_harmtarget = "ffur_HARMTarget" camcreate [(_xScan+50),(_yScan+50),0]
_Target = nearestObject [_harmtarget,"ZSU"]
_radar = "ZSU" CountType [_Target]
deleteVehicle _harmtarget
?(_radar > 0) : goto "ARMtrack"
; Killbox III
_harmtarget = "ffur_HARMTarget" camcreate [(_xScan-50),(_yScan+50),0]
_Target = nearestObject [_harmtarget,"ZSU"]
_radar = "ZSU" CountType [_Target]
deleteVehicle _harmtarget
?(_radar > 0) : goto "ARMtrack"
; Killbox IV
_harmtarget = "ffur_HARMTarget" camcreate [(_xScan+50),(_yScan-50),0]
_Target = nearestObject [_harmtarget,"ZSU"]
_radar = "ZSU" CountType [_Target]
deleteVehicle _harmtarget
?(_radar > 0) : goto "ARMtrack"
; Killbox V
_harmtarget = "ffur_HARMTarget" camcreate [_xScan,_yScan,0]
_Target = nearestObject [_harmtarget,"ZSU"]
_radar = "ZSU" CountType [_Target]
deleteVehicle _harmtarget
?(_radar > 0) : goto "ARMtrack"

goto "ScanPoint"

ARM tracking code, also rather brute - I'm sure there are more efficient ways to do this.
Code: [Select]
#ARMtrack
?(!alive _missile): exit
~0.0001
;Calculate heading and height difference between missile and target
_mPos = getPos _missile
_targetPos = getPos _Target
_delalt = (_targetPos select 2) - (_mPos select 2)
_dirmis = getDir _missile

_ang = ((_targetPos select 0) - (_mPos select 0)) atan2 ((_targetPos select 1) - (_mPos select 1))
?_ang < 0:_ang = _ang + 360

#Angle
_angleDif = _ang - _dirmis
?(_angleDif > 180): _angleDif = _angleDif-360
?(_angleDif < -180): _angleDif = 360+_angleDif

?(abs _angleDif)>60: goto "ScanPoint"

;Horizontal angle change
?(_angleDif > 2): _angleDif = 3
?(_angleDif < -2): _angleDif = -3

;New missile direction

_dirmis = _dirmis + _angleDif
_missile setdir _dirmis

;Vertical Angle/Speed Change
_range = _missile distance _Target
?(_range < 5): exit
_velz = 300*(_delalt/_range)
_range = (300^2-(_velz)^2)^0.5
_velx = _range*(sin(_dirmis))
_vely = _range*(cos(_dirmis))
_missile setvelocity [(_velx),(_vely),(_velz)]

goto "ARMtrack"

exit

Might try my hand at coding a killer AMRAAM missile next, with all the bells and whistles like proportional navigation, ECCM/chaff rejection.

 
« Last Edit: 21 Jul 2007, 20:46:14 by D-scythe »

Offline D-scythe

  • Members
  • *
ASL Problem
« Reply #5 on: 22 Jul 2007, 01:09:07 »
Can anyone tell me why I keep getting an error message with this code? It started cropping up when I implemented new code that calculates height difference from sea level, so the affected variables should be _velZ, _aslMis/Tar.

Error: _missile setvelocity [(_velX),(_velY),(_velZ)]|#| Type any, expected number

I can't for the life of me see what's going wrong. _velZ is obviously a freakin' number, and in the "Variables and Arrays" tutorial an "any"-type variable isn't even listed as one of the possible types.

Code: [Select]
#Compute ASL for both missile and target
_hx = mPos select 0
_hy = mPos select 1
_dist = _logic distance _missile
_ground = (_hx^2)+(_hy^2)
_aslMis = ((_dist^2)-_ground)^0.5

_hx = _targetPos select 0
_hy = _targetPos select 1
_dist = _logic distance _Target
_ground = (_hx^2)+(_hy^2)
_aslTar = ((_dist^2)-_ground)^0.5

_aslTar = (_aslTar) - (_aslMis)
_range = _missile distance _Target
_velZ = 300*(_aslTar/_range)
_range = (300^2-(_velZ)^2)^0.5
_velX = _range*(sin(_dirmis))
_velY = _range*(cos(_dirmis))
_missile setvelocity [(_velX),(_velY),(_velZ)]

« Last Edit: 22 Jul 2007, 01:12:32 by D-scythe »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Noob here, need a tiny bit of help
« Reply #6 on: 22 Jul 2007, 02:02:54 »
Are the other local variables declared anywhere?

_range, _dirmis and any others.

Unless they are declared elsewhere in this script that you haven't shown us.

If they are declared in another script they will not be local to this one.


Planck
I know a little about a lot, and a lot about a little.

Offline D-scythe

  • Members
  • *
Re: Noob here, need a tiny bit of help
« Reply #7 on: 22 Jul 2007, 02:36:02 »
No, they're all local variables. _dirmis has been declared earlier in the same script, but the other variables (_hx/y, _velX/Y/Z, _range, _ground, _dist and the _aslXX variables have been declared no where else anywhere.

I'm almost certain the problem is _velZ (and it's associated variables from the above sea level calculations). The HARM missiles are tracking targets fine laterally in OFP - just not in the Z-axis, so they tend to overfly their targets and sail off to some empty space. Unfortunately, I still can't figure out what to do - "Type Any, expected Number" means nothing to me, because as far as I can tell, _velZ is a number variable.