Jump to content
redarmy

Are multiple hitpart/hit EH's not functional on a player?

Recommended Posts

For a few weeks now iv tried like hell to create a good system that when the player takes any damage(zombies,shots etc) that it will randomly choose a single item in the players inventory(not looking to create an array as there could be so many items) and delete it(to simulate it being damaged beyond repair)

 

Best solution i came up with was an event handler to remove a piece of gear(vest/backpack etc)

 

player addEventHandler ["HitPart",  
{  
 (_this select 0) params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ((vest _unit) != "") then  
 {  
  {  
   if (_x == "pelvis"   && 15 > random 100) then  
   {  
    removeVest _unit;  hint "Your Vest and items inside were ruined"; 
   };  
  } forEach _hitLoc;  
 };  
}];   
 
}];      

Above example works mostly ok.

 

So i tried to expand it with this:

 

player addEventHandler ["HitPart",  
{  
 (_this select 0) params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ((vest _unit) != "") then  
 {  
  {  
   if (_x == "pelvis"   && 15 > random 100) then  
   {  
    removeVest _unit;  hint "Your Vest and items inside were ruined"; 
   };  
  } forEach _hitLoc;  
 };  
}];   
 player addEventHandler ["HitPart",  
{  
 (_this select 0) params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ((backpack _unit) != "") then  
 {  
  {  
   if (_x == "pelvis"   && 6 > random 100) then  
   {  
    removeBackpack _unit;  hint "Your Backpack and items inside were ruined";
   };  
  } forEach _hitLoc;  
 };  
}];   player addEventHandler ["HitPart",   
{   
 (_this select 0) params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];   
 if ((Headgear _unit) != "") then   
 {   
  {   
   if (_x == "pelvis"   && 15 > random 100) then   
   {   
    removeHeadgear _unit;  hint "Your Headgear was ruined";  
   };   
  } forEach _hitLoc;   
 };   
}];   
 player addEventHandler ["HitPart",   
{   
 (_this select 0) params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];   
 if ((Uniform _unit) != "") then   
 {   
  {   
   if (_x == "pelvis"   && 6 > random 100) then   
   {   
    removeUniform _unit;  hint "Your Uniform was ruined"; 
   };   
  } forEach _hitLoc;   
 };   
}];      

In theory ,with a random chance of x/100,either backpack,uniform,vest or headgear is removed and all items inside gone.

 

The issue is,this 2nd syntax produces odd results. Often times,only one or two pieces of equipment gets removed,then the eventhandler never fires again.

OR

After re equipping a piece of equipment that was removed from a hit,its INSTANTLY removed again when im hit next time.

 

Im struggling to understand the concept of on hit/ hit part or even event handlers for that matter as its supposed to handle an event,multiple time and is easy of cpu so i cant understand why this isnt working correctly. I tried using hit instead of hit part,and  tried changing"pelvis" to other body parts and giving "headgear" one body part,uniform another body part and so on.. Nothings working.

 

Could someone more knowledgable break it down for me or help me script a better solution to my need?

Share this post


Link to post
Share on other sites

hi mate 🙂 tes that working but the EH required two elements by array element 🙂

 

HitPart = "[(_this select 0 select 0),(_this select 0 select 5)] execvm ""\88mm\scripts\hitpart.sqf"";";

 

that is init for a vehicle and man is considered to vehicle 😉

 

_unit = _this select 0;
_selelection = _this select 1;

 

_this select 0 select 0 = _unit

_this select 0 select 5 = selection hit 

 

Enjoy 🙂

Share this post


Link to post
Share on other sites
9 hours ago, cervantes said:

"[(_this select 0 select 0),(_this select 0 select 5)] execvm ""\88mm\scripts\hitpart.sqf"";";

 

Just a point here:

If this code is supposed to run from a "hitPart" EH, don't execVM a sqf!  execVMing means spawn compile preprocessFileLineNumbers "hitpart.sqf". So, you are compiling every time for nuts.

execVM: "If the same script is to be executed more than one time, declaring it as a Function is recommended to avoid recompiling and wasting performance with every execution."

 

