OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: RujiK on 28 Mar 2005, 22:55:50

Title: Head Shot!
Post by: RujiK on 28 Mar 2005, 22:55:50
I've recently run into a problem, I was going to make an Unreal Tornament style engine And one of the things I wished was to have it when you shoot any player if you hit him in the head it says "Head Shot!" Easy. The only problem is the dammaged eventhandler does not return who shot the person! Making it so everytime some1 gets a head shot everyone sees the message! Here is my very simple scripting:

Heres the trigger stuff
Code: [Select]
"_x addEventHandler [{dammaged},{_this exec {Dammaged.sqs}}]" foreach thislist
And Dammaged.sqs

Code: [Select]
_unit = _this select 0
_area = _this select 1
?(_area != "hlava"):exit

titletext ["Head Shot","Plain",0.1]
exit

It seems the only way to fix this would be to also add a hit event handler however I cannot figure out how to make it keep the dammaged init into another script without major bugs.

-Any help greatly appreciated.
Title: Re:Head Shot!
Post by: General Barron on 29 Mar 2005, 01:10:30
Hmm... just throwing out a few ideas here, without giving any specifics to back it up, but...

What if you set a global variable from the dammaged eventhandler, and then in the hit or killed eventhandler, you check to see if that variable is set or not? In general this could be a very complicated process, but I think it might be fairly simple to do in your case, since (a) this only applies to players and (b) it only applies to headshots, which always kill the unit. Maybe something like this:

dammaged EH:
  ? (guy who got shot) is a player && was shot in head : Head_Shots = Head_Shots + [guy who got shot]

hit / killed EH:

;make sure global var gets set first
~0.5
? (guy who got killed) IN Head_Shots : hint "headshot!"; Head_Shots = Head_Shots - [guy who got killed]

I would think that this should, although there may be some problems with locality in MP (especially if hit and dammaged EHs run on different locations).
Title: Re:Head Shot!
Post by: RujiK on 29 Mar 2005, 02:45:20
Yes, Thats the problem. I cant figure a way to transfer the offender to the dammaged script as dammaged does not give this information.

Therefore I cant figure out who "Guy who shot guy" is.
Title: Re:Head Shot!
Post by: General Barron on 29 Mar 2005, 04:14:31
I'm saying to transfer the fact that the victim was hit in the head (discovered in the "dammaged" EH) to a "hit" or "killed" EH (which can tell you WHO shot the victim). You are trying to do it the other way around, but I think it is simpler to do it this way.
Title: Re:Head Shot!
Post by: S0GSEAL on 19 Nov 2005, 03:50:19
so guys did u fixed it?:P

i would love to try it><

tnx
Title: Re:Head Shot!
Post by: THobson on 19 Nov 2005, 18:19:45
Mmm.  I am not sure it was right to move this from the Advanced board.  There is some complex stuff here.  

The Dammaged EH enables you to know where the unit was damaged - but not by who, and the Hit EH enables you to know who did the hiting - but not what part of the body was hit.  So what is needed is a set of Dammaged EHs and Hit EHs assigned to units that will run scripts that need to be smart enough to link each damaged unit script to the correct hit script, when there could be a lot of dammaged  Events and Hit Events being actioned at the same time in the middle of a battle.

Something like:
Create empty global arrays in init.sqs:
RecentlyHit = []
RecentlyHitBy = []

the script called by the Hit EH:
RecentlyHit = RecentlyHit + [_this select 0]
RecentlyHitBy = RecentlyHitBy + [_this select 1]
~1
RecentlyHit = RecentlyHit - [_this select 0]
RecentlyHitBy = RecentlyHitBy - [_this select 1]
exit


Then in the Dammaged EH script:
start with a small delay

~0.1


then find the position of _this select 0 in the array RecentlyHit and the unit that did the damaging will be in the same place in the array RecentlyHitBy


Anyway just a few random thoughts.  i am sure it will need a fair bit of work from here.

