OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Aldo15 on 23 Jan 2012, 18:32:07
-
Hi,
I'd like to know if there's some script or command to know the real position of 'handgrenade' or 'smokegrenade'
For example I throw a 'handgrenade' to certain position and then I want to know what's its position in the map.
-
Ok, you will need to use a 'fired' eventhandler:
this addEventHandler ["fired",{(nearestObject [_this select 0,_this select 4]) exec "bomb.sqs"}]
The script (bomb.sqs) will need this
@isNull _this
'_this' is the name of the projectile, so in your case it will be the handgrenade or smoke grenade
So, what you need is to find out the x,y,z of _this before it detonates (before it ceases to exist basically).
So, after the 'bomb.sqs' is called, I think you need to add a delay (whilst the projectile is in flight), and then use:
hint format ["%1", getpos _this]
...before you use the 'isNull' command.
I think that's it. You could try finding out whether or not you can obtain the coordinates after the detonation.
Syntax not guaranteed.
Hope this helps
Gruntage
EDIT: This method is no good for very fast projectiles like tank shells, but good for slow moving bombs or grenades.
-
Hey gruntage, your example doesn't work. :dunno: Well I did your example and I get a hint with following coordiinates [0,0,0]. So I made a script to know its position and I get a hint wiht my coordinates. I want to have grenade coordinates. This is what I got [Hg-69] that was my position. This is the script
_letras1 = ["A","B","C","D","E","F","G","H","I","J"]
_letras2 = ["a","b","c","d","e","f","g","h","i","j"]
_numeros1 = ["9","8","7","6","5","4","3","2","1","0"]
_numeros2 = ["9","8","7","6","5","4","3","2","1","0"]
_maxx1 = 12800
_maxx2 = 1280
_maxy1 = 12800
_maxy2 = 1280
_xu = getPos _this select 0
_yu = getPos _this select 1
_zu = getpos _this select 2
_l1 = 10 * _xu / _maxx1
_l1 = _l1 - (_l1 mod 1)
_n1 = 10 * _yu / _maxy1
_n1 = _n1 - (_n1 mod 1)
_xu = _xu - _l1*_maxx2
_l2 = 10 * _xu / _maxx2
_l2 = _l2 - (_l2 mod 1)
_yu = _yu - _n1*_maxy2
_n2 = 10 * _yu / _maxy2
_n2 = _n2 - (_n2 mod 1)
_coordstrt1 = format["%1%2-%3%4", _letras1 select _l1, _letras2 select _l2, _numeros1 select _n1, _numeros2 select _n2]
@isNull _this
hint format ["%1", _coordstrt1]
What I want to throw a 'smoke grenade' and then some unit or vehicle is moved to its position
-
Well I did say 'syntax not guaranteed' lol, and this is why.
The script I used as an example is used to get the coordinates of where an LGB hits.
After a little bit of searching, here's what looks like a solution:
player addEventHandler ["Fired", {_this exec "smoke.sqs"}]
That's the eventhandler you use...
_ammo = _this select 4
_shell = nearestObject [player, _ammo]
_smoke_types = ["SmokeShell","SmokeShellRed","SmokeShellGreen"]
if !(_ammo in _smoke_types) then {goto "end"}
;Wait till the shell is stopped
@speed _shell < 0.1
_pos = [getPos _shell select 0, getPos _shell select 1, 0]
;Wait 10 seconds while generating big enough smoke cloud
~10
;landing code here
#end
exit
The 'landing code' part is obviously for directing the chopper to the location of '_pos'.
There are actually plenty of threads around addressing this issue. So, this is one of those occasions where the search function is your friend :)
These two codes should work now, but as always, syntax not guaranteed ::)
-
Fine. I'll try this one, but a question: must 'doMove' command be written after 'Landing code'? For example:
_chopper domove _pos
-
I believe so. If you want a big smoke cloud to develop then you have to put your 'domove' command after the 10 second delay.
EDIT: I would probably use 'setwppos' instead of 'domove'
-
Gruntage, the reason why your first code didn't work is that you try to get the grenade's position after it has been destroyed in which point it obviously doesn't exist in any position anymore..
The way I use is a loop that updates the position into a variable, something like this:
this addEventHandler ["fired",{_nade = (nearestObject [_this select 0,_this select 4]); if ((_this select 4) in ["SmokeShell","SmokeShellRed","SmokeShellGreen"]) then {[_nade,choppername] exec "whatever.sqs"}]
_nade = _this select 0
_chopper = _this select 1
#loop
_pos = position _nade
if (!(alive _this) goto "choppa"
~0.01
goto "loop"
#choppa
_chopper doMove _pos
; wait for the chopper to start moving
~10
; wait until the chopper arrives
@isReady _chopper
;land the chopper
_chopper land "GET IN"
No idea if that script works at all, it has been years since I did anything with sqs.. :dunno:
-
Guys it doesn't work. :weeping:
-
Well, one of the reasons why it won't work (at least when it comes to moving the chopper) is that there isn't a command '@isReady' :D
#choppa
_chopper doMove _pos
; wait for the chopper to start moving
~10
; wait until the chopper arrives
@unitReady _chopper
;land the chopper
_chopper land "land"
My advice to you Aldo is to search around a little. There were a lot of threads addressing this issue a while back.
If I get time later I'll have a little play around with it and see if I can get the script working.
-
Oops :-[
Remembered the command wrong, it's unitReady (http://www.ofpec.com/COMREF/index.php?action=details&id=377&game=All) :whistle:
And there is a command @
It's basically the same as waitUntil in A1/A2 (waitUntil is just a bit more usable), it's a "looping pause" kind of thing, it waits until the condition becomes true (performs check on every frame), so in this case the script waits until the unitReady _chopper becomes true.
The command is missing from our COMREF which should be fixed in the near future (it's actually missing from BIS wiki command reference too)..
_nade = _this select 0
_chopper = _this select 1
#loop
_pos = position _nade
if (!(alive _this) goto "choppa"
~0.01
goto "loop"
#choppa
_chopper doMove _pos
; wait for the chopper to start moving
~10
; wait until the chopper arrives
@unitReady _chopper
;land the chopper
_chopper land "GET IN"
-
But what must I put in unit's init?
-
this addEventHandler ["fired",{_nade = (nearestObject [_this select 0,_this select 4]); if ((_this select 4) in ["SmokeShell","SmokeShellRed","SmokeShellGreen"]) then {[_nade,choppername] exec "whatever.sqs"}]
Syntax not guaranteed...
-
Aldo,
Try the attached demo mission. The scripts are all commented and also read the readme files and the included file that explains eventHandlers.
-
Ok Thanks Raptorsaurus.