Share this post


Link to post
Share on other sites

Sorry guys,im still not following.

 

Could you show me a working example edited version of my script above and maybe break that down in simpler terms?

Share this post


Link to post
Share on other sites
player addEventHandler ["HitPart",{
 private _chance = random 100;  // random 1 for test!
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
 if ("pelvis" in _hitLoc) then {  
   if ( vest _unit !="" && {15 > _chance}) then {  
    removeVest _unit;  systemChat "Your Vest and items inside were ruined";  
   };
   if ((backpack _unit) != "" && {6 > _chance}) then {  
    removeBackpack _unit;  systemChat "Your Backpack and items inside were ruined";
   };
   if ((headgear _unit) != "" && {15 > _chance}) then {  
    removeHeadgear _unit;  systemChat "Your headgear were ruined";
   };  
  };
 }];

 

Test with random 1 instead for 100 (100% chance)

Not sure pelvis has something to do with headgear... but you catch the principle: a unique EH, a check about pelvis or else part, conditions on chance + gear(s) (and systemChat as each hint overrides the previous one).

Share this post


Link to post
Share on other sites

i not see a troubls with this method.

you not see a sqf script but a compiled script do not affect performances of games when the loop exit after execution.

or when unit is killed.

 

if (_sel select 0 == "HitGlass") exitwith 
{
_spotlight animate ["hitglass", 1];
                
_ExplodeArray = ["searchlight\sounds\glass.wav"];
_Explode = selectRandom _ExplodeArray;
playsound3d [format ["%1",_Explode], _spotlight,false, getPosASL _spotlight, 7, 1, 25];
[_spotlight] execvm "searchlight\scripts\glass_shards.sqf";
};

 

EH apply in config .cpp do not compile the script same to EH add by script.

and is only loaded for this unit.

Share this post


Link to post
Share on other sites
1 minute ago, cervantes said:

i not see a troubls with this method.

 

I gave you the links explaining why it's resource consuming to compile a sqf each time you fire a code. EHs like "hitpart" can fire very often. Some of them like "handleDamage", multiple times. So, it's a bad idea execVMing sqf in this context, even applied on one unit. EHs from config.cpp (you probably mean for modded units) are not the general case and, even here, I can't see the added value of a sqf compared to a function.

Share this post


Link to post
Share on other sites
57 minutes ago, pierremgi said:

player addEventHandler ["HitPart",{
 private _chance = random 100;  // random 1 for test!
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
 if ("pelvis" in _hitLoc) then {  
   if ( vest _unit !="" && {15 > _chance}) then {  
    removeVest _unit;  systemChat "Your Vest and items inside were ruined";  
   };
   if ((backpack _unit) != "" && {6 > _chance}) then {  
    removeBackpack _unit;  systemChat "Your Backpack and items inside were ruined";
   };
   if ((headgear _unit) != "" && {15 > _chance}) then {  
    removeHeadgear _unit;  systemChat "Your headgear were ruined";
   };  
  };
 }];

 

Test with random 1 instead for 100 (100% chance)

Not sure pelvis has something to do with headgear... but you catch the principle: a unique EH, a check about pelvis or else part, conditions on chance + gear(s) (and systemChat as each hint overrides the previous one).

So if i understand it correctly, say backpack chance =2 . Vest chance = 10 .Headger chance = 12.  Then if the number chance selected is say "9", then BOTH headgear and vest are removed. In testing this it seems if the vest was lost,the headgear was also lost,and if backpack was lost,all items were lost. Am i understanding this correctly? Initially i had though it was randomly selecting a chance for each item to be removed,so even a backpack a =2% chance,could be removed while vest and headgear maybe werent.

 

so if i were to say, change body parts hitfor each item,t could produce an effect were i may loose backpack(at 2% chance) but still keep headgear that had a higher number chance?

 

i had used "pelvis" as the hit is being done by Ravage zombies,they seem to hit an "area" of player and pelvis seemed like a more reliable choice(i cant see how swinging zeds can hit your leg for example)

 