EDIT:
I have just noticed that this thread has been pretty dormant for 8 months - I presume they either solved it or did something else. Oh well.
Title: Re:Head Shot!
Post by: h- on 19 Nov 2005, 19:20:43
Well, you pretty much die in 100% certainty whenever you get shot in the head in OFP so why not just use the 'killed' eventHandler (like GB suggested already)..

It returns who did the killing so you will know who shot the head shot....
Title: Re:Head Shot!
Post by: THobson on 19 Nov 2005, 20:39:49
Well there's me getting carried away solving a complex problem, and it is just a simple one all along :o
Title: Re:Head Shot!
Post by: THobson on 20 Nov 2005, 16:05:50
On reflection.  The killed EH doesn't help because it doesn't tell you where the unit was hit.
Title: Re:Head Shot!
Post by: h- on 20 Nov 2005, 16:56:52
Ach, I was to vague in me post... :P

What GB said is valid.

You use something like a unit specific global variable (format function comes in handy) in the "dammaged" event and if it's a head shot you set that global variable true which then allows the "killed" event on the same unit to 'act'...

So (purely theoretical) "dammged" event:
Code: [Select]
? _this select 1 == "hlava" && !(alive) _this select 0: call format ["mytag_headShot_%1=true",_this select 0]
And (equally theoretical) "killed" event:
Code: [Select]
~.1
? !(call format ["mytag_headShot_%1",_this select 0]): exit
<insert headshot related stuff here>

I'm sure my format syntax is all assed up, but you get the picture ::)
And no quarantees on the rest either :P  *hands washed*
Title: Re:Head Shot!
Post by: S0GSEAL on 23 Nov 2005, 06:46:11
omg my head will blow up:) from these stuff......can any1 tell me if script is done?


btw guys..i have addon that show..the health bar..and when some1 shoots at u..it shows the only spots: head, chest, arms, legs. maybe it will help like when AI or person shoot u in the head...u can add to that addon like HEAD SHOT....dunno if im right :/
Title: Re:Head Shot!
Post by: chupchup on 25 Nov 2005, 15:50:52
A workaround for this is to get the Dammaged EH to run a dirtoobject function for each player (except the victim) where the player is object1 and the headshot target is object2. Create a global array in the init called something original like PlayerList and add all the unit names [p1,p2,etc...] In the script running off the EH:
Create a loop that calls the dirtoobj function for each selection of PlayerList and getdirs that unit. If both variables are equal (might require small error +/- 5deg), you have found the shooter.

[most of the time]

Try it out, might even work!
Title: Re:Head Shot!
Post by: S0GSEAL on 26 Nov 2005, 02:39:01
can u make example mission?:P

im only starting:)
Title: Re:Head Shot!
Post by: THobson on 26 Nov 2005, 11:36:44
Why don't you have a go with the code I put in Reply #5 I still think it is worth trying.
Title: Re:Head Shot!
Post by: S0GSEAL on 27 Nov 2005, 14:07:24
lol i try...but still dont fully get it:)

-edit-
nope didnt get it to work..coz dont understand anything..

can any1 make example mission plz :'(
Title: Re:Head Shot!
Post by: h- on 28 Nov 2005, 18:19:00
Ok, here's one with my method ;D :P ::)

Works like a charm (only briefly tested though) although it doesn't use any of that format stuff I mentioned as it's a bitch to get to work with soldier objects... for some reason..
Absolutely no idea whether this works in MP, most likely not..
Title: Re:Head Shot!
Post by: Triggerhappy on 28 Nov 2005, 23:16:08
another method, using format:

unit addevenhandler ["killed",{_this exec "killer.sqs"}]; unit addeventhandler ["dammaged",{_this exec "dammaged.sqs"}]

init.sqs
Code: [Select]
TRG_counter = 0
killed.sqs
Code: [Select]
call format ["killer%1 = (_this select 1)",TRG_counter]
;insure that the other EH gets the right counter value
~.1
TRG_counter = TRG_counter + 1
exit

dammaged.sqs
Code: [Select]
call format ["?(killer%1 != player):exit",TRG_counter]
_area = _this select 1
?(_area != "hlava"):exit

titletext ["Head Shot","Plain",0.1]
exit

untested, but it should work