Home   Help Search Login Register  

Author Topic: Is it possible to obtain the position of a fired bullet ?  (Read 1511 times)

0 Members and 1 Guest are viewing this topic.

Offline Roni

  • Members
  • *
  • Play the Game !
Hi All

What it says up top.   ::)

I'm working on a group suppression script and I want to be able to determine when bullets are whizzing past or landing nearby.  EventHandler "fired" doesn't seem to give any info about the bullet itself and I don't want to use eventHandler "hit" as this is supposed to simulate suppressive fire, not aimed fire.

Ideally I'd like some way of returning the final resting position of (say) every nth round fired by a given unit, with n determined semi-randomly (eg random 10 < 1, random 20 < 1 etc).

The idea would be to allow a unit to spray fire into an area on order from the group leader using an onMapSingleClick, a gamelogic and doFire command and work out cowering effects for every unit within (say) 10m of that point.

I want to combine the above with more inaccurate fire (JAM or setdammage -1) and see if I can get some good long lasting firefights.  The goal is to get one side supressing the other with its MG's while it moves its maneuver group in to flank positon and/or grenade range.

If anyone know how to return a fired bullet's final position I'd be greatly appreciative !

Cheers



roni

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #1 on: 10 Mar 2005, 02:41:06 »
The fired EH does pass the classname of the bullet just fired in _this select 4. So use the nearestobject function, and you should be able to "catch" the bullet, unless it moves too fast (only happens with some vehicle weapons I think):

_bullet = nearestobject [_this select 0, _this select 4]

I may have that switched around, so double check on the syntax. After you have "caught" the bullet, you can do many things. In your case, you want to find out where it lands, so you just need to make a loop that constantly records the position of the bullet until it disappears. You can tell if the bullet has disappeared because it won't be an object anymore. A handy fact is that all null objects/groups/variables/etc are never equal to anything, including themselves. So the script could look like this:

Code: [Select]
_bullet = nearestobject [_this select 0, _this select 4]
#loop
_pos = getpos _bullet
~0.001
? _bullet == _bullet : goto "loop"

; (at this point _pos will contain the last position of the bullet before it disappeared)

You may want to change the delay to be shorter or longer, but I think the lowest delay is 0.0001. If you only want to catch bullets randomly, then just 'roll some dice' at the start of the script (? random 1 > .5 : exit), or else use the "ammo" command to find out how many bullets are left in the unit's magazine. Also bear in mind that you may want to do some checks to see if the unit fired a rifle, a grenade, a LAW, etc.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #2 on: 10 Mar 2005, 03:03:54 »
Thank you so very much for that GB - I knew that it was possible.  As they used to say at NASA - "Anything is possible, the impossible just takes longer !".

I'd already figured out how to winnow out all but the nth bullet, I just wasn't sure how to catch the darn thing in the first place !

My only concern is what will happen to lag if I start checking every single bullet fired and tracking every 10th one until it comes to rest.  IMHO OFP firefights actually tend to be a bit light on the volume of firepower that units put out (see any video from Vietnam or Iraq to see what I mean), so this might not be a problem.

The full "grab, track, locate rest point, check reaction of nearby units" routine won't be actioned for every round so the lag shouldn't be too bad.  In fact, depending on how many rounds DO actually get fired in a typical OFP firefight I may make it only every 30th or 40th round that creates the effect.  That should REALLY bring MG's in to their own !

I'll try to get this together this weekend and post a beta on the board by Sunday night.

cheers and thanks again   :cheers:



roni

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #3 on: 10 Mar 2005, 08:44:41 »
If I was you I would 'catch' the bullet straight from the unit's fired eventHandler, otherwise there can (and will) be a chance that the bullet is 'missed' when there's desync or lag happening...

So,
Code: [Select]
_unit addEventHandler ["fired",{(nearestObject [_this select 0,_this select 4]) exec "whatever.sqs"}]
And in 'whatever.sqs':
Code: [Select]
#blahblah
_bulletPos = position _this

? !(isNull _this): goto "blahblah"
etc....

But, there is no loop that can keep up with rifle bullets as discussed in this thread (but I think the problem was solved at the end):
http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=22254

The @true loop I suggest there works for one MCAR vehicle just because it shoots a 'very' slow projectile so OFP sqs can keep up with it...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #4 on: 11 Mar 2005, 01:50:58 »
Thanks HR, I'll try that tonight.

I already have a very rough test version running - at the moment I'm pissing around with all the things I can do with this EH.

One test simply camcreated a flag pole ("FlagCarrier") at the bullets final rest point.  It was interesting to note that even with no delay step between the getPos updates there was about a 5m gap between the bullet's final resting point and the creation point of the object.  OFP must run script steps slower than it runs bullet updates !

