Home   Help Search Login Register  

Author Topic: Need Help! NearestObject is killing me!  (Read 807 times)

0 Members and 1 Guest are viewing this topic.

Grendel

  • Guest
Need Help! NearestObject is killing me!
« on: 06 Apr 2004, 19:52:17 »
Hey Guys!

I need someone that is very well versed in scripting, and good with the NearestObject command in particularâ€Â¦who also doesn't mind reading a long post.

Here's what I'm trying to do:

I am making a script to enhance the effects of round impact, specifically large caliber anti-material sniping ammo in the .50 Raufoss-20mm AP/HEI-T range (look up the South African NTW-20 addonmakers :)).  I need my script to do a few things:  1) determine if the round hit a target, 2)determine the type of the target, 3) create specific effects for each case.

I have a bunch of nifty drop effects already done up; a "steel on steel" effect with sparks and such for hard targets, an effect for soft targets that gives the appearance that the target was vaporized (like the guy in Saving Private Ryan that gets hit by the 20mm Flak), and a dirt impact/ricochet effect when you don't hit crap.  

There are two approaches I can take (that I know of).  One would be to use an EH "fired" for the player, and EH "damaged" assigned to every enemy unit via an uber-trigger/foreach thislist, but I think this approach has several disadvantages.  For one, the EH "damaged" only activates if a certain percentage of damage is inflicted, so a rifle wouldn't trigger it on a tank. And two: I'm not sure, but wouldn't hundreds of EH's slow things down cycle wise?

What I want to do is have my bullet tracking script call a NearestObject command when it's speed reaches zero (impact).  So far, the script captures the bullet's speed fine and gives me a [x,y,z] within a meter or so of impact, so that part is good.  I can't, however, get it to find the nearest object.  I tried setpos'ing a gamelogic (named "spl") at the impact coordinates, and using it to find nearestobject, but it didn't work.  Heres the Syntax I tried to use:
Code: [Select]
spl nearestobject [spl,"All"]From what I could gather trying to find the answer elsewhere on the forums, am I going to have to separately specify every possible object in place of the "All"?  If this is the case would a looped nearest position work? Could I use an uber-trigger and script to put all possible typeof's in the nearestobject array? Arrghhh!!

Does anyone have any suggestions/tips and a better way to explain how the Syntax of the NearestObject command works (especially the array portion)? :'( :-\

I would greatly appreciate (and credit) any help!
-Grendel

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Need Help! NearestObject is killing me!
« Reply #1 on: 06 Apr 2004, 20:09:36 »
No expert here, but have you considered nearestbuilding?

Presuming your bullet still exists when it impacts, it is an object......so :

_obj = nearestbuilding bulletname........might return the name of the nearest object.
This would have to be checked after your bullet has stopped though.

Just an idea........I haven't tried it or anything.


Planck

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

sa8gecko

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #2 on: 06 Apr 2004, 20:37:14 »
Quote
spl nearestobject [spl,"All"]
doesn't work. You need to be type specific to find something
with this syntax, ie "M1A1", "Hellfire","RPG" and so on.
perhaps this way:
target = nearestobject [x,y,z]
? "landVehicle" countType [target] == 1: goto ...
? "man" countType [target] == 1: goto ..
and so on

Grendel

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #3 on: 06 Apr 2004, 21:39:04 »
 :DHA HA!! Hey sa8gecko! I knew I could count on you!

The funny thing is, I just posted another reply on the official forum thread asking you for help after seeing the replies you made!

Between that thread and this one I think I'm on the right track now...

I posted some code on the official forum, I'll paste it over here as well in a few.

Thanks Guys!

-Grendel

Here's the code I think might work as far as getting the object itself...


Code: [Select]
;where _bx/_by/_bz are the bullet's final coordinates...

;place gamelogic at impact coordinates for range info...

gamelogic setpos [_bx,_by,_bz]

;check to see if impact altitude is greater than 1...
?(_bz>1):goto "goodaltitude"
_bz=_bz+1
#goodaltitude

;find nearest object to impact coordinates...
_target= nearestObject [_bx,_by,_bz]

;check for null object ***is this syntax right???***
?(_target isNull):goto "notarget"

;get distance from impact to target
_distance=_target distance gamelogic

;see if bullet actually hit target, might be able to reduce value below one
?(_distance>1):goto "nohit"

player sidechat format["I just hit %1!",_target]
exit

#nohit
player sidechat format["I just missed %1 by %2 meters", _target, _dis]
exit

#notarg
player sidechat "I didn't even come close!"
exit
« Last Edit: 06 Apr 2004, 21:46:04 by Grendel »

