Jump to content
unidad2pete

AddAction multiplayer for allplayers

Recommended Posts

I Want create an object with an action to rearm, but this action only appear to player who create object.

I want everyone to use the action of the object.

First I assign action to player:

muni = player addAction ["AMMO", "muni.sqf"];

This action is for create an object with the action. Ok, works fine, on use action call muni.sqf

muni.sqf:

player removeAction muni;

amo = "B_supplyCrate_F" createVehicle (position player);

amo1 = amo addAction ["REARM","rearmar.sqf"];

hint " Next box in 10 seconds ";

sleep 10;

deletevehicle amo;

muni = player addAction ["MUNI", "muni.sqf"];

This create an object "B_supplyCrate_F", remove action to create object, wait 10 seconds, removes object and create action to recreate the object.

Object is viewed for all, but her action is only visible to object creator.

Where is the problem?

Share this post


Link to post
Share on other sites

Problem is that the action is local - local to the person who created the item or server (generally). You need to enable the addaction to be visible to all. Since the removal of setvehicleinit and mp frame work from A2 - you will have to use the new command function BIS_fnc_MP;

http://community.bistudio.com/wiki/BIS_fnc_MP

an example of how you could use it ive thrown below...

caches = createVehicle ["Box_NATO_Wps_F", getmarkerpos "spawnPoint", [], 0, "None"];

Fock_addactionMP =
{
private["_object","_screenMsg","_scriptToCall"];
_object = _this select 0;
_screenMsg = _this select 1;
_scriptToCall = _this select 2;

if(isNull _object) exitWith {};

_object addaction [_screenMsg,_scriptToCall];
};

