Jump to content
Sign in to follow this  
mattxr

How to Make a Script Act On All Clients

Recommended Posts

How can i make a script which is server side and when activated in game it will run on everyones computer?

For Example - In game Weather Options.. from an action menu

Share this post


Link to post
Share on other sites

You do like to start right at the top of the difficulty scale, don't you? tounge2.gif

In fact there's no easy, reliable and streamlined way to do this in ArmA.

In OFP this already bordered to black art scripting and with JIP it just got up a notch in ArmA.

Maybe you can explain a bit more what exactly you're trying to do and what scope you are aiming at for the solution.

Share this post


Link to post
Share on other sites

THE ArmA workaround is to use setVehicleInit and add the command you want to execute and then use processInit, but this is not really "clean", as rom already said.

Share this post


Link to post
Share on other sites

The very reason why I think BIS should consider giving us proper network functions . Even the functionality Bn880's NS 2.0 had would be perfect.

But I doubt anyone at BIS has any time in the next couple of months to do that confused_o.gif

Same with Connected and Disconnected JIP eventhandlers.

I guess until then we will either have to use the hacks described above, wait for Bn880 to produce Network Services 3.0 or play SP.

Sigh

Share this post


Link to post
Share on other sites

You can send strings with PublicVariable now.

The rest is easy.

Share this post


Link to post
Share on other sites

@lwlooz: Check the biki for onPlayer(Dis)connected.

@salisan: No, not really. Only if you have a script running on the clients to wait for that string.

Share this post


Link to post
Share on other sites
...I guess until then we will either have to use the hacks described above...Sigh

At a certain level of scripting, pretty much everything is more or less a "hack", so better get used to it wink_o.gif

It's just about knowing what hack is best to apply to a given problem.

Share this post


Link to post
Share on other sites
@salisan: No, not really. Only if you have a script running on the clients to wait for that string.

Ofcourse, but that's trivial to arrange in a mission, which seems to be what he's trying to do here.

Without changing the mission it'll be a bit tricky to activate the server side script anyway.

Share this post


Link to post
Share on other sites
@salisan: No, not really. Only if you have a script running on the clients to wait for that string.

Ofcourse, but that's trivial to arrange in a mission, which seems to be what he's trying to do here.

Without changing the mission it'll be a bit tricky to activate the server side script anyway.

It's not really that trivial with JIP now.

For someone not used to MP scripting setVehicleInit/processInit should be easier to accomplish. Of course this all depends on what he actually wants to do.

Share this post


Link to post
Share on other sites

thanks for the input.

Overview:

1.-Theres a Tent with a Computer

2.-A Player walks up the computer and in his action menu he gets the option "Weather Control"

3.-Player Clicks the Option and Gets more Options [sunny, Overcast, Storm, Rainy, Foggy so-on]

But the Problem is when someone activates this control it only affects that player and not everyone else.

I hope that puts it in more detail for u guys and i hope my first question wasn't wrong and complicated tounge2.gif

Share this post


Link to post
Share on other sites

What you need to do is to have script that is launched on every PC at mission start. That script is fairly simple loop that check state of signal variable and if it has changed it acts according to contents of signal variable.

Note that I'm writing this on work PC, so scripts may not work fully as I cannot test them smile_o.gif. You get the general idea though.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

signalWeatherChange = -1;

// you need to have gamelogic called "server" to make this work

if (local server) {

// store initial weather to serverWeather variable

serverWeather = overcast;

}

// loop forever while mission runs

while {1 == 1} do {

// when signal variable is zero or greater, it means someone activated the action and publicVariable has been broadcast

if (signalWeatherChange >= 0) {

// fade new weather in 10 seconds

10 setOvercast signalWeatherChange;

signalWeatherChange = -1;

}

// if script is running on server, store weather setup so we can broadcast it when new player joins

if (local server) {

serverWeather = signalWeatherChange;

}

// only check it every 10 second or so

sleep 10;

}

and on your action you run following script

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

