Jump to content
MrCrazyDude115

[Question] AddAction when inside boat

Recommended Posts

Hey everyone!

 

I'm trying to make it so that whenever a player is garrisoned in a boat, they'll get an addAction to "Go Fishing", which will then spawn a fish item in their inventory, which I already have added to the game with the classname "gen_fish".

 

Any ideas? Thanks!

Share this post


Link to post
Share on other sites

Simple: add the action to the player with the condition "_this in my_boat". Disadvantage: Performance. The condition is evaluated all the time.

 

Better: Use a GetIn EH (or GetInMan) to add the action when the player enters the boat. This would also require to remove the action with GetOut (GetOutMan) EH.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
3 hours ago, 7erra said:

Simple: add the action to the player with the condition "_this in my_boat". Disadvantage: Performance. The condition is evaluated all the time.

 

Better: Use a GetIn EH (or GetInMan) to add the action when the player enters the boat. This would also require to remove the action with GetOut (GetOutMan) EH.

 

Okay so I see how to do it, but the situation here is as follows: The vehicles (boats) are spawned mid-game through a shop system. Therefore, the vehicles don't have a name. Is it possible to replace the "_vehicle" shown here: this addEventHandler ["GetIn", { params ["_vehicle", "_role", "_unit", "_turret"]; }];

 

Replace _vehicle with a variable that basically looks at a specified array of classnames for boats, and if a player is in one of those vehicles, execute the addAction?

Share this post


Link to post
Share on other sites

yes... If you can't add the addAction straight below the spawn vehicle code.

 

Do that with getInMan EH, in initPlayerLocal.sqf   (best place)

player  addEventHandler ["GetInMan", {

  params ["_unit", "_role", "_vehicle", "_turret"]
   if (_vehicle isKindOf "ship") then { _vehicle addAction ["yourAction", {..}] };

}];

 

You need to remove the action by getOutMan, or simpler, in addAction, add at the end of code:

waitUntil {sleep 0.5; isNull objectParent _caller};

_target removeAction _id;

See addAction for more details on its own params.

 

Note 1: this addAction will stay local but any player will run the EH, so be able to addAction locally on boats. That doesn't matter as the inner code of addAction is also local.

Note 2: For better interaction in game, for example if you need to definitely remove the addAction for everyone, you can share this addAction by a remote execution,

then this action will be visible for all players satisfying the usual conditions:

  _yourAction =  ["yourAction", {..}];  [_vehicle, _yourAction] remoteExec ["addAction",0,_vehicle];

That's similar to addAction inside the init field of a vehicle.  Then, manage the addAction condition parameter. But remember how did you add this addAction... by getInMan for any player. So, mind also for avoiding the duplication of Addaction in this case (several players in the same boat).

 

 

  • Like 1
  • Thanks 1

Share this post


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

yes... If you can't add the addAction straight below the spawn vehicle code.

 

Do that with getInMan EH, in initPlayerLocal.sqf   (best place)

player  addEventHandler ["GetInMan", {

  params ["_unit", "_role", "_vehicle", "_turret"]
   if (_vehicle isKindOf "ship") then { _vehicle addAction ["yourAction", {..}] };

}];

 

You need to remove the action by getOutMan, or simpler, in addAction, add at the end of code:

waitUntil {sleep 0.5; isNull objectParent _caller};

_target removeAction _id;

See addAction for more details on its own params.

 

Note 1: this addAction will stay local but any player will run the EH, so be able to addAction locally on boats. That doesn't matter as the inner code of addAction is also local.

Note 2: For better interaction in game, for example if you need to definitely remove the addAction for everyone, you can share this addAction by a remote execution,

then this action will be visible for all players satisfying the usual conditions:

  _yourAction =  ["yourAction", {..}];  [_vehicle, _yourAction] remoteExec ["addAction",0,_vehicle];

That's similar to addAction inside the init field of a vehicle.  Then, manage the addAction condition parameter. But remember how did you add this addAction... by getInMan for any player. So, mind also for avoiding the duplication of Addaction in this case (several players in the same boat).

 

 

 

Thank you so much! I'll experiment with this now.

Share this post


Link to post
Share on other sites

Okay so here's how this is set up:

 

initPlayerLocal.sqf

player addEventHandler ["GetInMan", {

  params ["_unit", "_role", "_vehicle", "_turret"];
   if (_vehicle isKindOf "ship") then { _vehicle addAction ["Start Fishing", {"scripts\actions\fishing.sqf"}] };

}];

 

fishing.sqf

hint "Fishing...";
sleep 10;
player addItem "gen_fish";
hint "You caught a fish.";

waitUntil {sleep 0.5; isNull objectParent _caller};

_target removeAction _id;

 

It added the addAction after entering the boat, but fishing.sqf did not execute when I click the action, and if I leave the boat and get back into it, there are two actions. It appears the removeAction isn't working. Any help?

Share this post


Link to post
Share on other sites

That seems your sqf doesn't execute (and you never pass any argument on it, anyway!).

Try to place you code inside the addAction:
 

player addEventHandler ["GetInMan", {
  params ["_unit", "_role", "_vehicle", "_turret"];
  if (_vehicle isKindOf "ship") then {
    _vehicle addAction ["Start Fishing", {
      params ["_target","_caller","_id"];
      hint "Fishing...";
      sleep 10;
      _caller addItem "gen_fish";
      hint "You caught a fish.";
      waitUntil {sleep 0.5; isNull objectParent _caller};
      _target removeAction _id;
    }];
  };
}];

 

  • Like 1
  • Thanks 1

Share this post


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

That seems your sqf doesn't execute (and you never pass any argument on it, anyway!).

Try to place you code inside the addAction:
 


player addEventHandler ["GetInMan", {
  params ["_unit", "_role", "_vehicle", "_turret"];
  if (_vehicle isKindOf "ship") then {
    _vehicle addAction ["Start Fishing", {
      params ["_target","_caller","_id"];
      hint "Fishing...";
      sleep 10;
      _caller addItem "gen_fish";
      hint "You caught a fish.";
      waitUntil {sleep 0.5; isNull objectParent _caller};
      _target removeAction _id;
    }];
  };
}];

 

 

Works perfectly! Thank you so much!

Share this post


Link to post
Share on other sites
On 12/25/2019 at 6:18 PM, MrCrazyDude115 said:

_vehicle addAction ["Start Fishing", {"scripts\actions\fishing.sqf"}]

 

On 12/25/2019 at 6:18 PM, MrCrazyDude115 said:

fishing.sqf did not execute

 

The second parameter of the addAction requires either code or string. In this case you have to drop the {}-brackets. Otherwise the path of the file will get treated as a normal string and not as a path to the script.

  • Thanks 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

×