[[caches,"call hinting","hinting.sqf"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;  

hint.sqf would be the script that gets called on activation of the addaction

Share this post


Link to post
Share on other sites

Couldn't you make the action global? Like testAction = unit addAction["whatever","whatever.sqf"]; wouldn't that work?

Share this post


Link to post
Share on other sites

No, this Way you could access it more easily in other scripts but you'd still have to use bis_fnc_mp, which BTW is very good and quite easy to use. ^^

Share this post


Link to post
Share on other sites
Problem is that the action is local - local to the person who created the item or server (generally). You need to enable the addaction to be visible to all. Since the removal of setvehicleinit and mp frame work from A2 - you will have to use the new command function BIS_fnc_MP;

http://community.bistudio.com/wiki/BIS_fnc_MP

an example of how you could use it ive thrown below...

caches = createVehicle ["Box_NATO_Wps_F", getmarkerpos "spawnPoint", [], 0, "None"];

Fock_addactionMP =
{
private["_object","_screenMsg","_scriptToCall"];
_object = _this select 0;
_screenMsg = _this select 1;
_scriptToCall = _this select 2;

if(isNull _object) exitWith {};

_object addaction [_screenMsg,_scriptToCall];
};

[[caches,"call hinting","hinting.sqf"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;  

hint.sqf would be the script that gets called on activation of the addaction

RexJoker_removeActionMP =
{
private["_object","_id"];
_object = _this select 0;
_id = _this select 1;
_object removeAction _id;
/*
* [[_object,"_id"],"RexJoker_removeActionMP",nil,false] spawn BIS_fnc_MP;
*/
};

Would this work for removing the action? If I use this inside the action script it would remove itself right?

Edited by Johnson11B2P
Thought up some code to see if it would work.

Share this post


Link to post
Share on other sites

Hi. I don't fully understand the code above.

Here is my scenario. I have a crashed helicopter ("heli1"). On the crash I added an action to the heli via a trigger ("actionid1 = heli1 addaction ["Search Helicopter", "srch = 1;"];").

Then I have another trigger which fires on "srch == 1".

When any client other than the host uses the action nothing happens. When the server host uses the action, the trigger fires.

If I got you right, I have to use:

[[heli1,"Search Helicopter","srch = 1;"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;

on the trigger which recognizes the heli crash (where "actionid1 = heli1 addaction ["Search Helicopter", "srch = 1;"];" was before). Correct?

But where do I paste the function "Fock_addactionMP" itself?

Share this post


Link to post
Share on other sites
;2422596']Hi. I don't fully understand the code above.

Here is my scenario. I have a crashed helicopter ("heli1"). On the crash I added an action to the heli via a trigger ("actionid1 = heli1 addaction ["Search Helicopter"' date= "srch = 1;"];").

Then I have another trigger which fires on "srch == 1".

When any client other than the host uses the action nothing happens. When the server host uses the action, the trigger fires.

If I got you right, I have to use:

[[heli1,"Search Helicopter","srch = 1;"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;

on the trigger which recognizes the heli crash (where "actionid1 = heli1 addaction ["Search Helicopter", "srch = 1;"];" was before). Correct?

But where do I paste the function "Fock_addactionMP" itself?

Just make sure that the function is accessed during the init.sqf. So basically you can make a file called functions.sqf and just paste the code there. Just make sure the init.sqf is passed the execVM "functions.sqf";

Share this post


Link to post
Share on other sites

So when I add the line

[[heli1,"Search Helicopter","srch = 1;"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;

to my trigger that has to add the action to the heli, I get an error "Type Script, expected nothing" when I hit OK

Share this post


Link to post
Share on other sites
;2422626']So when I add the line

[[heli1' date="Search Helicopter","srch = 1;"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;

to my trigger that has to add the action to the heli, I get an error "Type Script, expected nothing" when I hit OK

Try putting null = [[heli1,"Search Helicopter","srch = 1;"],"Fock_addactionMP",nil,false] spawn BIS_fnc_MP;

Share this post


Link to post
Share on other sites

Ah..so obvious.. :D

will try that when at home..

---------- Post added at 04:22 PM ---------- Previous post was at 03:19 PM ----------

Doesn't get me a script error now, but anyhow doesn't work.

Now in multiplayer (tested with 2 players) the heli had 2 actions on it both called "Search Heli", and still the client player was not able to activate it...

Any suggestions?

Share this post


Link to post
Share on other sites

If the client wasn't able to activate it then that means it is the script itself not the addAction.

Share this post


Link to post
Share on other sites

The script is "srch = 1;"

Maybe I don't fully understand the concept where this variable exists and where the script has to be run in multiplayer.

When I just add a trigger zone which sets srch = 1 I can walk into the zone as a client and the tigger gets fired. Why doesn't it work, when the variable is set via the addaction?

Share this post


Link to post
Share on other sites

[[heli1,"Search Helicopter",[color="#FF0000"]{srch = 1}[/color]],"Fock_addactionMP",true,true] spawn BIS_fnc_MP;

The Filename parameter of addAction is either a String or Code. If it's a String it expects to be the name of a script to run. If you want to use Code, like you are here with the srch = 1, you need to denote that it's code by using { } instead of " " around the data as shown in red above.

Share this post


Link to post
Share on other sites

Might be an old thread, but this is a much better way to handle addaction in MP.

actBatt = [[battery1,["Grab",{deleteVehicle battery1}]],"addAction",true] call BIS_fnc_MP; 

Share this post


Link to post
Share on other sites

Geez this looks complicated for a simple thing.

Can't BIS just do a addactionglobal?

 

I have a mission where players must click "Use Radio" on a radio to call a helo at the end of the mission and I cannot for the life of me get this to work in MP environment.

It works only if the host does it.

 

How I have it setup:

In a trigger when all tasks are complete:
activateRadio = [[radio1,["Use Radio","evac.sqf"]],"addAction",true] call BIS_fnc_MP;
First thing in evac.sqf:
radio1 removeAction 0;

None of this work for other players than the host.

 

 

How would you do this the simplest way?

Share this post


Link to post
Share on other sites

Folkene som later som de er eksperter har for mye stolthet til å hjelpe deg.

 

^ The experts on this forum will solve it for you proudly. Below is about as far as I got, and from the coded and pedagogically "special" guides I got from the Spocks of scripting at the time ;), the most I was able to grasp from their arcane scribblings was something about remoteExec.. If I knew how, I'd explain how to do this for you in 10 words or less.

 

init of unit

 this addaction ["Rig Car", {playSound "rigging"; "scripts\rig.sqf" remoteExec [ "BIS_fnc_execVM",2 ] }];

rig.sqf

_nul = rigcar remoteExec [ "removeAllActions", 0, true ]; //Remove action for all players

sleep 15;
riggedcar setdamage 1;

};

This is the only thing I've gotten working with this method. Global commands like setdamage will work, but not local ones.. It seems like after this much communicating back and forth, we'd have some definite guide on this by now. If I knew it, I'd share it with you, nord brother. Hail Ulfrik. :803:

Share this post


Link to post
Share on other sites

 Hail Ulfrik. :803:

 

 

Hail, son of Odin.

Your scribbles of knowledge helped me finish my mission at least!

Skål. :beeeers:

  • Like 1

Share this post


Link to post
Share on other sites

Geez this looks complicated for a simple thing.

Can't BIS just do a addactionglobal?

....

Why not just add radio trigger in editor?

Share this post


Link to post
Share on other sites

Geez this looks complicated for a simple thing.

Can't BIS just do a addactionglobal?

 

I have a mission where players must click "Use Radio" on a radio to call a helo at the end of the mission and I cannot for the life of me get this to work in MP environment.

It works only if the host does it.

 

How I have it setup:

In a trigger when all tasks are complete:
activateRadio = [[radio1,["Use Radio","evac.sqf"]],"addAction",true] call BIS_fnc_MP;
First thing in evac.sqf:
radio1 removeAction 0;

None of this work for other players than the host.

 

 

How would you do this the simplest way?

 

 

 

 

evac.sqf

radio1 removeAction activateRadio;

 

 

What is your trigger conditions? If you have "this && isServer" it will only be for the host.

Share this post


Link to post
Share on other sites

I have the same kind of issue, would love to hear someone fix this. Good luck.

Share this post


Link to post
Share on other sites

Create function in somefile.sqf:

fnc_addactionMP = {
private ["_object", "_screenMsg", "_scriptToCall", "_arguments", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_condition"];
_object = _this select 0;
_screenMsg = _this select 1;
_scriptToCall = _this select 2;
_arguments = _this select 3;
_priority = _this select 4;
_showWindow = _this select 5;
_hideOnUse = _this select 6;
_shortcut = _this select 7;
_condition = _this select 8;

if(isNull _object) exitWith {};
_object addaction [_screenMsg,_scriptToCall,_arguments,_priority,_showWindow,_hideOnUse,_shortcut,_condition];
};

on top in init.sqf:

[] call compile preprocessFileLineNumbers "somefile.sqf";

in trigger

if (isServer) then { 

[radio1, "Use Radio", "evac.sqf", nil, 6, false, true, "", "(_target distance _this) < 5"] remoteExecCall ["fnc_addactionMP", 0, true];

};

in evac.sqf:

_radio = _this select 0;
_player = _this select 1;
_actionID =_ this select 2;

radio1 removeAction _actionID;

more code...

Share this post


Link to post
Share on other sites

This is what use for dedicated servers:

_actPilot = _this addaction ["<t color=""#CC0000"">Rescue Pilot</t>", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;},[], 9,true, false, "","((vehicle _target) distance  (vehicle _this)) < 3"];

Or simply:

this addaction ["Rescue Pilot", {[[_this,"hostage.sqf"],"BIS_fnc_execVM",true] call BIS_fnc_MP;}];

If you want to see hostage.sqf....

 

_hostage = _this select 0;
_rescuer = _this select 1;
_hostage enableAI "MOVE";
_hostage switchMove "";
_hostage setCaptive true;
[_hostage] joinSilent _rescuer;
removeAllActions _hostage;

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

×