The second test created a Shell73 instead - that turned my MG into a fully automatic rocket launcher !  The neat thing was that due to the script lag and depending upon the loop delay setting if the bullet hadn't gone at least 10m or so then it wouldn't blow up (ie no bulletPos so no shell creation !).

Another test stopped the bullet in mid air with a getpos / setpos routine.  I couldn't actually see the bullet so to see where it was I tried creating various other things at that point.  In the end I created a Shell73 in each step of the loop - I found that if I fired near straight up then all of the shells would hit each other and make a beautiful cascade of fireworks.  Again, due to some lag effect the cascade would end and the last shell would drop out and land next to me !  Oh well !  :beat:

What I'm working on now is getting all of the units within (say) 20m of that final point, then having them do something so that I know that they were "affected".  I was thinking about one of setdammage 1, play a clearly ndentifiable animation or camcreate a flagpole over their head.  I like the flagpole idea - I use it a lot when testing my scripts - nothing beats a 30 foot pole floating 10m over your head pointing out exactly where you are !     ::)

I've set up a trigger with activation Any Present, I am now in the process of looking up my refs to find out how to get the array of all current members satisfying that trigger.  If anybody wants to save me a half an hour of searching that would be great !    :P

I've also tested various "nth" tests and am sort of settling on every 15-20 rounds creating the effect.  It means that rifle firefights usually produce the effect about once or twice per clip, while an MG can create it with one long burst.  Snipers of course can't really do it unless they go wild with their fire.

More news as I make it.  And FWIW, I've attached the "pre, pre-alpha" version of the script to this post (the cascade of shells version !)

 :gunman:        :tomato:

Cheers !



roni

EDIT - Fixed annoying typos . . .  :-[
« Last Edit: 11 Mar 2005, 03:03:57 by Roni »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #5 on: 11 Mar 2005, 01:59:26 »
Quote
It was interesting to note that even with no delay step between the getPos updates there was about a 5m gap between the bullet's final resting point and the creation point of the object.  OFP must run script steps slower than it runs bullet updates !
Check the thread HateR_Kint linked to: it talks about exactly this.

Quote
I've set up a trigger with activation Any Present, I am now in the process of looking up my refs to find out how to get the array of all current members satisfying that trigger.  If anybody wants to save me a half an hour of searching that would be great !    

Two commands work equally well:
#1: In the "on activation" field of the trigger, write: VAR_NAME = thislist
#2: Name your trigger, and then in a script, you can refer to it's list with the command:
   list TRIGGER_NAME
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #6 on: 11 Mar 2005, 02:19:50 »
Once again, thanks for that.

I've ben having heaps of fun with this EH.  Previously I'd used to overlay new sounds for certain weapons (does a silenced HK REALLY sound that lame ?), now I realise that it can be used to create new weapon effects.

For example - I could take a stock standard M16, overlay a new "fired" sound, then camcreate a Shell120 with position, bearing and velocity exactly the same as the original shell(note to self - need to work out incidence angle too . . .  :joystick: ).  Alternatively, I could wait until the bullet hits something THEN camcreate the explosion.

I can make a "surrender gun" - ever time in fires everyone within 20m of where the bullet lands drops their weapon, stands up and surrenders.

I can make a "spawn gun" - fire it and create new group members (shouldn't I adda step that only does this if I throw a smoke grenade on the ground ?)  :D

I can make a gun that accelerates time, blows everyone back 50m, projects houses or anything else I want.

Okay, nuff fantasising- back to reality.



roni

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #7 on: 11 Mar 2005, 08:43:18 »
Quote
OFP must run script steps slower than it runs bullet updates
Most likely because external sqs code has lower CPU priority than the game engine stuff has..

Quote
that turned my MG into a fully automatic rocket launcher !
::)
*khm! MCAR... khm!*


Just remember that a bullet in OFP 'lives' only for 2-3 secs after which it vanishes and is considered by OFP of being 'isNull' and '!alive' so your explosions etc could be created in pretty odd places at times if you don't take this into account...
You can use something like this in the script to avoid that:
? _time >= 2.2: exit

_time is OFP reserved variable that tells you how long a script has been running...
And is saved by OFP savegame, unlike time...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Is it possible to obtain the position of a fired bullet ?
« Reply #8 on: 11 Mar 2005, 10:46:12 »
Just remember that a bullet in OFP 'lives' only for 2-3 secs after which it vanishes and is considered by OFP of being 'isNull' and '!alive'

That was the reason for the getpos / setpos routine.  I was hoping to be able to freeze a bullet in flight and then walk in to it.  My understanding is that when bullets die they cause damage to anyone that they are in contact with.  I was hoping to be able to make a "mine gun" - fire bullets at a spot and if anyone walks there they take damage.

All in good fun of course !



roni