OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started 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
"_x addEventHandler [{dammaged},{_this exec {Dammaged.sqs}}]" foreach thislist
And Dammaged.sqs
_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.
-
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).
-
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.
-
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.
-
so guys did u fixed it?:P
i would love to try it><
tnx
-
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.
-
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....
-
Well there's me getting carried away solving a complex problem, and it is just a simple one all along :o
-
On reflection. The killed EH doesn't help because it doesn't tell you where the unit was hit.
-
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:
? _this select 1 == "hlava" && !(alive) _this select 0: call format ["mytag_headShot_%1=true",_this select 0]
And (equally theoretical) "killed" event:
~.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*
-
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 :/
-
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!
-
can u make example mission?:P
im only starting:)
-
Why don't you have a go with the code I put in Reply #5 I still think it is worth trying.
-
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 :'(
-
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..
-
another method, using format:
unit addevenhandler ["killed",{_this exec "killer.sqs"}]; unit addeventhandler ["dammaged",{_this exec "dammaged.sqs"}]
init.sqs
TRG_counter = 0
killed.sqs
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
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