If i add more hit parts:

 if ("pelvis","body","leg r" in _hitLoc) then {  

would this be correct?

Share this post


Link to post
Share on other sites

the handle dammage i see 😉

no here the compil and damage is detected only once and damaged selections perfectly detected.

no multiple execution of script and all selections damaged can be returned with a cuttext format 😉

 

optimising script for resource is a scriptor objective 🙂

 

 

Share this post


Link to post
Share on other sites

Do what you want with randomized chance.

["pelvis","body","leg r"] findIf {_x in  _hitLoc} > -1

Edited

  • Thanks 1

Share this post


Link to post
Share on other sites
10 minutes ago, pierremgi said:

Do what you want with randomized chance.


["pelvis","body","leg r"] find {_x in  _hitLoc} > -1

 

ok let me try this,is this the correct way to assign a hit part to the item?:

 

player addEventHandler ["HitPart",{
 private _chance = random 100;  
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
 if ("pelvis" in _hitLoc) then {  
   if ( vest _unit !="" && {10 > _chance}) then {  
    removeVest _unit;  systemChat "Your Vest and items inside were ruined";  
   };
   if ("leg r" in _hitLoc) then {
   if ((backpack _unit) != "" && {10 > _chance}) then {  
    removeBackpack _unit;  systemChat "Your Backpack and items inside were ruined";
   };
   if ("body" in _hitLoc) then {
   if ((headgear _unit) != "" && {10 > _chance}) then {  
    removeHeadgear _unit;  systemChat "Your headgear were ruined";
   };  
  };
 }];

Is this the correct way to assign a different body part for a different piece of gear?

 

Im getting errors trying to use that syntax so obviously incorrect,but you can see what im trying to do right?

 

Share this post


Link to post
Share on other sites

OK after testing a few times iv finally got it to where it needs to be, testing with 3 triggers set to true:

trig1

player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( vest _unit !="" && {10 > _chance}) then {    
    removeVest _unit;  systemChat "Your Vest and items inside were ruined";    
   };  
     
  };  
 }];

trig2

player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( Headgear _unit !="" && {10 > _chance}) then {    
    removeHeadgear _unit;  systemChat "Your headgear ruined";    
   };  
     
  };  
 }];

trig 3

player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( Backpack _unit !="" && {10 > _chance}) then {    
    removeBackpack _unit;  systemChat "Your Backpack and items inside were ruined";    
   };  
     
  };  
 }];

I should have actually been more clear. "Pelvis" is the only viable body location that the player can be hit in in this scenario/situation,so each needed a pelvis hit,but not to remove all items at once,but instead with a random chance. So 3 individual triggers for testing,fired in different way at a 10% chance for contact on pelvis,and results show me that im loosing one of three pieces of gear randomly(not altogether)

 

Huge thanks for helping me crack this.

 

/

full code in init.sqf

 

player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( vest _unit !="" && {10 > _chance}) then {    
    removeVest _unit;  systemChat "Your Vest and items inside were ruined";    
   };  
     
  };  
 }];

player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( Headgear _unit !="" && {10 > _chance}) then {    
    removeHeadgear _unit;  systemChat "Your Headgear was ruined";    
   };  
     
  };  
 }];


player addEventHandler ["HitPart",{  
 private _chance = random 100;    
 _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];  
 if ("pelvis" in _hitLoc) then {    
   if ( Backpack _unit !="" && {10 > _chance}) then {    
    removeBackpack _unit;  systemChat "Your Backpack and items inside were ruined";    
   };  
     
  };  
 }];

 

Share this post


Link to post
Share on other sites

If you want multiple possibilities , like "pelvis" and "hit_pelvis" , use findIf instead of find (my bad):

["pelvis","hit_pelvis","body","leg_r"] findIf {_x in _hitLoc} > -1

 

2 hours ago, redarmy said:

I should have actually been more clear. "Pelvis" is the only viable body location that the player can be hit in in this scenario/situation,so each needed a pelvis hit,but not to remove all items at once,but instead with a random chance. So 3 individual triggers for testing,fired in different way at a 10% chance for contact on pelvis,and results show me that im loosing one of three pieces of gear randomly(not altogether)

 

