Home   Help Search Login Register  

Author Topic: Distance to grenade?  (Read 610 times)

0 Members and 1 Guest are viewing this topic.

Offline Wildebeest

  • Contributing Member
  • **
  • The time the wildebeest ruled the Earth.
Distance to grenade?
« on: 19 Oct 2005, 09:44:51 »
Hello!

Is it possible to check if a unit is close to a specific projectile type? I want something to happen to a guy when he is like 1 meters away from a grenade, which means that his soldier model will be replaced by one missing a leg when the grenade explodes close to him (actually like a heartbeat before it explodes, since the grenade will disappear).

I've got a mortar script that names the grenades "_obj" but I can't use like _obj distance _unit or something because I don't think I can have a loop in the script that checks this.

However, I would rather check if a guy is close to any grenade in the mission.

Anyway, this is what the script looks like:

Code: [Select]
;BarrageArea.sqs - script to Barrage a Triggered area
;make a tigger
;call this script on activate or deactivate:  
;[ID,Type,#shells,Xrange,Yrange,starting height,minimum time, variable time, mortar name, mortar group] exec "tripobject.sqs"
_tag    = _this select 0
_objtype = _this select 1
_amount    = _this select 2
_randomX = _this select 3
_randomY = _this select 4
_height  = _this select 5
_timemin = _this select 6
_timev    = _this select 7
_mortar    = _this select 8
_mortarteam = _this select 9
_offsetX  = _randomX / 2
_offsetY  = _randomY / 2
_height  = _this select 5

#loop
_tX   = getpos _tag select 0
_tY   = getpos _tag select 1
_tZ   = getpos _tag select 2
? leader grp1 distance _mortar < 100 : goto "loop2"
_obj = _objtype CamCreate[((_tX+Random _randomX)-_offsetX),((_tY+Random _randomY)-_offsetY),_tZ+_height]
_obj say "shell1"
? (_amount < 1 ) || leader grp1 distance _mortar > 500 || not alive _mortar || "not alive _X" count units _mortarteam == count units _mortarteam: exit
_amount = _amount - 1
~(_timemin+(random _timev))
goto "Loop"

#loop2

? leader grp1 distance _mortar > 110 : goto "loop"

~1

goto "loop2"

Thanks
Weeee...

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Distance to grenade?
« Reply #1 on: 19 Oct 2005, 12:06:05 »
Quote
I would rather check if a guy is close to any grenade in the mission
Should be possible..

In order to get any grenade/shell detected you would need a constant fast sqs loop that checks the surroundings of the unit with nearestObject.
Then, once a certain type of object is detected, the script would set a unit specific global variable true, which would then be checked in the units dammaged eventHandler..
(the global variable would be needed because otherwise you can't 'detect' what hit the guy..)

The dammaged eventHandler would execute a script that would first check if the above mentioned global variable was true or not...
If true, then the script would check whether the unit was killed and if not, where the unit was hit and how much damage was inflicted...
Then according to that info the model would be replaced with one that would have it's arm, leg or what ever, severed off...

That inflicted damage stuff would be done because you wouldn't wanna have someones arm torn off by just a tiny bit of damage :P
But I'm speaking about acting under OFP damage 'engine', if you would like to have just the distance of the grenade/shell impact as a damage factor you would need to check the distance in the looping sqs searching around the unit...

The looping nearestObject search would need to be insanely fast (most likely) which means that there will be a major performance hit; the more units the more the game performance would suffer...


On that barrage script you would again need nearestObject..
Once the _obj is created another script would be executed which would monitor the _obj untill it dies constantly recording the _obj's position..
Once the _obj dies a few nearestObject searches would be performed on and around the last known position of the _obj.
Then, if a man class object was found the man's position would be compared with the _obj's last known position and if the difference between thos two positions is short enough the man would get some of it's limbs severed...
This same method could be used on weapons/vehicles firing shells/grenades (in their fired eventHandler) to do what my first example does...
This method should not cause as much performance hit as the first example...
Only problem is that following the fired shells/grenades does not necessarily provide very exact position data... OFP sqs can not keep up with projectiles travelling very very fast like for example tank fired shells do...
Slower grenades and stuff should provide a bit more exact position data as they travel slower...

But this is all just theory, practise can be a whole different deal... :)
And of course neither of these methods work on the player unit, which is a major drag...

Oh, and all ideas hereby copyrighted ;D ;D ;D
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Wildebeest

  • Contributing Member
  • **
  • The time the wildebeest ruled the Earth.
Re:Distance to grenade?
« Reply #2 on: 19 Oct 2005, 12:29:34 »
Thanks HateR_Kint. I imagined it would have something to do with nearestObject.

However, I decided to let only a few specific guys have their limbs blown off during mortar fire alone. I named the guys who would be cut to pieces "bp", "cp", "dp", etc. and modified the script a little. If one of the guys (vietnam guys) has the radio a radio will camcreate next to the victim.

This is my solution and it works just the way I want it to: :)

