Home   Help Search Login Register  

Author Topic: getPos of thrown smokeshell?  (Read 2439 times)

0 Members and 1 Guest are viewing this topic.

Offline subroc

  • Members
  • *
getPos of thrown smokeshell?
« on: 01 Jun 2006, 17:00:16 »
is there anyway to get the position of where a thrown smokeshell has landed?

i would like it to work like this, by radio 0-0-1 a chopper flies to the general area of the player (within ~500 meters or so) and when he pops smoke i want the chopper to land where the smoke is.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re: getPos of thrown smokeshell?
« Reply #1 on: 01 Jun 2006, 17:36:51 »
The SEARCH button is your best friend!

I did not have time to check the contents of the links below, but a simple search found many entries that may answer your question.

Start with the bottom link and work up.

http://www.ofpec.com/forum/index.php?topic=7067.0

http://www.ofpec.com/forum/index.php?topic=6036.0

http://www.ofpec.com/forum/index.php?topic=10149.0

http://www.ofpec.com/forum/index.php?topic=10146.0

http://www.ofpec.com/forum/index.php?topic=13931.0

http://www.ofpec.com/forum/index.php?topic=10479.0

http://www.ofpec.com/forum/index.php?topic=10726.0

http://www.ofpec.com/forum/index.php?topic=23759.0

http://www.ofpec.com/forum/index.php?topic=25654.0

If none of these solves your problem, I have a demo at home somewhere that I may be able to post over the weekend.

Cheers!

Wadmann
Check out my Camouflage Collection! New items added 31 July 2005.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: getPos of thrown smokeshell?
« Reply #2 on: 01 Jun 2006, 17:55:33 »
not sure there's a way to determine where it landed, exactly, but you could fake it. how far can the average human throw a smoke shell? 10 metres?

if you add a fired event handler to whomever is going to do the throwing and point it at a script which checks if it's a smokeshell, you get the position of the thrower. then just add 10 metres in a random direction.

so.

Code: [Select]
throwsmoke = player addeventhandler ["fired", {_this exec "is_it_smoke.sqs"}]
is_it_smoke.sqs


Code: [Select]
;detect a smoke shell thrown

;check if the weapon has been thrown, quit if not
_thrown = _this select 1
?not (_thrown == "throw"):exit

;check if the weapon thrown is a smokeshell, quit if not
_what = _this select 4
?not (_what == "smokeshellgreen"):exit

;find out where player is when the smokeshell was thrown
_who = _this select 0
chopperland = getpos _who

;get rid of the eventhandler
_who removeeventhandler throwsmoke

exit

Offline nindall

  • Members
  • *
Re: getPos of thrown smokeshell?
« Reply #3 on: 01 Jun 2006, 20:21:24 »
You could use the nearestObject command - nearestObject [Object, "Type"]

