Jump to content
Alpine_gremlin

Question Regarding Dedicated Server Scripting

Recommended Posts

Hey guys so I`m working on a mission that I plan to put on to a dedicated server but I have a question that I would like to ask regarding scripting for this environment.

 

I realize that the initPlayerLocal.sqf is incredibly important for this task. Let`s say I had a script that I wanted to run on each client`s computer separately. A simple message to pop up when the player approaches a vehicle. I`ll call this "script.sqf".

 

far = true;
while {far} do {
_meters = player distance car;

sleep 1;

	if (_meters < 5) then { 
                    far = false;
                    hint "You are close to the car";
                    }
};

In a dedicated server environment, I realize that the command "player" would return as nil and therefore would not work if say executed via init.sqf. What if I were to call this script in the initPlayerLocal.sqf however? Or would I have to find an alternative to "player" in this case to refer to the player`s unit?

Share this post


Link to post
Share on other sites

Player works fine, as initPlayerLocal only runs on the client. Being the first of two params IPL takes, you could also use 

_unit = this select 0;

 

  • Like 1

Share this post


Link to post
Share on other sites
44 minutes ago, Alpine_gremlin said:

So if I call a script (a totally separate sqf) from initPlayerLocal, it will still only work on that client?

That's the principle. But "work" doesn't have sense. You can say "run" instead, then the effects depend on what your script is made of (local / global effect commands)

 

Example: initPlayerLocal.sqf:

[] execVM "someScript.sqf"

 

and  someScript.sqf:

 

hint format ["hello %1, name player];   // E.L.  that's for the player's PC only

_myCar = createVehicle "B_MRPA_01_F", player getpos [10,getDir player],[],0,"NONE"];   // E.G.  the vehicle is visible/usable for all clients.

Same for:

format ["%1 in game", name player] remoteExec ["hint"] // as you remoteExec on all Pcs, the hint (name of the player who runs the code) will appear everywhere even if run locally on a JIP client.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

That's the principle. But "work" doesn't have sense. You can say "run" instead, then the effects depend on what your script is made of (local / global effect commands)

 

Example: initPlayerLocal.sqf:

[] execVM "someScript.sqf"

 

and  someScript.sqf:

 

hint format ["hello %1, name player];   // E.L.  that's for the player's PC only

_myCar = createVehicle "B_MRPA_01_F", player getpos [10,getDir player],[],0,"NONE"];   // E.G.  the vehicle is visible/usable for all clients.

Same for:

format ["%1 in game", name player] remoteExec ["hint"] // as you remoteExec on all Pcs, the hint (name of the player who runs the code) will appear everywhere even if run locally on a JIP client.

Ah I see.

 

Also what is your opinion on triggers placed in the editor? Would you say that they are a reliable way of making events happen if only evaluated by the server?

Share this post


Link to post
Share on other sites
7 minutes ago, Alpine_gremlin said:

Ah I see.

 

Also what is your opinion on triggers placed in the editor? Would you say that they are a reliable way of making events happen if only evaluated by the server?

As long as you check the "Server Only" box, yeah.

  • Like 1

Share this post


Link to post
Share on other sites

I often place triggers in editor and I don't have problems. You just have to decide if they have to run (be evaluated) on server only or everywhere.

Server only is fine for many things like spawning units while players enter in area. Consider the condition is evaluated on server and that's fine:

any player present of BLUFOR present or even your own condition like {side _x == west} count allUnits > 0  is OK

Then the code will run on server (the clients doesn't care with this trigger).

Firing a trigger on each clients is OK for some global features you don't need to broadcast Example:  a hint "Hello". All players can see it even if its a local effect. On the other hand, avoid that if you create vehicles or units. If NOT server only, you will have x spawned vehicles for x clients in game.

 

  • Like 1

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

×