Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
helling3r

Multiplayer: addAction with remote object

Recommended Posts

Hello,

i try to addAction a script to a object that is created dynamically through the mission, but i have problems with the addAction adding.

I already googled around and im aware that addAction is local only.

Situation in detail:

- Via COIN, a player can create various objects.

- One such object is a barbed wire (object tpye is not important, it also does not work with other objects)

- When the object is created, i broadcast an CBA-GlobalEvent to let all other clients know that the new Object exists. The object is a parameter of that event.

- An event listener executes a local addAction command, attaching the script in question to the newly created object.

- The event gets executed on any client correctly, but it looks like the object itself is not available as parameter. The script is syntactically correct.

Whats supposed:

The event gets executed correctly. However the action does not show up.

I suppose that the object-parameter is not working as object-objects are local too (so i cannot transport them over net as parameter)?

Question:

How can i reference the object in question on other clients when the object is created from a remote client?

Share this post


Link to post
Share on other sites

Showing your code wouldn't hurt.

For CBA EV's, you pass the variable, and you have to select it with _this just like in a script or function or PVEH's.

Init:

["TAG_ActionEV",{ (_this select 0) addAction ["test","test.sqf"]; }] call CBA_fnc_addEventHandler;

After spawning the vehicle:

["TAG_ActionEV", [_vehicle]] call CBA_fnc_globalEvent;

Can also be done by not using an array:

["TAG_ActionEV",{_this addAction ["test","test.sqf"]; }] call CBA_fnc_addEventHandler;

//later on
["TAG_ActionEV", _vehicle] call CBA_fnc_globalEvent;

Share this post


Link to post
Share on other sites

Thank you for your reply!

I know how to use CBA events, they serve me well. They cause no trouble, as stated above, the event fires fine client side. its just that _this seems not to be the object that is generated at the other client...

Code:

(Coin executes a special script every time something is build. In case of certain objects, it just raises the event in question).

func_addActionGlobal.sqf (its called by the coin on build)

// CBA EventHandler script for event "global add action"
//
// adds an action.
//

sleep 5; // wait for object to be broadcastet to the net.
_subject = _this select 0;     // The object to which the action should be added
_txt = _this select 1;         // Text entry for the action
_neededGear = _this select 2;  // gear needed for action to be present
_script = _this select 3;      // script to execute

diag_log format ["B_Event received: addActionGlobal (%1; %2)", _txt, _script];

// TODO: Only add action when needed gear-item is present in gear. (addAction condition? If clause here?)
_subject addAction [_txt, _script];

When building, my RPT confirms, the event handler script is called:

"B_Event received: addActionGlobal (Cut wire; scripts\cutRazorWire.sqf)"

---------- Post added at 22:47 ---------- Previous post was at 22:28 ----------

Just a quick reply: adding it using a globalEvent is the same.

Both solutions wont work even in singleplayer.

---------- Post added at 22:52 ---------- Previous post was at 22:47 ----------

Heureka!

This now works - why i have no clue:

(the code is contained in coin_onconstruct.sqf and called via the BIS_COIN_onconstruct handle)

// Razor Wire
if (_build_class == "Fort_RazorWire") then {
// add action on every client to remove the wire.
// TODO: Only add action when ACE_WireCutter is present in gear. (addAction condition?)

_globalCode = {
	_wireObj = _this select 0;
	waituntil {!(isNull _wireObj)};
	diag_log "[DEF-COIN] added global action to freshly built Fort_RazorWire";
	_wireObj addAction ["Cut wire", "scripts\cutRazorWire.sqf"];
};
[-2, _globalCode, [_build_obj]] call CBA_fnc_globalExecute;
};

Share this post


Link to post
Share on other sites

_txt needs to be a string for addAction, but your RPT seems to indicate it's an object? or something? Basically missing " " around the Cut Wire part.

Share this post


Link to post
Share on other sites
_txt needs to be a string for addAction, but your RPT seems to indicate it's an object? or something? Basically missing " " around the Cut Wire part.

Hi, no thats not the problem; the RPT text is coming from an format'ed string. The code used previously correctly passed the _subject variable.

Nonetheless its working now (i edited the posting above, see the code there), i used a globalExecute.

Thank you very much for your input!

Share this post


Link to post
Share on other sites

You didn't show us how you sent the event :). That's also a global execute, not an event handler. (Technically this an EV, but you're sending code instead of arguments)

Just a quick reply: adding it using a globalEvent is the same.

You don't add EV's with globalEvent, they trigger the EV :).

You didn't diag_log the subject.

Edited by cuel

Share this post


Link to post
Share on other sites
You didn't show us how you sent the event :). That's also a global execute, not an event handler. (Technically this an EV, but you're sending code instead of arguments)

You don't add EV's with globalEvent, they trigger the EV :).

You didn't diag_log the subject.

Hello,

yes, because the eventing was not the problem. The problem was the execution of the addAction noit having the desired effect. Because of that i thought it was irrelevant how the event is defined and fired.

The event handler script itself is posted above, and it is also correctly executed (meaning: event is risen successfully and also catched nd processed).

However, now its replaced by an globalExecute and now it works fine. I think there was some problem with the locality of "_this" (maybe the cba eventing stuff transforms the type of the parameters somehow).

Share this post


Link to post
Share on other sites

Well it works just fine for me.

// init.sqf
["TAG_actionEV",
{
_subject = _this select 0;     // The object to which the action should be added
_txt = _this select 1;         // Text entry for the action
_neededGear = _this select 2;  // gear needed for action to be present
_script = _this select 3;      // script to execute

diag_log format ["B_Event received: addActionGlobal (%1; %2)", _txt, _script];

// TODO: Only add action when needed gear-item is present in gear. (addAction condition? If clause here?)
_subject addAction [_txt, _script];
}] call CBA_fnc_addEventHandler;

//testev.sqf, called from radio alpha
_veh = "AH1Z" createVehicle (getPos player);
["TAG_actionEV", [_veh,"Test action",nil,"myAction.sqf"]] call CBA_fnc_globalEvent;

//myAction.sqf
hint "works";

Share this post


Link to post
Share on other sites
Sign in to follow this  

×