Dutch Flander

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #4 on: 06 Apr 2004, 21:47:03 »
There is one important thing!!!!!!!!

NearestObject only(!!!!) works within 50m range!!!
That means, if you (player) want to find out a position with it, you must be within this range!!

Grendel

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #5 on: 06 Apr 2004, 21:59:40 »
Quote
NearestObject only(!!!!) works within 50m range!!!
That means, if you (player) want to find out a position with it, you must be within this range!!
Well if thats the case, then I'm screwed (my snipers might as well use pistols :-\)!

 So if you use x,y,z to determmine the location of the nearestObject search it has to occur no more than 50m from the player?!? Or does it just have to be within 50m of an object it can detect (not necessarily player).  Say it aint so, someone...

I won't get to try any of this out until I get home and the suspense will kill me.

-Grendel

I guess if I have to I can just do the whole uber-trigger thislist thing...Still use the bullet tracker script to find the impact coords, and then check the distance from every friggin unit in the array.  Seems like such a waste of precious cycles. :P
« Last Edit: 06 Apr 2004, 22:04:55 by Grendel »

Dutch Flander

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #6 on: 06 Apr 2004, 22:11:19 »
I wanted to find out the distance between 2 objects that are 100m away from me. Didn't work! "x distance (nearestobject [x, "something"]) = 0"

But when I was less than 50m away it worked!
"x distance (nearestobject [x, "something"]) = 10" -> So, the distance between x and something was really 10m!

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Need Help! NearestObject is killing me!
« Reply #7 on: 07 Apr 2004, 03:16:41 »
Didn't read everything here in detail, but here goes:

Dutch Flander, you are misinterpreting what you saw. Nearestobject can only find objects that are within 50m of the "center" object you give it. However, that has nothing to do with where the player is. That was just specific to the way you were using it.

Grendel, I think you are approaching this the wrong way. First off, when a bullet hits something, its velocity doesn't go to 0; the bullet actually disappears; it is deleted entirely. So you can't wait until it's velocity is 0, because by then the bullet isn't in the game anymore.

What you can do is have a loop that updates the bullets position in a variable, and exits once the bullet no longer exists:

Code: [Select]
#Loop
_pos = getpos _bullet (_bullet would be gotten from the nearestobject command in the EH)
? _bullet == _bullet : goto "Loop"

;//now do something with _pos

Another thing to note: you can give a POSITION to the "nearestObject" command, instead of an object and an object type. Example:

_obj = nearestObject[200, 1341, 2]

In this case, it will return the object of ANY type that is closest to the position. It can return units, triggers, bullet holes, bushes; anything. However, this wouldn't be reliable, because for example, if a bullet hits the edge of a tank, the "nearestobject" to where it hit could be a bullet hole on the ground (since the "tank" is considered to be in the middle of the model, which could be a full meter away from the impact)

  As a final note on the command, I made a function so that you can find the nearestobject out of a list of object types, which may be useful to you. Grab it here:

http://www.ofpec.com/editors/funcref.php?filter_func=43

-----------------------------

However, I think there is a better way to approach this problem. I believe that there is a part of a bullet's config that defines the 'drop' effects for the bullet hitting different surfaces, such as water, ground, people, vehicles, etc. That would be much easier to use, and much more reliable than scripting. I'd look in the official config, under the base bullet class, to find out more info.
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!

Grendel

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #8 on: 08 Apr 2004, 00:38:45 »
Thanks General Barron!!!

WOW, that helped immensely!  I havent done any config editing, but hell, you gotta learn sometime.

I would like to keep it scripted, to make it work regardless of addon or config differences...but that's just me (probably has something to do with me being less than enthusiastic about climbing out of the scripting "box" and learning a whole new syntax :P)

-Grendel

Grendel

  • Guest
Re:Need Help! NearestObject is killing me!
« Reply #9 on: 09 Apr 2004, 01:58:38 »
OK, I looked at some configs and I have no idea where to find the drop commands associated with the bullet classes.  It must be possible, as is evident in the Wargames 4.0 MOD, I'll be buggered if I can figure out how though.  

I think I've seen some addons with different drop effects, can they be stuctured within the config to use sqs files or do they have to be straight forward:  All the drop effects on the Wargame Mod ammo are exactly alike with no randomization built in. Is this because you can't set this up from a config, or were they just not inclined to make it random...

-Grendel

oh, one more question: does anyone know what the hell those "fxExploGround1" things do exactly.  On the official forums someone posted that they can be camcreated, but I can't seem to figure out what they do.  They definitely don't explode (unless you camcreate a shell at the same loc) :D.  
« Last Edit: 09 Apr 2004, 02:01:32 by Grendel »