Code: [Select]
handlerID = player addEventHandler ["Fired", {if (_this select 3 == "SmokeShell") then {[nearestObject [player, "SmokeShell"]] exec "script.sqs"}}]
I did a test involving the above code and it worked. (Don't forget to add a delay at the start of the script to allow the smokeshell to land.)

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: getPos of thrown smokeshell?
« Reply #4 on: 01 Jun 2006, 20:47:43 »
Hmm, I looked into this, cause I've been wondering about this myself. I found a script that didn't (at least not anymore) work, but I got it to work by making some minor changes to it.

just add a EH to the player: player addEventHandler ["Fired", {_this exec "smoke.sqs"}]

then save this as smoke.sqs:
Code: [Select]
_ammo = _this select 4
_smoke_types = ["SmokeShell","SmokeShellRed","SmokeShellGreen"]
if !(_ammo in _smoke_types) then {goto "end"}
_shell = nearestObject [player, _ammo]


#loop
@ (getpos _shell select 2 <=0.5)
_pos = getPos _shell


;landing code here

#end
exit

uh oh, the player setpos _pos was just to check that I got the right pos :P
« Last Edit: 01 Jun 2006, 22:46:56 by Garcia »

Offline subroc

  • Members
  • *
Re: getPos of thrown smokeshell?
« Reply #5 on: 02 Jun 2006, 10:53:27 »
thx all, im really learning alot.

Garcia: that should work for me, only question is the:
@ (getpos _shell select 2 <=0.5)

was does the <=0.5 do?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: getPos of thrown smokeshell?
« Reply #6 on: 02 Jun 2006, 12:33:26 »
@ is the equivalent of saying "wait until"

(getpos _shell select 2 is the height of _shell

<=0.5) is less than or equal to 0.5 metres (50 cm)

Offline subroc

  • Members
  • *
Re: getPos of thrown smokeshell?
« Reply #7 on: 02 Jun 2006, 14:36:09 »
ok, so the getpos wont be taken until the shell is on the ground, i think im getting the hang of it
thx

Offline chops

  • Members
  • *
  • I'm a llama!
Re: getPos of thrown smokeshell?
« Reply #8 on: 04 Jun 2006, 08:39:25 »
How can you set an object already on the map to the position where the smokeshell lands?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: getPos of thrown smokeshell?
« Reply #9 on: 04 Jun 2006, 10:27:48 »
Smoke grenade objects are "alive" for more than 15 seconds after hiting the ground. Using Garcia'sl fired event handler and script:


Code: [Select]
_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

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: getPos of thrown smokeshell?
« Reply #10 on: 04 Jun 2006, 12:42:36 »
How can you set an object already on the map to the position where the smokeshell lands?

You mean a object that is on the island or a object you placed in the editor from the start? If the first I don't think you can. In earlier version of OFP you could (I think), but BIS changed that in a patch. If the second, then just use the script Mandoble posted and setpos the object to _pos:

Code: [Select]
objectname setpos _pos

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: getPos of thrown smokeshell?
« Reply #11 on: 04 Jun 2006, 14:05:54 »
A side note about sending helicopters at the smoke position. If the helicopters are too far away, they may timeout before resolving the path between their position and the smoke object, and they will not come. Typical case when you try to move an helicopter from one extreme to the other of an island. These timeouts are more frequents with low end computers or when mission itself consumes a lot of CPU.

I use the following script to solve that problem. You provide how far will move the helicopter in each step until reaching the destination (2000m for example is a safe value).

Code: [Select]
;mandoairpath.sqs by Mandoble
;
;Allows long flying traves avoiding the timeouts while resolving paths
;Arguments
;flyin unit
;final position
;Maximum length in meters of each travel segment
;flying height
;Maximum allowable damage before ejecting
;script to be executed upon arrival (receives flying unit as argument), "" if not needed.
;script to be executed when ejecting (receives flying unit as argument), "" if not needed.
;Camera following air unit true/false
;
;Examples:
;
;[heli1,getMarkerPos "mk_land",2000,40,0.5,"landnow.sqs","ejectnow.sqs",true]exec"mandoairpath.sqs"

_unit          = _this select 0
_finpos        = _this select 1
_length        = _this select 2
_height        = _this select 3
_maxdmg        = _this select 4
_arrivalscript = _this select 5
_ejectscript   = _this select 6
_camera        = _this select 7

?_height > 80:_height = 80
?_maxdmg > 0.9:_maxdmg = 0.9
?_camera: _unit switchCamera "EXTERNAL"
_driver = driver _unit
_pos1 = [getPos _unit select 0,getPos _unit select 1,0]
_log1 = "logic" camCreate _pos1
_log2 = "logic" camCreate _finpos
_log3 = "logic" camCreate [0,0,0]
_dist = _log1 distance _log2
_ang = ((_finpos select 0) - (_pos1 select 0)) atan2 ((_finpos select 1) - (_pos1 select 1))
_steps = _dist / _length
_i = 0
_pos = _pos1

#move
_dist = _log1 distance _log2
?_dist > _length:_dist = _length
_pos = [(_pos select 0) + sin(_ang)*_dist,(_pos select 1) + cos(_ang)*_dist]
_log3 setPos _pos
_driver doMove _pos
_unit flyInHeight _height
~1
@((_unit distance _log3) < 1000) || (damage _unit > _maxdmg)
?(damage _unit > _maxdmg): goto "eject"
?(_unit distance _log2) < 1050: goto "goal"
_log1 setPos _pos
_i = _i + 1
?_i < _steps:goto "move"

#goal
_driver doMove _posfin
~1
@((unitReady _driver) || (damage _unit > _maxdmg))
?(damage _unit > _maxdmg): goto "eject"
?_arrivalscript != "":[_unit]exec _arrivalscript
#exit
deleteVehicle _log1
deleteVehicle _log2
deleteVehicle _log3
?_camera: player switchCamera "EXTERNAL"
exit

#eject
?_ejectscript != "":[_unit]exec _ejectscript
goto "exit"

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: getPos of thrown smokeshell?
« Reply #12 on: 10 Jun 2006, 10:47:50 »
[offtopic]

Just a quick note about how you guys start scripts from fired event handlers: start the script only if your conditions are met, like in nindall's example. Or better yet, don't start the script at all even if conditions are met. Just think about what happens when the player fires an automatic rifle, emptying the clip in one go. Also what if you have this event handler attached to many units on the same map? Your script would be started only to exit right away in almost all of the cases without a doubt. You don't want to start your script for nothing that many times, or do you? Try to put everything into the event handler itself if possible (a delay will not work there).

Discussion around this and also a handy tip to stuff code into event handlers can be found from a BIS forum thread  Need help with Fired Script and Event Handlers, Need an in depth explanation.

[/offtopic]