Home   Help Search Login Register  

Author Topic: Artillery observer script.  (Read 934 times)

0 Members and 1 Guest are viewing this topic.

Robinhansen

  • Guest
Artillery observer script.
« on: 20 Feb 2005, 12:52:36 »
Here's a challenge. How do I make a script that alloweds the player to click any place on a map, and then recive a message saying the angle and distance between the player and the click on the map.

With such abilityes it would actually be possible to deliver fire support in a MPgame using fx. Our Weapons BM-21 etc...

 :D

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Artillery observer script.
« Reply #1 on: 20 Feb 2005, 14:25:31 »
This has been done many times.   You should definitely become familar with snYpir's SP/MP support pack before attempting to reinvent the wheel.

For the particular point you raise, it's just a combination of onMapSingleClick (which is a slightly tricky command, there is a fair bit of information about it scattered around ofpec) and simple trigonometry.    There are also plenty of trig guides scattered about, somebody posted it just the other day.  THobson I think.
Plenty of reviewed ArmA missions for you to play

Robinhansen

  • Guest
Re:Artillery observer script.
« Reply #2 on: 21 Feb 2005, 20:11:48 »
Well as far as I recall the supportpack only gives the grid when click on map, and not the angel and distance. The reason why I started this topic is that even though such script would be a pice of cake for somebody, I still know to little about scripting.

 ;)

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Artillery observer script.
« Reply #3 on: 22 Feb 2005, 02:40:19 »
Use the forum search function and check THobson's posts over the last few days.    
Plenty of reviewed ArmA missions for you to play

Dubieman

  • Guest
Re:Artillery observer script.
« Reply #4 on: 22 Feb 2005, 02:50:05 »
Also check out COC arty since they have made "real" arty, the shell that comes out of the barrel is the same one landing on the enemy positions. ;)

And maybe you could extract something if you depbo their work and learn from it.

Robinhansen

  • Guest
Re:Artillery observer script.
« Reply #5 on: 22 Feb 2005, 20:43:27 »
I found such a script made by Dinger (CoC).

http://www.ofpec.com/editors/browse.php?browseon=&browsewhat=-1&catselected=-1_-1&catagory=-1&subcategory=-1_-1&numreturn=25&displayformat=0&ofpv=1&searchwhat=1&searchlevel=0&searchwhat=1&searchopts=&searchstring=Artillery+suite&x=26&y=14

What it does is actually giving the distance and angle, using the laser designator. I only need to convert it in to OnMapSingleClick.

But how?

_alphanames = ["A","B","C","D","E","F","G","H","I","J"]
_numeric = ["9","8","7","6","5","4","3","2","1","0"]

forcelasertargetlost = false
?(InitLLDrunning):forcelasertargetlost = true; exit
InitLLDrunning = true
laseron = false
_player = player
lasermode = 0
#MainLoop
player removeaction initlld
(vehicle player) removeaction initlld

#getlaze
detectlaser setpos getpos _player
?not((player hasweapon "LaserDesignator") or ( (vehicle player) hasweapon "LaserDesignatorOH")):goto "noLLD"
?((vehicle player) hasweapon "LaserDesignatorOH"):_player = vehicle player
_timer = _time + 10
@(("LaserTarget" CountType list detectlaser > 0) or (_time > _timer))
?("LaserTarget" CountType list detectlaser == 0):goto "getlaze"
_detectlist = list detectlaser
_n = 0
#FindLaserTarget
?("LaserTarget" counttype [(_detectlist select _n)] > 0):goto "foundtarget"
_n = _n + 1
?(_n < count _detectlist):goto "FindLaserTarget"
hint "OVERRUN"
exit

#FoundTarget
LaserTarget = _DetectList select _n
LaserInitialized = true
publicvariable "LaserInitialized"
publicvariable "LaserTarget"

Titletext ["Laser designator initialized", "PLAIN DOWN", 1]
~1
_lasermodes = ["No display", "Mils", "Degrees", "Grid Readout", "Target XYZ", "Nearest Object", "Teleport", "Death Ray"]
maxmodes = 3
;decomment next line for editing modes
;maxmodes = count _lasermodes
#modes
_nextlasermode = lasermode + 1
?(_nextlasermode == maxmodes):_nextlasermode = 0
_lasermodename = _lasermodes select lasermode
_nextlasermodename = _lasermodes select _nextlasermode
_title = format ["Laser mode: %1", _lasermodename]
TitleText [_title, "PLAIN DOWN", 1]

_player removeaction laserswitch
_player removeaction laseronoff
laserswitch = _player addaction [_nextlasermodename, "SwitchMode.sqs"]
?(lasermode > 5): laseronoff = _player addaction ["Trigger laser", "laseronoff.sqs"]
_lasermodepage = format ["LaserModePage_%1", lasermode]
_nexttime = _time + 2
@(lasermode == _nextlasermode || _time > _nexttime)
TitleText ["", "PLAIN DOWN", 1]
?(Lasermode == _nextlasermode):goto "modes"


#LaserProtoPage
_TargetPos = getpos LaserTarget
_TargetX = _TargetPos select 0
_TargetY = _TargetPOs select 1
?(_TargetX == 0):goto "Lost"
?(forcelasertargetlost):goto "ForceLost"
goto _lasermodepage

#lasermodepage_0
; no display
?(_TargetX == 0):goto "Lost"
_nexttime = time + 3
@(lasermode != 0 || time > _nexttime)
?(lasermode == 0):goto "laserprotopage"
goto "modes"