signalWeatherChange = 1.0; // or 0.0 if you want it to set sunny weather

publicVariable "signalWeatherChange";

To make newly joined players get proper weather, also have following thing on run on server

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (local server) {

// when new player joins, broadcast weather state again

onPlayerConnected { signalWeatherChange = serverWeather; publicVariable "signalWeatherChange"; }

};

Funny fact: OFP/ArmA multiplayer scripting is only time ever I've had to put stuff I learned in concurrent programming course at university into practice.

edit: fixed syntax

Share this post


Link to post
Share on other sites
...

Thats some, altough basic, kick ass stuff m8.

Altough I would not keep a ?local server in the loop, but make a seperate loop for server and client, as now it keeps checking in the loop if it's a server or a client that is running the script, dunno what kind of performance thing that is, but at the very least it's not nececairy.

Share this post


Link to post
Share on other sites
Altough I would not keep a ?local server in the loop, but make a seperate loop for server and client, as now it keeps checking in the loop if it's a server or a client that is running the script, dunno what kind of performance thing that is, but at the very least it's not nececairy.

I think performance hit is negligible, especially as SQF scripts are precompiled instead of parsing during runtime. You have to run setOvercast on server anyway as I think during rain you get more fog than on sunny weather and it may affect AI.

Share this post


Link to post
Share on other sites

Not to sound like noob who knows nothing but tht first bit u posted where do i run tht from. Script/Init/Description?

and where do i add the last one you posted. for when new players join.

Share this post


Link to post
Share on other sites
Not to sound like noob who knows nothing but tht first bit u posted where do i run tht from. Script/Init/Description?

and where do i add the last one you posted. for when new players join.

Put it into separate file, for example "weatherthingy.sqf". Then put into init.sqs line

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">spawn compile preprocessFile "weatherthingy.sqf";

As for last line, you can add it into beginning of "weatherthingy.sqf" or directly into "init.sqs". It doesn't really matter where you put those scripts as long as they get executed at mission start.

Share this post


Link to post
Share on other sites

thx.. also is this right for a loop?

Every 5 seconds the time will skip 0.5 is tht right?

Quote[/b] ]

#time

SkipTime 0.5

~5

goto time

Share this post


Link to post
Share on other sites

Yes. Though I would recommend doing everything with SQF scripting syntax as SQS scripts are being phased away.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while (1 == 1) do {

skipTime 0.5;

sleep 5;

}

Read more at http://community.bistudio.com/wiki/SQF

Share this post


Link to post
Share on other sites

Well you call a *script using spawn or execVM. As long as you use either of those, you can use the sleep command.

* Or Function based script, depending on your preference

Share this post


Link to post
Share on other sites

*nvrmind*

I see that the need for network functions has only gotten worse.

Share this post


Link to post
Share on other sites

I think that was the whole issue why BIS never tried adding JiP in OFP. It brings more pain for the scripter than it solves things.

Share this post


Link to post
Share on other sites

It doesn't really change things that much and some things are a lot easier to do in ArmA than in OFP. For those special cases, onPlayerConnected does the job just fine.

Share this post


Link to post
Share on other sites

If OnPlayerConnected/OnPlayerDisconnected at least would provide something like the player entity that someone just joined in or left,but noo...... .

Share this post


Link to post
Share on other sites
If OnPlayerConnected/OnPlayerDisconnected at least would provide something like the player entity that someone just joined in or left,but noo...... .

As Wiki says: "Variables _id and _name are set.". If onPlayerConnected is set on init.sqs, it will be run on client as well and simple check like "if (name player == _name)" will let you identify if script is being run on connecting client.

As almost all scripting functions that require object as a parameter have to be run on client where object is local, I don't think this is much of an issue.

Share this post


Link to post
Share on other sites

I get an error in the init file when using this

Quote[/b] ]spawn compile preprocessFile "weatherthingy.sqf";
saying its missing a ; but its there :/

Share this post


Link to post
Share on other sites

need your help feersum.endjinn check above post.

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  

×