Jump to content
Nicole_UK

Need help with fired event handler - PLEASE HELP ME!!!

Recommended Posts

Hey everyone 😀

 

Iv been stuck with this issue for AGES now and cant work out what to do, can someone please help me?!

 

Basically im making a mission where the AI shouts when firing their weapon (like a warcry) I have implemented the sounds fine and I can get them to shout when firing which is great but they shout EVERYTIME they fire so the sounds are kind of overlapping and constantly been played. I dont want my AI to do their warcry everytime they fire their weapon maybe like 50% of the time or something.

 

Is there a way i can set it to play every other time they fire their weapon (maybe every 3rd time? or at random?) so there is no overlapping and it sounds more like realistic shouting?

 

This is the event handler im using:

 

this addEventHandler ["Fired", { params ["_IS1"]; _IS1 say3D "akbar1"; }];

 

Im sure there is a very easy fix for this that someone will know of but i cant find an answer anywhere - if someone can help me id really appreciate it! 👍

Share this post


Link to post
Share on other sites

You can broadcast that the sound is being played, then check that in the EH:

//Exits if already playing OR has 50% chance to play
//So, > 0.1 would give it a 10% chance to play
if (NIC_WarCry_Playing || ((random 1) > 0.5)) exitWith {};

NIC_WarCry_Playing = true;

params ["_IS1"];

_IS1 say3D "akbar1";

//pause for however long it takes to play, plus maybe add some time for a delay afterwards, to prevent instantly repeating
sleep 10;

NIC_WarCry_Playing = false;

 

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, beno_83au said:

You can broadcast that the sound is being played, then check that in the EH:


//Exits if already playing OR has 50% chance to play
//So, > 0.1 would give it a 10% chance to play
if (NIC_WarCry_Playing || ((random 1) > 0.5)) exitWith {};

NIC_WarCry_Playing = true;

params ["_IS1"];

_IS1 say3D "akbar1";

//pause for however long it takes to play, plus maybe add some time for a delay afterwards, to prevent instantly repeating
sleep 10;

NIC_WarCry_Playing = false;

 

 

Thank you for your help - do i put all that code where i put my original event handler is and just replace it? 

 

sorry im just a bit new to modding so i can get confused easily lmao

Share this post


Link to post
Share on other sites

I put all that code into the units init (like i did with my original event handler) but its not working. It wont let me save it it keeps saying "error invalid number in expression".

 

Im a bit confused as to what im doing wrong? Am i supposed to put it all in the unit's init or in the description.ext?

 

😔

 

 

Share this post


Link to post
Share on other sites

I do a similar thing in some of my scripts, but I just add a timer so that the unit has to wait a few seconds before it can say something else

 

this addEventHandler ["Fired", { params ["_IS1"]; if (diag_ticktime > _IS1 getvariable["timer",0]) then {_IS1 say3D "akbar1";_IS1 setvariable["timer",diag_ticktime + random 5]}}];

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

So, I forgot to spawn the code inside the EH, which meant the sleep failed. But replied to the OP's PM so for reference, this works:

this addEventHandler ["Fired",{ 
  if (NIC_WarCry_Playing || ((random 1) > 0.5)) exitWith {}; 
  NIC_WarCry_Playing = true; 
 
  nul = _this spawn { 
    params ["_IS1"]; 
    _IS1 say3D "akbar1"; 
 
    sleep 10; 
 
    NIC_WarCry_Playing = false; 
  }; 
}];

TPW's way probably works too. Difference would be that his will do the time check per unit, so more units yelling out.

  • Like 1

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

×