Don't multiply hitpart EHs. There si no reason at all for that. Try:

 

player addEventHandler ["HitPart",{
  private _chance = random 100;
  _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
  if (["pelvis","hit_pelvis","body"] findIf {_x in _hitLoc} > -1) then {
    call {
      if (_chance < 6) exitWith {
        removeUniform _unit; systemChat "Your uniform and items inside were ruined";
      };
      if (_chance < 12 && backpack _unit != "") exitWith {
        removeBackpack _unit; systemChat "Your backpack and items inside were ruined";
      };
      if (_chance < 27 && vest _unit != "") exitWith {
        removeVest _unit; systemChat "Your vest and items inside were ruined";
      };
      if (_chance < 42 && headgear _unit != "") exitWith {
        removeHeadgear _unit; systemChat "Your headgear were ruined";
      };
    };
  };
 }];

 

This code will check for few chance for removing uniform (and all units have one), and will exit if matching;

if not, check for few chance (12 mean 6% more after missing chance for uniform), so roughly 6% chance also but player also must have a backpack...

if not... for vest:  15% (above 12 missed chance) , you can set the figures as you want...

 

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

If you want multiple possibilities , like "pelvis" and "hit_pelvis" , use findIf instead of find (my bad):


["pelvis","hit_pelvis","body","leg_r"] findIf {_x in _hitLoc} > -1

 

 

Don't multiply hitpart EHs. There si no reason at all for that. Try:

 


player addEventHandler ["HitPart",{
  private _chance = random 100;
  _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
  if (["pelvis","hit_pelvis","body"] findIf {_x in _hitLoc} > -1) then {
    call {
      if (_chance < 6) exitWith {
        removeUniform _unit; systemChat "Your uniform and items inside were ruined";
      };
      if (_chance < 12 && backpack _unit != "") exitWith {
        removeBackpack _unit; systemChat "Your backpack and items inside were ruined";
      };
      if (_chance < 27 && vest _unit != "") exitWith {
        removeVest _unit; systemChat "Your vest and items inside were ruined";
      };
      if (_chance < 42 && headgear _unit != "") exitWith {
        removeHeadgear _unit; systemChat "Your headgear were ruined";
      };
    };
  };
 }];

 

This code will check for few chance for removing uniform (and all units have one), and will exit if matching;

if not, check for few chance (12 mean 6% more after missing chance for uniform), so roughly 6% chance also but player also must have a backpack...

if not... for vest:  15% (above 12 missed chance) , you can set the figures as you want...

 

 

 

I see and can understand what you mean. It exits the code under conditions and starts again. Pretty neat way to do this. I took what you have above and tweaked a few things and tested. Everythings great with it:

 

player addEventHandler ["HitPart",{
  private _chance = random 100;
  _this #0 params ["_unit", "_shooter", "_bullet", "_pos", "_vel", "_hitLoc"];
  if (["pelvis","hit_pelvis","body"] findIf {_x in _hitLoc} > -1) then {
    call {
      if (_chance < 2) exitWith {
        removeUniform _unit; ["GEAR RUINED", "<t color='#FF0000'>Your uniform and items inside were ruined.</t>"] spawn BIS_fnc_showSubtitle;
      };
      if (_chance < 8 && backpack _unit != "") exitWith {
        removeBackpack _unit; ["GEAR RUINED", "<t color='#FF0000'>Your backpack and items inside were ruined.</t>"] spawn BIS_fnc_showSubtitle;
      };
      if (_chance < 10 && vest _unit != "") exitWith {
        removeVest _unit; ["GEAR RUINED", "<t color='#FF0000'>Your vest and items inside were ruined.</t>"] spawn BIS_fnc_showSubtitle;
      };
      if (_chance < 12 && headgear _unit != "") exitWith {
        removeHeadgear _unit; ["GEAR RUINED", "<t color='#FF0000'>Your headgear was ruined.</t>"] spawn BIS_fnc_showSubtitle;
      };
    };
  };
 }];

 

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

×