Jump to content
Sign in to follow this  
Blakestophen

Hit Event Handler Effects

Recommended Posts

I'm developing a game of hide and seek for my community. The problem I've encountered is figuring out how to have the hiders become seekers once they are found. To do this, I have the seekers with weapons shoot the hiders, and have an event handler in the init of every hiding unit that runs a script to change faction and equipment. I have a couple of problems:

1. The hiding units have allowDamage false, since I don't want them to die when they are found and shot. This means most damage-detecting event handlers do no work.

2. I don't know how to have the script effect the hiding unit who is shot, and not the seeker who shoots.

 

This is one configuration I had that worked, except it effected the shooter and not the hider.

Hiding Unit init:

this allowDamage false; this addEventHandler ["HitPart", {this execVM "switchside.sqf"}];

switchside.sqf

this joinSilent hunters; 
// "Exported from Arsenal by Blakestophen";
// "Remove existing items"; removeAllWeapons this; removeAllItems this; removeAllAssignedItems this; removeUniform this; removeVest this; removeBackpack this; removeHeadgear this; removeGoggles this;
// "Add containers"; this forceAddUniform "CUP_U_O_RUS_Gorka_Partizan_A"; this addItemToUniform "FirstAidKit"; this addItemToUniform "ACE_Banana"; this addItemToUniform "ACE_CableTie"; this addItemToUniform "ACE_bodyBag"; this addItemToUniform "ACE_IR_Strobe_Item"; this addItemToUniform "ACE_MapTools"; this addItemToUniform "ACE_microDAGR"; this addItemToUniform "ACE_SpraypaintRed"; this addItemToUniform "ACE_Flashlight_XL50"; this addVest "CUP_V_RUS_Smersh_1"; for "_i" from 1 to 6 do {this addItemToVest "CUP_30Rnd_Sa58_M_TracerG";}; for "_i" from 1 to 3 do {this addItemToVest "CUP_8Rnd_9x18_MakarovSD_M";}; for "_i" from 1 to 2 do {this addItemToVest "ACE_HandFlare_Green";}; for "_i" from 1 to 2 do {this addItemToVest "ACE_Chemlight_HiWhite";}; this addHeadgear "CUP_H_RUS_Beret_Spetsnaz"; this addGoggles "G_Balaclava_oli";
// "Add weapons"; this addWeapon "CUP_arifle_Sa58RIS1_des"; this addPrimaryWeaponItem "CUP_acc_Flashlight_desert"; this addWeapon "CUP_hgun_PB6P9"; this addHandgunItem "CUP_muzzle_PB6P9"; this addWeapon "ACE_Vector"; 
// "Add items"; this linkItem "ItemMap"; this linkItem "ItemCompass"; this linkItem "ItemWatch"; this linkItem "tf_fadak"; this linkItem "ItemGPS";

I tested this and I successfully did what I wanted, except on the wrong unit. Now I am experimenting with MPHit and other event handlers, but this won't let me use allowDamage. Is there anyway to change this code I posted to effect the one who is shot and not the shooter?

Share this post


Link to post
Share on other sites
// in unit initialization field
this allowDamage false; this addEventHandler ["HitPart", {_this select 0 execVM "switchside.sqf"}];

// in switchside.sqf
[_this] joinSilent hunters; 

* code fixed, thanks to killzone_kid

 

The variable "this" has a meaning and value only inside object initialization field, but not in event handlers. The event handler or script receives its arguments in  "_this" variable (starts with an underscore). Arguments of your handler are listed here: Event_Handlers#HitPart. The target character is the first argument. To get it use expression "_this select 0".

 

Share this post


Link to post
Share on other sites
9 minutes ago, serena said:

_this select 0

_this select 0 is array, alright, but not the kind of array you want to pass to joinSilent 

Share this post


Link to post
Share on other sites
21 minutes ago, killzone_kid said:

_this select 0 is array, alright, but not the kind of array you want to pass to joinSilent 

Yeah, all the time I forget that the first argument of  joinSilent is an array, not a unit.

 

Blakestophen, if you want to do something with both, target and shooter units in your script:

// in unit initialization field
this allowDamage false; this addEventHandler ["HitPart", {_this execVM "switchside.sqf"}];

// in switchside.sqf
params ["_target", "_shooter"];
// from this point and until end of this script
// _target variable references target unit, and _shooter variable references shooter unit

[_target] joinSilent hunters; 
[_shooter] joinSilent hiding; 

 

Share this post


Link to post
Share on other sites

Thanks for the help, but I guess I didn't say that this is a multiplayer mission. I used this:

this allowDamage false; this addEventHandler ["HitPart", {_this select 0 execVM "switchside.sqf"}];

but I had no need to do something to the hunter so I used _target in the sqf like this:

params ["_target"];
[_target] joinSilent hunters;

// "Exported from Arsenal by Blakestophen";

// "Remove existing items";
removeAllWeapons _target;
removeAllItems _target;
removeAllAssignedItems _target;
removeUniform _target;
removeVest _target;
removeBackpack _target;
removeHeadgear _target;
removeGoggles _target;

// "Add containers";
_target forceAddUniform "CUP_U_O_RUS_Gorka_Partizan_A";
_target addItemToUniform "FirstAidKit";
_target addItemToUniform "ACE_Banana";
_target addItemToUniform "ACE_CableTie";
_target addItemToUniform "ACE_bodyBag";
_target addItemToUniform "ACE_IR_Strobe_Item";
_target addItemToUniform "ACE_MapTools";
_target addItemToUniform "ACE_microDAGR";
_target addItemToUniform "ACE_SpraypaintRed";
_target addItemToUniform "ACE_Flashlight_XL50";
_target addVest "CUP_V_RUS_Smersh_1";
for "_i" from 1 to 6 do {_target addItemToVest "CUP_30Rnd_Sa58_M_TracerG";};
for "_i" from 1 to 3 do {_target addItemToVest "CUP_8Rnd_9x18_MakarovSD_M";};
for "_i" from 1 to 2 do {_target addItemToVest "ACE_HandFlare_Green";};
for "_i" from 1 to 2 do {_target addItemToVest "ACE_Chemlight_HiWhite";};
_target addHeadgear "CUP_H_RUS_Beret_Spetsnaz";
_target addGoggles "G_Balaclava_oli";

// "Add weapons";
_target addWeapon "CUP_arifle_Sa58RIS1_des";
_target addPrimaryWeaponItem "CUP_acc_Flashlight_desert";
_target addWeapon "CUP_hgun_PB6P9";
_target addHandgunItem "CUP_muzzle_PB6P9";
_target addWeapon "ACE_Vector";

// "Add items";
_target linkItem "ItemMap";
_target linkItem "ItemCompass";
_target linkItem "ItemWatch";
_target linkItem "tf_fadak";
_target linkItem "ItemGPS";

_target removeEventHandler ["HitPart", 0];

This works perfectly when I test it in single player, but when I tested it on our group's dedicated server, the player who is shot gets all intended equipment except for weapons. He also starts with NVGs, and when he is hit he doesn't lose them. I don't get any script errors in single player or multiplayer.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×