Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Pacino_Arma3

[HELP!]How to prevent enemies attacking a no weapon player?

Recommended Posts

I want no make a mission and play in MP ,I create many playable units and they all  have different special ability. But now  I have some trouble.

1.One guy has a special ability: Enemies don't attack him if the guy has no weapon.When the guy has some weapons, Enemies will attack him. 

2.How to hide a player in MP? I Know the code : _unit hideObjectGlobal true;  I make the code in "onplayerrespawn.sqf"  but it's no use in MP!!

 

Thanks!!!

 

 

 

Share this post


Link to post
Share on other sites

1.  {_x spawn {while {true} do { waitUntil {sleep 1; !(_this hasWeapon "")}; _this setCaptive FALSE; waitUntil {sleep 1; _this hasWeapon ""}; _this setCaptive TRUE}}} forEach playableUnits; (NOT TESTED)

 

or try with:   weapons _this isEqualTo []

 

2. hiding a player when why?

Share this post


Link to post
Share on other sites
8 hours ago, pierremgi said:

1.  {_x spawn {while {true} do { waitUntil {sleep 1; !(_this hasWeapon "")}; _this setCaptive FALSE; waitUntil {sleep 1; _this hasWeapon ""}; _this setCaptive TRUE}} forEach playableUnits; (NOT TESTED)

 

or try with:   weapons _this isEqualTo []

 

2. hiding a player when why?

Thanks pierremgi! But..

1.I copy your code in "onplayerrespawn.sqf" and replace Myunit   by   _this  ,  its not use !

2.It's just one guy's special ability and I add the ability on "addaction", I want the guy be invisible when he active his ability in multiplayer game .

 

Share this post


Link to post
Share on other sites

hasWeapon is probably harder to use than currentWeapon. I modify the code even if I still can't test it.


You don't need to copy the code in onPlayerRespawn.sqf. As you are on MP scenario and setCaptive is AL EG (see BIKI), you need to run the code on server (for playableUnits not yet played, if that make sense in your scenario, i.e. they are not played, they don't have weapons and  you don't want them to be shot).

But you need also to run the code again when a player enters a slot, because the locality changes (on his PC). Then you have to focus on local playable units, usually the played slot, but also the AI units belonging to the player's group if he is their leader.
Init.sqf runs at server start but also on each JIP. So you just have to filter the locality:

In init.sqf:

{

  _x spawn {

     _this setCaptive TRUE;

     while {true} do {

      if (local _this) then {

        waitUntil {sleep 1; !(currentWeapon _this isEqualTo "")};

        _this setCaptive FALSE;

        waitUntil {sleep 1; currentWeapon _this isEqualTo ""};

        _this setCaptive TRUE

      } else {
        sleep 1;
      };
    };

  };

} forEach playableUnits;

 

Perhaps, some better code possible. I'm not on my Arma

 

2. You can create a little function for your addAction code:

your_func = {player addAction [....]};
call your_func;

and recover this addAction on respawn, adding in onPlayerRespawn.sqf:
call your_func;

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, pierremgi said:

hasWeapon is probably harder to use than currentWeapon. I modify the code even if I still can't test it.


You don't need to copy the code in onPlayerRespawn.sqf. As you are on MP scenario and setCaptive is AL EG (see BIKI), you need to run the code on server (for playableUnits not yet played, if that make sense in your scenario, i.e. they are not played, they don't have weapons and  you don't want them to be shot).

But you need also to run the code again when a player enters a slot, because the locality changes (on his PC). Then you have to focus on local playable units, usually the played slot, but also the AI units belonging to the player's group if he is their leader.
Init.sqf runs at server start but also on each JIP. So you just have to filter the locality:

In init.sqf:

{

  _x spawn {

     _this setCaptive TRUE;

     while {true} do {

      if (local _this) then {

        waitUntil {sleep 1; !(currentWeapon _this isEqualTo "")};

        _this setCaptive FALSE;

        waitUntil {sleep 1; currentWeapon _this isEqualTo ""};

        _this setCaptive TRUE

      } else {
        sleep 1;
      };
    };

  };

} forEach playableUnits; 

 

Perhaps, some better code possible. I'm not on my Arma

 

2. You can create a little function for your addAction code:

your_func = {player addAction [....]};
call your_func;

and recover this addAction on respawn, adding in onPlayerRespawn.sqf:
call your_func;

  

 

 

 

Thanks @pierremgi ! The question 1 has been solved!!!U R really my teacher!

But now,question 2, I write the  code "your_func = {player addAction [....]};"     in each  init.sqf/initServer.sqf/initplayerlocal.sqf/initserver.sqf and then "call your_func;" in onplayerrespawn.sqf.My unit can be hidden  now !

But when I play single game or local server, AI enemies can't see me and when I play MP game(use the TADST server) ,AI enemies can still see me and kill me !!

why ?

Share this post


Link to post
Share on other sites

That's because hideObjectGlobal must run on server (only) and your addAction run a local code (on player's PC who acts the action). So you need to remoteExec the code

 

in initPlayerLocal.sqf

 

my_funct = {

  Player addAction ["Activate invisibility", {
    params ["_target", "_caller", "_id"];
    if ((player actionParams _id)#0 == "Activate invisibility") then {
      [player,TRUE ] remoteExec ["hideObjectGlobal",2];
      player setUserActionText [_id,"Deactivate invisibility"];

    } else {

      [player,FALSE ] remoteExec ["hideObjectGlobal",2];
      player setUserActionText [_id,"Activate invisibility"];

    }

  }];

};

call my_funct;

 

in onPlayerRespawn.sqf:

call my_funct;

 

sorry, not tested.

   

Share this post


Link to post
Share on other sites
On 2/28/2020 at 12:29 AM, pierremgi said:

That's because hideObjectGlobal must run on server (only) and your addAction run a local code (on player's PC who acts the action). So you need to remoteExec the code

 

in initPlayerLocal.sqf

 

my_funct = {

  Player addAction ["Activate invisibility", {
    params ["_target", "_caller", "_id"];
    if ((player actionParams _id)#0 == "Activate invisibility") then {
      [player,TRUE ] remoteExec ["hideObjectGlobal",2];
      player setUserActionText [_id,"Deactivate invisibility"];

    } else {

      [player,FALSE ] remoteExec ["hideObjectGlobal",2];
      player setUserActionText [_id,"Activate invisibility"];

    }

  }];

};

call my_funct;

 

in onPlayerRespawn.sqf:

call my_funct;

 

sorry, not tested.

   

Thanks bro! You r really a good guy! 

Share this post


Link to post
Share on other sites

×