Home   Help Search Login Register  

Author Topic: Is is ammo, or what?  (Read 864 times)

0 Members and 1 Guest are viewing this topic.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Is is ammo, or what?
« on: 09 May 2005, 10:22:22 »
I've been having some problems with the nearestobject command.

I'm using it as a way to detect incoming ammunition, of ANY type, at a certain point, but I'm finding it difficult to distinguish between the ammo I'm after and the variety of other detritus that the nearestobject command hauls in. I'm refering to explosion craters, footprints, even game logics as far as I can tell.

I need some foolproof way of separating the mixture, so to speak. Whilst it's easy to detect tanks, men, planes etc, using "type" counttype [object], there appears to be no such method to finding if the object is ammo. I have ruled out several:

TypeOf: I can't use this because then I'd need every single possible type of ammo that may or may not be present.

GetPos object select 2 < 0.05: On occasion, ammo hits the ground or is travelling low enough to be confused with craters or footprints. Example: smoke shells and ECP timed grenades, bullets fired from prone position.

Velocity object: This may be what I'll have to settle for. Craters etc are stationary; projectiles generally aren't. But this still doesn't solve the problem of certain types of ammo.

Any ideas? I'm tired of my script identifying the player's footprints as a risk! ;D


Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Re:Is is ammo, or what?
« Reply #1 on: 09 May 2005, 20:09:36 »
This is some one elses scripting however I cant remember whos. So whoever it is kudos to him. But I think this is what you want:

Code: [Select]
_unit = _this select 0
_bullets = ["bulletsinglew","bulletburstw","bulletfullautow","bulletsinglee","bulletburste","bulletfullautoe","bullet7_6","bullet12_7"]

#start
@ ({_x == typeOf (nearestObject [_unit,_x])} count _bullets) > 0
? (vehicle _unit != _unit) : goto "start"

I havent messed with this scripting much and it may be buggy, but its the best I have.
I like your approach, lets see your departure.
Download the New Flashlight Script!

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Is is ammo, or what?
« Reply #2 on: 09 May 2005, 20:35:27 »
There are a lot more than the ones listed there Rujik, but they all ultimately inherit from BulletSingle.

Code: [Select]
"BulletSingle", "BulletSingleW", "BulletSingleE",
"BulletSingleG", "BulletBurst", "BulletBurstW",
"BulletBurstE", "BulletBurstG", "BulletFullAuto",
"BulletFullAutoW", "BulletFullAutoE", "BulletFullAutoG",
"BulletSilencedSingle", "BulletSilencedSingleW",
"BulletSilencedSingleE", "BulletSilencedSingleG",
"BulletSilencedBurst", "BulletSilencedBurstW",
"BulletSilencedBurstE", "BulletSilencedBurstG",
"BulletSniper", "BulletSniperW", "BulletSniperE",
"BulletSniperG", "Bullet7_6", "Bullet7_6W",
"Bullet7_6E", "Bullet7_6G", "Bullet12_7",
"Bullet12_7W", "Bullet12_7E", "Bullet12_7G",
"BISBulletCamel" "ExplosiveBullet", "Bullet30",
"Bullet30W", "Bullet30A10", "Bullet30E",
"Bullet4x23", "Bullet4x20", "Cannon30HE",
"Cannon30AP", "Cannon25HE", "CZ75",
"Skorpion", "Tokarev", "Beretta",
"HKG3", "FAL", "Glock",
"UZI", "Bizon", "G36a",
"RevolverBullet", "KozliceBall", "KozliceShell",
"HuntingRifle, "IngramBullet", "GlockS", "Steyr"

That is just the bullets and cannon shells and doesn't include any third party ammo definitions.


Planck
« Last Edit: 09 May 2005, 20:36:32 by Planck »
I know a little about a lot, and a lot about a little.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Is is ammo, or what?
« Reply #3 on: 09 May 2005, 20:42:05 »
Are you sure you can't use the "counttype" command with bullets? That's a shame... does that mean it only works with "vehicles"? (vehicles, objects, units, logics, etc).

I was going to suggest using counttype to compare to "BulletSingle", since most bullets seem to inherit from that class. Actually, on second look, all bullets inherit from the "default" class, but then there is also a "default" vehicle class.

Depending on how often you are checking this, you could just make an array of all known bullet types, and then use the "in" command to see if the caught object is one of those types. If you want this to be a 'universal' script, then that won't really be feasable, I suppose.
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 Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Is is ammo, or what?
« Reply #4 on: 10 May 2005, 00:46:32 »
Ya. Unfortunately, "ammo" counttype [bullet] does not work, nor anything else you care to try in the place of 'ammo'. IIRC, there is a special place in the cfgVehicles section of config.cpp which actually defines the types you can use with 'counttype'. I will try and find it later when I get home. Obviously, there is no equivalent in the cfgAmmo section that allows it.

Like I say, I may have to resort to checking the velocity of my nearestobject. At least I am able to remove all vehicles from my checks, leaving me with ammo, builidngs, decals etc. Out of that, only my ammo is likely to be moving.

Here's a question then: I want to have an iterator within another iterator. How do I do this? -

{ call {if ("landvehicles" counttype [_x] == 0 && {_x == 0} count (velocity _x) != 3) then {_myAmmo = _myAmmo + [_x]}; } } foreach _myObjects

- does not seem to work. Maybe '_y' then '_z' and so on? ;D

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Is is ammo, or what?
« Reply #5 on: 10 May 2005, 07:12:56 »
Quote
I want to have an iterator within another iterator. How do I do this?

AFAIK there is no way to do this with the default OFP commands. There is no way to distinguish the _x vars between two counts, foreach's, etc. Its a pain in the butt, but the way I usually get by this is by making a little function in place of one of the commands.
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!

UNN

  • Guest
Re:Is is ammo, or what?
« Reply #6 on: 10 May 2005, 19:08:59 »
Quote
There is no way to distinguish the _x vars between two counts, foreach's, etc.

You can, as the _x is always local to the {}.

Code: [Select]
_TestArray=[["1","2","3"],["A","B","C"]]

_FinalArray=[]
_SubCount=[]

{{_FinalArray=_FinalArray+[_x] ; _SubCount=_SubCount+[({_x != "0"} count [_x])]} ForEach _x} ForEach _TestArray

Hint Format ["Final %1 %2",_FinalArray,_SubCount]

If you run this, the output is:

["1","2","3","A","B","C"] [1,1,1,1,1,1]

Ok so it's not exactly the same as Fraglor's question as he wanted the count loop to work on a seperate array provided by the velocity command. But I don't see why the rules would suddenly fall apart there? But as it happens I don't think he needs to use velocity.

Quote
Here's a question then: I want to have an iterator within another iterator. How do I do this? -

{ call {if ("landvehicles" counttype [_x] == 0 && {_x == 0} count (velocity _x) != 3) then {_myAmmo = _myAmmo + [_x]}; } } foreach _myObjects

I'm assuming you want to remove any object that is stationary and not a vehicle of some sort? Written like this should be ok as speed is just the sum total of velocity:

Code: [Select]
_myAmmo=[]
{If (("landvehicles" counttype [_x]==0) And (Speed _x>0)) Then {_myAmmo = _myAmmo + [_x]}} ForEach _MyObjects

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Is is ammo, or what?
« Reply #7 on: 12 May 2005, 06:30:33 »
Cheers UNN. I thought there'd be some problem with the _x's, but as you point out, there's not.