Jump to content
Sign in to follow this  
Icaruk

AddAction doesn't work on multiplayer.

Recommended Posts

One item named "obj".

player1 (host) init:

this addAction ["<t color=""#FFAD1F"" size='1.5' shadow='2'>" +"PUSH",{detach obj; obj setVelocity [10,0,0]}]; 

player2 init:

this addAction ["<t color=""#FFAD1F"" size='1.5' shadow='2'>" +"PUSH",{detach obj; obj setVelocity [10,0,0]}]; 

Player1 can push the obj, player2 can't.

Bug? Bad script?

Share this post


Link to post
Share on other sites

anything exec or {in here} using the addaction is only done on the person who called its computer.

So you'd need to do something like this:

Init.sqf:

Tag_fnc_doSomething = {

detach obj; obj setVelocity [10,0,0];

};

Player addAction [("<t color=""#CC2900"">" + ("Inf Spawn 1") + "</t>"), {[[],"Tag_fnc_doSomething",false,false] spawn BIS_fnc_MP; }, "radio", -1, false, true,"", ""];

Share this post


Link to post
Share on other sites

How could I run this:

null = [player] "script.sqf";

inside the addAction ?

Edited by Icaruk

Share this post


Link to post
Share on other sites

player init

this addAction ["<t color=""#FFAD1F"" size='1.5' shadow='2'>" +"PUSH","script.sqf"];  

script.sqf

detach obj;
obj setVelocity [10,0,0];

Share this post


Link to post
Share on other sites
player init

this addAction ["<t color=""#FFAD1F"" size='1.5' shadow='2'>" +"PUSH","script.sqf"];  

script.sqf

detach obj;
obj setVelocity [10,0,0];

That's equivalent to this:

null = [] "script.sqf"; 

I need this

null = [player] "script.sqf";

Share this post


Link to post
Share on other sites

Well, I do'nt see why you need to pass player when addaction already passes this:

_target = _this select 0; // Object that had the Action (also _target in the addAction command)

_caller = _this select 1; // Unit that used the Action (also _this in the addAction command)

_action = _this select 2; // ID of the Action

You can still use player in your script without having to pass it. That would give you the same result as passing it.

Addaction is local to the player.

_caller {do stuff}; is like player {do stuff}; within your script..

Share this post


Link to post
Share on other sites

You should never need to pass player, in any case. Since its always retrievable.

Share this post


Link to post
Share on other sites

First, I'd like to say I have learned so much from the community and I am grateful. Thanks guys! (I would include gals, but we all know there are maybe 3 total in the Arma community :P)

I am having similar issues using a push vehicle script I made. Getting some strange problems on a dedicated so maybe someone can help me out.

push.sqf

_object = _this select 0;
_user = _this select 1;
if (_user != vehicle _user) exitwith {hint "You can't push from inside the vehicle you idiot!"};
_dir = getDir _user;
_dx = sin(_dir)*4;
_dy = cos(_dir)*4;

_object setVelocity [_dx,_dy,0];

When I just add the addaction to the boats it works fine in editor preview but doesn't work in dedicated multiplayer. I tried to use BIS_FNC_MP but I just can't wrap my head around it yet.

Here is what I tried doing:

init.sqf

j_fnc_push =
{
   _action = _this addaction ["<t color=""#CC0000"">Push</t>", "push.sqf",[], 9, false, false, "","((vehicle _target) distance  (vehicle _this)) < 10"];
};

Then on the boats I add this to the init line:

null = [this, 'j_fnc_push', true, true] spawn BIS_fnc_MP;

When I launch the mission on a dedicated and "push" the boats I hear a sound like it's being pushed but nothing happens....

Can someone explain why doesn't this work on dedicated?

Share this post


Link to post
Share on other sites
Well, I do'nt see why you need to pass player when addaction already passes this:

_target = _this select 0; // Object that had the Action (also _target in the addAction command)

_caller = _this select 1; // Unit that used the Action (also _this in the addAction command)

_action = _this select 2; // ID of the Action

You can still use player in your script without having to pass it. That would give you the same result as passing it.

Addaction is local to the player.

_caller {do stuff}; is like player {do stuff}; within your script..

I can't do "player" stuff because of locality.

If I call with addAction a script that has _caller = _this select 0; It says that it's not defined :/

---

Edit: Oh wait... I'll try with _caller = _this select 1;

---

Edit2: Same problem that Jinker, but It just works on myself (I'm the host) and not on other players.

Edited by Icaruk

Share this post


Link to post
Share on other sites

unfortunately MP and certain elements can be a pain - you are trying to physically move an object that is not local to you - basically you need the server to do this for you, something that MP func etc would solve.

The Addaction (although attached to an object on the server) is local to you when executed - so the effects of using this on server still wont work. For example try placing a hint on that object and it will display the hint on your screen only, nowhere else.

Set velocity is executed on every computer - but i think because it is wrapped inside this addaction (local to you) it will give mixed results.

So to be safe you need to create a function using the BIS_fnc_MP that tells the server to move it - easiest way (top of my head) is execute a file for everyone using BIS_Fnc_MP, but start it with if(iserver). That way only the server will execute it. Had issues with set velocity before - sometimes it works across the network and sometimes it doesnt.

Sorry havent got time to write something that targets the Server directly - exams at mo...

hope this helps a little

Edited by Mikie boy

Share this post


Link to post
Share on other sites

Thanks Mikie, at least now I know I'm not going insane.... yet.

EDIT

Mikie you have a typo in your sig, Chapters.

Edited by Jinker

Share this post


Link to post
Share on other sites
you are trying to physically move an object that is not local to you - basically you need the server to do this for you

This is not 100% true. Server or not doesn't matter, the only thing that matters is where the object is local. By default that will be the server, but the locality of an object can change alot during a session (for example when someone enters as a driver) so you'll want to make sure the command is sent to the client where the object is currently local.

Don't worry though, it's easier than it sounds: If you put the object as the third parameter in BIS_fnc_MP, then the command will be sent only to the client where that object is local.

Share this post


Link to post
Share on other sites

Finally got it working on dedicated.

init.sqf

j_fnc_push = {
   _object = _this select 0;
   _pusher = _this select 1;

   _dir = getDir _pusher;
   _dx = sin(_dir)*4;
   _dy = cos(_dir)*4;
   _object setVelocity [_dx,_dy,0];
};

On object you want to push

this addAction ["<t color=""#CC0000"">Push</t>",'_target = _this select 0;_caller = _this select 1;[ [_target, _caller], "j_fnc_push", _target, false] spawn BIS_fnc_MP;', "", 9,false,false,"","((vehicle _target) distance  (vehicle _this)) < 10"];

Thanks for the help guys and I hope others will get some use out of this.

Share this post


Link to post
Share on other sites

Glad u got it working. Like I said not local to u. That means somewhere else other than ur computer. Appricat what u r saying tajin , but in essence u have said the same thing. And I was trying to make it easier for him to understand. Set velocity should really work on its own but god knows what that doesn't

Share this post


Link to post
Share on other sites

I understand you Mikie but it's really not the same thing and you post was missing some important information.

These tiny details can make a big difference and knowing that difference beforehand can prevent some serious headache ^^. (certain scripting commands are very strict about locality)

Share this post


Link to post
Share on other sites

Thank you Jinker, I'll put mine as soon as I have it finished!

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  

×