Home   Help Search Login Register  

Author Topic: createUnit in client [SOLVED]  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
createUnit in client [SOLVED]
« on: 21 Dec 2011, 17:30:03 »
If i run a script in all client and host/server and in this script i use createUnit, is it effect on client too or just in the server?

EDIT:
I tried it yesterday and it caused a catastrophy: script run in every client but produced units in server but as many times as many client was: so houndred enemy created and ArmA started so heavy weight internet traffic so my PC (or router or something) halt the internet and all client lost the connection and when I exit ArmA I didn't get a bit internet for minutes...
I tried it twice. It was horrible.
« Last Edit: 30 Dec 2011, 22:47:01 by bardosy »
Fix bayonet!

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
Re: createUnit in client
« Reply #1 on: 30 Dec 2011, 21:04:28 »
Sorry, I didnt spot this thread earlier. You need to place gamelogic e.g. named "server" on map. And then run those createunit scripts with trigger condition:
Code: [Select]
(local server)
Or use "if (local server) then..." in scripts. I have learned that almost all other stuff are local.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: createUnit in client
« Reply #2 on: 30 Dec 2011, 22:46:40 »
Thanks for the answer!

I need those scripts run on all clients because there are sideChat and TitleText strings in it.

But I use if (isServer) then {} blocks to use createUnit. It solved the problem. I just was wondering is that necessary, because somewhere I read createVehicle is only effective in the server. But it was not true.
Fix bayonet!

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
Re: createUnit in client [SOLVED]
« Reply #3 on: 31 Dec 2011, 00:15:44 »
Remember that many conditions work only in server. E.g. unit names are only in server side. To solve many problems, I would suggest to use separate scripts for clients without any conditions in them except publicvariables if needed.

I use it like this. In init.sqf I have:
Code: [Select]
if (isnil("Var1")) then {Var1=false;};
Then during mission a script (ran in server) changes it to true for all clients with:
Code: [Select]
Var1=true;
publicvariable "Var1";

After that the variable "Var1" is true also for JIP-players and to the end of the mission unless you make the server change it back to false in the same way. This way you can trigger e.g. chatting, but disable it again so players (joined during playing) dont have all the outdated client stuff running superpositioned at mission start.

E.g. I have triggers for client scripts like this:
Code: [Select]
Condition: Var1 && !(local server)
On Act: _nul = [] execVM "ClientScript1.sqf";

The other challening part is to display tasks right for eneryone. For server and clients, you can use the previous methods, but for JIP-players you need this:

In init.sqf:
Code: [Select]
if (isnil("VarOBJLZ")) then {VarOBJLZ = 0;};
if (local server) then {} else {_nul = [] execVM "History.sqf";};

History.sqf:
Code: [Select]
waitUntil {!isNull player};
//-1 not made, 0 created, 1 finished, 2 assigned, 3 failed

if (VarOBJLZ==-1) then {};
if (VarOBJLZ==0) then {
taskLZ = player createSimpleTask [Localize "STR_5OBJLZH"];
taskLZ setSimpleTaskDescription [Localize "STR_5OBJLZ", Localize "STR_5OBJLZH", Localize "STR_5OBJLZW"];
taskLZ setSimpleTaskDestination [10081.2,10312.5,0];
player setCurrentTask taskLZ;
};
if (VarOBJLZ==1) then {
taskLZ = player createSimpleTask [Localize "STR_5OBJLZH"];
taskLZ setSimpleTaskDescription [Localize "STR_5OBJLZ", Localize "STR_5OBJLZH", Localize "STR_5OBJLZW"];
taskLZ setSimpleTaskDestination [10081.2,10312.5,0];
taskLZ settaskstate "SUCCEEDED";
};
if (VarOBJLZ==2) then {};
if (VarOBJLZ==3) then {};

So when new player joins, he gets "taskLZ"-task created. Unless server have changed VarOBJLZ to 1 (with VarOBJLZ=1;
publicvariable "VarLZ"; ), when the joined player have the task created with "succeeded"-status.

Thats the way I have been creating my COOP-missions. I am also only learning MP scripting (so my way could include rookie stuff), but these methods should work right for dedicated and normal servers.
« Last Edit: 31 Dec 2011, 00:24:38 by SaOk »

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: createUnit in client [SOLVED]
« Reply #4 on: 31 Dec 2011, 09:00:39 »
Thanks for the suggestions!

Like you, I just started to convert my campaigns' best missions to coop. And it's always harder, because it's done and full of single-player stuff and solutions.
Fix bayonet!

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
Re: createUnit in client [SOLVED]
« Reply #5 on: 31 Dec 2011, 11:55:41 »
Nope, :)

I forgot to add one more thing. Since "Player"-operator(?) is local, dedicated servers have no "Player" at all (breaking conditions with player). To fix it, I use (Repeatetly)-trigger with:
Code: [Select]
Condition: (isNull player) && (local server)
On Act: player = leader gpp;

Then in player group leader init I have:
Code: [Select]
gpp = group this;
As downsite it only works if the group leader is not disabled when choosing units in MP briefing.