Home   Help Search Login Register  

Author Topic: Some questions about scripts execution in MP  (Read 4184 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Some questions about scripts execution in MP
« on: 22 Apr 2007, 12:34:25 »
- If the server executes anything with execVM, is it in fact executed in every client? For example: ?local server:[]execVM"whatever.sqf".

- If the server executes anything with exec, is it executed in every client? For example: ?local server:[]exec"whatever.sqs"

- If a client activates an action (action menu), is its assigned script executed only in that client's machine? Is there any difference between activating actions of units local to client's machine and activating actions of units local to other clients or the server?

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Some questions about scripts execution in MP
« Reply #1 on: 22 Apr 2007, 15:25:46 »
answer to all questions is "Locally" run where they are called upon

typically when a player calls upon its AI to run an action command (eg via the units action menu), then that unit would be local to the player and therefore when an AI is called upon by the group leader player then the addaction script is run locally

There may be a few oddball instances where the players ai could be none local to him, eg when in another players vehicle "PERHAPS", but am not sure if this was the case whether you would be able to tap into ther ai's action menu then anyway
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: Some questions about scripts execution in MP
« Reply #2 on: 23 Apr 2007, 22:03:19 »
As for your first 2 questions, Mandoble, the example you provided ensure that both sqf and sqs scripts are run only on the server. Ofc, provided you put a LOGIC named "server" on the map ;)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #3 on: 24 Apr 2007, 00:11:19 »
That is the weird point, as these scripts are being executed in the first client to join and the dedicated server. But, placing a ?!local server:exit above solves the problem  :dunno:

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Some questions about scripts execution in MP
« Reply #4 on: 24 Apr 2007, 02:40:37 »
That is strange.... AFAIK it does not matter which unit/vehicle an action is attached to. The action only runs on the machine of the player who activated the action. As Terox said above, a script is only run on the machine on which it is executed.

To be more concise we really need to see the script in question and know exactly how it is being called i.e. init/action/trigger etc
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #5 on: 24 Apr 2007, 09:31:54 »
Init.sqs
Code: [Select]
...
...
?(local server):[["RHIB","PBX"]]execVM"mission\spawnship.sqf"
?(local server):[["AV8B","AH1W","Mi17","Su34"]]execVM"mission\spawnplane.sqf"
?(local server):[["Truck5tMG","T72","Ural","HMMWVTOW","Stryker_TOW","UAZ","BRDM2","Landrover","Bus_city","M1030","M1Abrams","M113","BMP2","ZSU"]]execVM"mission\spawntank.sqf"
...
...


spawntank.sqf
Code: [Select]
_types = _this select 0;
_i = 0;
_count = count _types;
while {true} do
{
   cutText["Spawning a new tank", "PLAIN DOWN"];
   _i = floor(random (_count - 0.01));
   westgrpland = createGroup west;
   _wp1 = westgrpland addWaypoint [getPos landmove, 0];
   _wp2 = westgrpland addWaypoint [getPos landcycle, 0];
   _wp3 = westgrpland addWaypoint [getPos landmove, 0];
   [westgrpland, 1] setWaypointType "MOVE";
   [westgrpland, 2] setWaypointType "MOVE";
   [westgrpland, 3] setWaypointType "CYCLE";

   tank1 = createVehicle [_types select _i, [0,0,0], ["spawnland1", "spawnland2", "spawnland3"], 0, "NONE"];
   "SoldierWCrew" createUnit [[0,0,30], westgrpland,"this setBehaviour ""AWARE"";tankman1 = this;this removeWeapon ""NVGoggles"";this setDir 0;this    MoveInDriver tank1", 0.6, "private"];
   tank1 setDir 0;
   publicVariable "tank1";
   Sleep 2;

   waitUntil {damage tank1 > 0.9};
   [tank1, westgrpland] spawn {Sleep(10);{deleteVehicle _x} forEach crew (_this select 0);deleteVehicle (_this select 0);deleteGroup (_this select 1);};
   Sleep(1);
};

1 tank in SP, 2 in MP with a dedicated server and a client.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Some questions about scripts execution in MP
« Reply #6 on: 24 Apr 2007, 16:43:19 »
Does the cutText appear on the client?
urp!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #7 on: 24 Apr 2007, 17:34:58 »
Yep, it does  :dunno: Probably it is some kind of stupid problem, else it has not sense at all  :dunno:

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Some questions about scripts execution in MP
« Reply #8 on: 24 Apr 2007, 17:41:50 »
Well, I know this does not really answer the question, but add a server check line(not local server then exit) to the top of the script. Might want to double check your server gamelogic....

Very strange....  :blink:

urp!

Offline WhisperOFP

  • Members
  • *
  • I'm a llama!
Re: Some questions about scripts execution in MP
« Reply #9 on: 24 Apr 2007, 18:04:30 »
The 1st thing I find strange is that it even works  :P : my SQF engine always refused to launch script through execVM if there was no assignation (tmp = blabla execVM "blibli.sqf", the "tmp =" part was required)
2nd, do you have actions that should also be done on client AFTER your vehicle-creation scripts launch in init.sqs? If not, then you could add a
Code: [Select]
?!(local server):exit before launching all the vehicle creation scripts, without checking each time that the server is local.