Code: [Select]
;BarrageArea.sqs - script to Barrage a Triggered area
;make a tigger
;call this script on activate or deactivate:  
;[ID,Type,#shells,Xrange,Yrange,starting height,minimum time, variable time, mortar name, mortar group] exec "tripobject.sqs"
_tag    = _this select 0
_objtype = _this select 1
_amount    = _this select 2
_randomX = _this select 3
_randomY = _this select 4
_height  = _this select 5
_timemin = _this select 6
_timev    = _this select 7
_mortar    = _this select 8
_mortarteam = _this select 9
_offsetX  = _randomX / 2
_offsetY  = _randomY / 2
_height  = _this select 5

#loop1
? (_amount < 1 ) || leader grp1 distance _mortar > 500 || not alive _mortar || "alive _X" count units _mortarteam == 0: exit
_tX   = getpos _tag select 0
_tY   = getpos _tag select 1
_tZ   = getpos _tag select 2
? leader grp1 distance _mortar < 100 : goto "loop3"
_obj = _objtype CamCreate[((_tX+Random _randomX)-_offsetX),((_tY+Random _randomY)-_offsetY),_tZ+_height]
_obj say "shell1"
_amount = _amount - 1

#loop2

? (_amount < 1 ) || leader grp1 distance _mortar > 500 || not alive _mortar || "alive _X" count units _mortarteam == 0: exit
~0.2
? (_amount < 1 ) || leader grp1 distance _mortar > 500 || not alive _mortar || "alive _X" count units _mortarteam == 0: exit
?_obj distance bp < 8 && !(player == bp):goto "bp"
?_obj distance cp < 8 && !(player == cp):goto "cp"
?_obj distance dp < 8 && !(player == dp):goto "dp"
?_obj distance ep < 8 && !(player == ep):goto "ep"
?_obj distance fp < 8 && !(player == fp):goto "fp"
?not alive _obj:goto "continue1"

goto "Loop2"

#continue1

~(_timemin+(random _timev))

goto "loop1"


#loop3

? not alive _mortar || "alive _X" count units _mortarteam == 0:exit
? leader grp1 distance _mortar > 110: goto "loop1"

~1

? not alive _mortar || "alive _X" count units _mortarteam == 0:exit

goto "loop3"

#bp

~1

?bp hasweapon "sebprc25":"radiodead1" setmarkerpos [(getPos bp select 0) - 0.44, (getPos bp select 1) + 0, 0]; weaponH1 = "weaponHolder" createVehicle getMarkerPos "radiodead1"; weaponH1 addWeaponCargo ["sebprc25",1]

dead="VTE_soldier2" camcreate [getpos bp select 0,getpos bp select 1,0.2];dead setdir getdir bp

~0.0001

deletevehicle bp

~(_timemin+(random _timev))

goto "loop1"

#cp

~1

?cp hasweapon "sebprc25":"radiodead1" setmarkerpos [(getPos cp select 0) - 0.44, (getPos cp select 1) + 0, 0]; weaponH1 = "weaponHolder" createVehicle getMarkerPos "radiodead1"; weaponH1 addWeaponCargo ["sebprc25",1]

dead="VTE_soldier2" camcreate [getpos cp select 0,getpos cp select 1,0.2];dead setdir getdir cp

~0.0001

deletevehicle cp

~(_timemin+(random _timev))

goto "loop1"

#dp

~1

?dp hasweapon "sebprc25":"radiodead1" setmarkerpos [(getPos dp select 0) - 0.44, (getPos dp select 1) + 0, 0]; weaponH1 = "weaponHolder" createVehicle getMarkerPos "radiodead1"; weaponH1 addWeaponCargo ["sebprc25",1]

dead="VTE_soldier1" camcreate [getpos dp select 0,getpos dp select 1,0.2];dead setdir getdir dp

~0.0001

deletevehicle dp

~(_timemin+(random _timev))

goto "loop1"

#ep

~1

?ep hasweapon "sebprc25":"radiodead1" setmarkerpos [(getPos ep select 0) - 0.44, (getPos ep select 1) + 0, 0]; weaponH1 = "weaponHolder" createVehicle getMarkerPos "radiodead1"; weaponH1 addWeaponCargo ["sebprc25",1]

dead="VTE_soldier2" camcreate [getpos ep select 0,getpos ep select 1,0.2];dead setdir getdir ep

~0.0001

deletevehicle ep

~(_timemin+(random _timev))

goto "loop1"

#fp

~1

?fp hasweapon "sebprc25":"radiodead1" setmarkerpos [(getPos fp select 0) - 0.44, (getPos fp select 1) + 0, 0]; weaponH1 = "weaponHolder" createVehicle getMarkerPos "radiodead1"; weaponH1 addWeaponCargo ["sebprc25",1]

dead="VTE_soldier1" camcreate [getpos fp select 0,getpos fp select 1,0.2];dead setdir getdir fp

~0.0001

deletevehicle fp

~(_timemin+(random _timev))

goto "loop1"
Weeee...

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Distance to grenade?
« Reply #3 on: 19 Oct 2005, 17:28:26 »
Quote
This is my solution and it works just the way I want it to
That's good then :)

I always tend to go with the larger scale way which just complicates things ;D
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Wildebeest

  • Contributing Member
  • **
  • The time the wildebeest ruled the Earth.
Re:Distance to grenade?
« Reply #4 on: 20 Oct 2005, 09:18:19 »
I had to fix some stuff in the script but it really works now. Thanks again. Topic solved. :)
Weeee...