#LaserModePage_1
;mils
?(lasermode != 1):goto "modes"
goto "SharedDirections"
#LaserModePage_2
;degs
?(LaserMode != 2):goto "modes"
#SharedDirections
_playerPos = getpos _player
_playerX =_playerPos select 0
_playerY = _playerPos select 1
_Xdiff = _TargetX - _playerX
_YDiff = _TargetY - _playerY
_Range = sqrt ((_Xdiff^2)+(_yDiff^2))
?(_Range == 0):goto "wait"
_Xfactor = (_Xdiff/_Range)
_Yfactor = (_YDiff/_Range)
_direction = acos _Yfactor
?(_Xfactor < 0):_direction = 360- _direction
_range = _range - (_range mod 10)
?(lasermode ==1):_direction = 1000* (rad _direction)
_Direction = _direction - (_direction mod 1)
_DirectionName = format ["%1 "+_LAsermodeName, _Direction]
_title = Format ["                                                                      "+_DirectionName+", %1m", _Range]
titletext [_title, "PLAIN DOWN", .3]

#wait
_currentlasermode = lasermode
_nexttime = time + 1
@(lasermode != _currentlasermode || time > _nexttime)
goto "laserprotopage"

#LaserModePage_3
;grid
_gridalpha = ""
_gridnumeric = ""
_a = 2
_factor = 12.8
#calculategrid
_FactorPrime = _factor * (10^_a)
_Xfactor = (_TargetX - (_TargetX mod _factorPrime))/_factorprime
_YFactor = (_TargetY - (_TargetY mod _factorPrime))/_factorprime
_TargetX = _TargetX - (_Xfactor*_FactorPrime)
_TargetY = _TargetY - (_Yfactor*_FactorPrime)
_gridalpha = _gridalpha + (_alphanames select _Xfactor)
_gridnumeric = _gridnumeric + (_numeric select _Yfactor)
_a = _a - 1
?(_a > -1):goto "calculategrid"

_title = "                                                                      Grid:"+_gridalpha + _gridnumeric
titletext [_title, "PLAIN DOWN", .3]
_nexttime = time + 3
@(lasermode != 3 || time > _nexttime)
?(lasermode != 3):goto "modes"
goto "laserprotopage"


#LaserModePage_4
;x, y, z (Debug)
_title = Format ["                                                                      %1",_TargetPos]
titletext [_title, "PLAIN DOWN", .3]
_nexttime = time + 3
@(lasermode != 4 || time > _nexttime)
?(lasermode != 4):goto "modes"
goto "laserprotopage"

#LaserModePage_5
;nearestobject (debug)
@(lasermode != 5 || NearestObject _Targetpos != LaserTarget)
?(lasermode != 5):goto "modes"

_thing = NearestObject _TargetPos
_title = Format ["%1         %2                                    %3",getpos _Thing, speed _thing, _Thing]
titletext [_title, "PLAIN DOWN", .3]
goto "laserprotopage"

#LaserModePage_6
;teleport (debug)
;if you're gonna use this in a mp mission or something
;camcreate some smoke and maybe a flash
;make it look cool.
?(laseron):_Player setpos _targetpos; laseron=false
_nexttime = time + 3
@(lasermode != 6 || time > _nexttime)
?(lasermode != 6):goto "modes"
goto "laserprotopage"

#LaserModePage_7
;death ray
@(lasermode != 7 || NearestObject _Targetpos != LaserTarget)
?(lasermode != 7):goto "modes"
_thing = NearestObject _TargetPos
?(laseron):_thing setdammage 4
goto "laserprotopage"


#Lost
#ForceLost
titletext ["Laser target lost", "PLAIN DOWN", .5]
_player removeaction laserswitch
_Player removeaction laseronoff
InitLLDRunning = false
LaserInitialized = false
publicvariable "LaserInitialized"
~1
titletext ["", "PLAIN DOWN", 1]
?!(forcelasertargetlost):goto "MainLoop"

initlld = _player addaction ["Initialize LLD", "InitLLD.sqs"]
~3
exit

#noLLD
TitleText ["Player has no laser designator", "PLAIN DOWN", 1]
InitLLDRunning = false
LaserInitialized = false
publicvariable "LaserInitialized"
~2
titletext ["", "PLAIN DOWN", 1]
exit

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Artillery observer script.
« Reply #6 on: 25 Feb 2005, 11:08:20 »
Converted for onmapsingleclick:

Call by:
OnMapSingleClick {_pos exec {showPolar.sqs}}

showPolar.sqs:
Code: [Select]
_player = player
_targetX = _this select 0
_targetY = _this select 1
_targetZ = _this select 2

_playerPos = getpos _player
_playerX =_playerPos select 0
_playerY = _playerPos select 1
_Xdiff = _TargetX - _playerX
_YDiff = _TargetY - _playerY
_Range = sqrt ((_Xdiff^2)+(_yDiff^2))
?(_Range == 0):goto "wait"
_Xfactor = (_Xdiff/_Range)
_Yfactor = (_YDiff/_Range)
_direction = acos _Yfactor
?(_Xfactor < 0):_direction = 360- _direction
_range = _range - (_range mod 10)
_Direction = _direction - (_direction mod 1)
_DirectionName = format ["%1 Degrees", _Direction]
_title = Format ["                                                                      "+_DirectionName+", %1m", _Range]
titletext [_title, "PLAIN DOWN", .3]

or you can convert the titletext and the _title thing into a hint message
Dinger/Cfit