Another note, I tend lately to use init.sqf instead of init.sqs, don't know if it's OK or not, but this way my syntax is the same everywhere.

And, last and stupid re-question : are you sure the "server" LOGIC exists in your mission?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #10 on: 24 Apr 2007, 18:07:15 »
Indeed I did that in init.sqs ?!local server:exit

And that solved the problem.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Some questions about scripts execution in MP
« Reply #11 on: 24 Apr 2007, 18:12:06 »
Quote
my SQF engine always refused to launch script through execVM if there was no assignation (tmp = blabla execVM "blibli.sqf", the "tmp =" part was required)
It works without the global variable in scripts..

I'm guessing it has something to do with differences between the scripting scope and the global scope..  :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re: Some questions about scripts execution in MP
« Reply #12 on: 28 Apr 2007, 01:08:31 »
The following answers to the OP's original questions have essentially already been given in some posts above. I'm just going to nail them to the wall so there won't be a need for any more confusion on these matters:

- If the server executes anything with execVM, is it in fact executed in every client?
No. The effect of exec and execVM, which is the execution of a script, is local to the machine (actually "ArmA process") where the command is issued.

Quote
- If the server executes anything with exec, is it executed in every client?
No. See above.

Quote
- If a client activates an action (action menu), is its assigned script executed only in that client's machine?
Yes.

Quote
Is there any difference between activating actions of units local to client's machine and activating actions of units local to other clients or the server?
No difference except that the locality of the object to which the action is tied is different (trivially obvious, I'm just stating it so as to leave no ambiguity). Even if an object is remote to the unit that activates the action, the actual action script is still only executed on the machine where the actor ("user of the action") resides. It is assumed that the object that has the action has gotten this by use of the addAction command issued on the actor's machine beforehand. (That, too, should be obvious, since the actor would not be able to use that particular action otherwise.)

Remember:
  • The effect of addAction, which is to add an action to an object, is local to the machine (ArmA process) where it's issued.
  • The effect of using an action, which is the execution of a script, is local to the actor's machine (ArmA process).
« Last Edit: 28 Apr 2007, 01:19:53 by Killswitch »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #13 on: 28 Apr 2007, 09:35:57 »
Thanks guys, good info here  :good:

Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
Re: Some questions about scripts execution in MP
« Reply #14 on: 10 Feb 2008, 06:12:04 »
I'm having problems getting some scripts which are activated via addActions attached to editor placed objects to run on all clients...for example i have a computer (editor placed object) on the map to which i have attached an addAction. The addAction calls a script which simulates the Player taking the hard drive using a playMove as well as some text. However the text does not appear on all machines connected to the server....

So if i understand the previous posts...i need to add this line of code to the start of each script?
Code: [Select]
?!(Local Server):exityes or no?

Or do i need to add a GameLogic named Server to the map?

A similar problem occurs when i try to run a cut scene via an addAction, the cut scene is only seen by the client who activated the action?
« Last Edit: 10 Feb 2008, 06:15:03 by Carroll »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #15 on: 10 Feb 2008, 11:18:11 »
Yep, the code executed via action menus is always executed locally (for the player or unit that activated the action).

On the other side, trigger's code is executed everywhere.

For example:
the code of your action would have only: action_activator = _this select 1;
the condition of a new trigger: !isNull action_activator
the code of your trigger: res = [action_activator]execVM"computer.sqf"

computer.sqf will be executed everywhere once action_activator has the unit that activated the action, and inside computer.sqf you will to check locallity of the passed unit to make sure the switchmove is executed only when local (_this select 0), as switchMove and playMove works only when passed unit is local.


Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
Re: Some questions about scripts execution in MP
« Reply #16 on: 10 Feb 2008, 14:45:05 »
Thanks Mandoble for the insight...however i am not entirely sure what i need to do  ???
I am guessing that in laymans terms i do not need to have a GameLogic named Server or have !?(Local Server):exit at the beginning of my script?

Please forgive my ignorance but i literaly have no idea how to interpret your answer, sorry but i'm realitively slow at picking things up

From what i can gather i need to check in my script when the Action has been activated with a trigger?
« Last Edit: 10 Feb 2008, 14:48:20 by Carroll »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Some questions about scripts execution in MP
« Reply #17 on: 10 Feb 2008, 17:16:04 »
The action script attached to your computer:
Code: [Select]
// computer_action.sqf
(_this select 0) removeAction (_this select 2);
action_activator = _this select 1;

Then you add a trigger to your map, condition:
Code: [Select]
!isNull action_activator
OnAct.:
Code: [Select]
res = [action_activator]execVM"gettingcomputerhd.sqf"


Code: [Select]
// gettingcomputerhd.sqf
// _unit is who activated the action
_unit = _this select 0;
// whatever you already have there
// In some cases use
if (local _unit) then
{
   switchMove whatever;
};

Offline Carroll

  • Members
  • *
  • Mission Designer (MP-"well tryin to capiche"
Re: Some questions about scripts execution in MP
« Reply #18 on: 10 Feb 2008, 18:17:03 »
Oh yes now i see it, thanks for taking the time to clear that up for me..my head gets easily confused when i see pieces of code i have never used before...but it makes sense to me now, cheers mate  :good: