Jump to content
Sign in to follow this  
jshock

[CODE SNIPPET] Easy Civilian Yelling Script (using actionKeys)

Recommended Posts

Hello Scripting Community,

Below I have a simple key down display script that basically allows the player to "yell" at a civilian to get down, to stay out of harms way, this action can be accomplished by binding a key to your user custom action #20 (this can easily be changed to any of the custom keys by changing one value). You simply have to be within 5 meters of the civilian and have your cursor target (aka your reticle) pointed at the civilian to get him to cooperate and go prone on the ground.

I have "two" versions that you can easily switch out, mainly due to the unknown locality of the directSay command, or at least there aren't any indicators of its locality on the biki page. So I have provided both the standard procedure as well as a function to use with BIS_fnc_MP.


To use this, just place the following in your initPlayerLocal.sqf, or any other script that would run locally on the client:

//uncomment the below function if your using the BIS_fnc_MP line
/*JSHK_fnc_directSay = {

      _msg = (_this select 0);
      player directSay _msg;

};*/


JSHK_civYellKeyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", 
{   

_handled = false;     

    if ((_this select 1) in (actionKeys "User20")) then// change User20 to whatever key you would like to use (1-20)
   {

       if ((cursorTarget distance player < 5) &&             
           {!isNull cursorTarget} &&             
           {alive cursorTarget} &&             
           {(side cursorTarget == CIVILIAN)} &&            
           {unitPos cursorTarget != "DOWN"})         
       then         
      {             
           cursorTarget setUnitPosWeak "DOWN"; 
           //comment out the below line depending on directSay locality            
           player directSay "JSHK_CIV_DOWN_MSG";                       

          //uncomment the below line if you comment the above line           
          //[["JSHK_CIV_DOWN_MSG"], "JSHK_fnc_directSay", nil, false, true] call BIS_fnc_MP;                    
      };        
          _handled = true;    
    };    

_handled;

}];

And place the following in your description.ext file:

class CfgRadio
{    
    sounds[] = {};    
    class JSHK_CIV_DOWN_MSG    
   {        
         name = "";        
         sound[] = {};        
         title = "Get Down!";    
   };

};

Feel welcome to make your own changes or suggestions, as well as any input on the directSay command as far as its locality goes :D.

**I do ask, however, if you do use this in a public project, large or small, that I get credits/thanks/header above any of the code above, thanks for your cooperation.**

Edited by JShock
  • Like 2

Share this post


Link to post
Share on other sites
Lovely code! Share moar!

Thanks, I'm currently working on combining this with my other snippet to make a really cool effect :D, still working on a couple issues, but hopefully will have it working soon.

Share this post


Link to post
Share on other sites
This SP only?

EDIT: how would I make this usable in multiplayer I don't get it :P

Should be MP compatible, but the issue I was talking about above is that I'm unsure of the locality of the directSay command, whether it's effects global or local, so that's why I provide a means by which to broadcast the effects of the directSay across all clients. But I'm unable to test MP locality on my own, so...

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  

×