PDA

View Full Version : MP Script Considerations, Client/Server Comms etc



Sickboy
Dec 12 2006, 17:43
Opened up this topic for covering the client/server communications, how to have synchronised clients with server & thus with eachother, aswell as sharing thoughts and script snippets etc.

In continuation of this thread, last posts:
http://www.flashpoint1985.com/cgi-bin....w;st=15 (http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?act=ST;f=71;t=55339;hl=new;st=15)

I want to kick off with some testing i've done and hope to get your thoughts:

I made a server/client script for synchronising the time (especially taking JIP in account), fog and overcast with the server.
It&#39;s half in SQF and half in SQS as I was not sure on how to get the same functionality from sqs in sqf (the @<hidden> part where it waits for the condition to be come true) http://forums.bistudio.com/oldsmileys/smile_o.gif

Running on the server (execVM):<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// bc_server.sqf by Sickboy &#40;sb_at_6thSense.eu&#41;

while {true} do
{
// Always broadcast time for JIP
six_time = daytime; publicVariable &#34;six_time&#34;;

// Only broadcast fog and overcast when different from last, saves bandwidth at static weather settings
if&#40;six_fog &#33;= fog&#41; then { six_fog = fog; publicVariable &#34;six_fog&#34; };
if&#40;six_overcast &#33;= overcast&#41; then { six_fog = overcast; publicVariable &#34;six_overcast&#34; };

// Notify the clients we have broadcasted
six_bc = true; publicVariable &#34;six_bc&#34;;
sleep 20;
};[/QUOTE]
Running on the client (exec):<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; bc_client.sqs by Sickboy &#40;sb_at_6thSense.eu&#41;
;
_timeset = false

#lp
@<hidden>
six_bc = false
if &#40;overcast &#33;= six_overcast&#41; then { 5 setOvercast six_overcast };
if &#40;fog &#33;= six_fog&#41; then { 5 setFog six_fog };
if &#40;&#33;_timeset&#41; then { _six_time = &#40;six_time - daytime + 24&#41; % 24; skiptime _six_time; _timeset = true; if&#40;six_DEBUG_MISS&#41; then { hint format&#91;&#34;Timeset&#58; %1&#92;n%2&#34;,_six_time,six_time&#93; } };
goto &#34;lp&#34;

exit[/QUOTE]

The mentioned variables are initialized at the start on both server and client:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">six_DEBUG_MISS = true; six_time = 0; six_fog = 0; six_overcast = 0[/QUOTE]

This seems to work well, altough I have not yet extensively tested this, will do soon.

I left DAC generating dynamic weather on the server on and disabled it on the clients, as the dac implementation usually isn&#39;t synchronised properly over the clients.
(btw, don&#39;t ask me to share the edited DAC, as I have no permission from nor affiliation with Silola whatsoever, to release this etc. etc. so I will not, so don&#39;t ask http://forums.bistudio.com/oldsmileys/smile_o.gif)

Of coarse this little piece can be used for other variables too, and other implementations aswell..
I&#39;m wondering how this could be fully converted to SQF aswell as improving the code or even the whole implementation.

I was playing around with onPlayerConnected etc. but don&#39;t seem to get the hang of it yet http://forums.bistudio.com/oldsmileys/tounge2.gif

CrashDome
Dec 12 2006, 20:29
I cannot test, but you could try:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
private &#91;&#34;_timeset&#34;&#93;;

_timeset = false;

while {true} do
{
  switch &#40;six_bc&#41; do
  {
     case true&#58;
     {
        six_bc = false;
        if &#40;overcast &#33;= six_overcast&#41; then { 5 setOvercast six_overcast };
        if &#40;fog &#33;= six_fog&#41; then { 5 setFog six_fog };
        if &#40;&#33;_timeset&#41; then { _six_time = &#40;six_time - daytime + 24&#41; % 24; skiptime _six_time; _timeset = true; if&#40;six_DEBUG_MISS&#41; then { hint format&#91;&#34;Timeset&#58; %1&#92;n%2&#34;,_six_time,six_time&#93; } };
     };
     case default&#58;
     {
        sleep 1;
     };
  };
};[/QUOTE]

I would actually refine it further and make the weather changing a function and place into a seperate file and preprocess it, but it is all up to the coder.

Sickboy
Dec 13 2006, 08:48
I cannot test, but you could try:
...
I would actually refine it further and make the weather changing a function and place into a seperate file and preprocess it, but it is all up to the coder.
Thanks m8&#33; Will have a go with the code tonight. I will consider the weather as functions etc, but that&#39;s &#39;tweaking&#39; in my books, as I got still shitloads to do http://forums.bistudio.com/oldsmileys/smile_o.gif

Just picked this code up from the onplayerconnected howto thread:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">onplayerconnected &#34;&#91;&#93; exec &#34;&#34;PlayerConnected.sqs&#34;&#34; &#34;;[/QUOTE]execute only on the server.... (Probably change to execVM SQF)

Now that I know how the implementation works of onplayerconnected (f*cking simple lol http://forums.bistudio.com/oldsmileys/biggrin_o.gif) I can drop the time sync from the loop and place it in the onplayerconnected script, aswell as start thinking about all other scripting aspects http://forums.bistudio.com/oldsmileys/smile_o.gif

CrashDome
Dec 13 2006, 13:34
Quote[/b] ]Now that I know how the implementation works of onplayerconnected (f*cking simple lol ) I can drop the time sync from the loop and place it in the onplayerconnected script, aswell as start thinking about all other scripting aspects

Good deal&#33; http://forums.bistudio.com/oldsmileys/thumbs-up.gif Now i just gots to get me a copy....

Sickboy
Dec 13 2006, 13:54
Good deal&#33;  http://forums.bistudio.com/oldsmileys/thumbs-up.gif  Now i just gots to get me a copy....
32 euro at the czech online distribution
48 euro at the german online distribution
what are you waiting for ?

offtopic though http://forums.bistudio.com/oldsmileys/biggrin_o.gif

CrashDome
Dec 13 2006, 15:32
32 euro at the czech online distribution
48 euro at the german online distribution
what are you waiting for ?
English version. http://forums.bistudio.com/oldsmileys/smile_o.gif

Unlike most people, I am only getting one copy and prefer it to be the one I want most&#33;

Breeze
Dec 17 2006, 15:42
Can you explain what this does more so a noob understands its value..


By the way thank you for all of the work with the language packs

Sickboy
Dec 17 2006, 16:06
Can you explain what this does more so a noob understands its value..


By the way thank you for all of the work  with the language packs
NP About the lang stuff http://forums.bistudio.com/oldsmileys/smile_o.gif

The script stuff is to synchronise the server time, fog and overcast with the clients.

There is some scripting missing to make it complete though I guess, if you want I can post those scripting examples aswell

Breeze
Dec 17 2006, 16:20
I started playing flashpoint about 5 months ago because of the advertisements of this game. I wanted to wait on map making until I got this game because I felt alot might change and wanted to get in with a game from the begining.

I would love any help in learning this scripting I tried going through the tutorials and creating the examples shown but much of it does not work because of the differences in Arma and Flashpoint.

So yea please post away.

Also If you know how can you help show me how to get my spawns limited on mp maps so that a player can only have like 5 deaths before sitting balance of round.. I saw this as a parameter on flashpoint and got the parameter part to work but I cant tie the respawn to the parameter.

[BnB]The Itch
Dec 17 2006, 17:53
nice one sickboy. I actually use this method for one of my missions because i use time acceleration there (every minute realtime is 5 minutes ingame time).

This is run by a trigger so its run on the server:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
_delaytime = _this Select 0
_skiphours = _this select 1

#beginloop
~_delaytime
skipTime _skiphours
timeofday = date
publicVariable &#34;timeofday&#34;
? &#40;&#33;&#40;local&#40;Server&#41;&#41;&#41; &#58; setDate &#91;&#40;timeofday select 0&#41;, &#40;timeofday select 1&#41;, &#40;timeofday select 2&#41;, &#40;timeofday select 3&#41;, &#40;timeofday select 4&#41;&#93;
goto &#34;beginloop&#34;
[/QUOTE]

usage: [120, 0.25] exec "timeaccel.sqs"
means that every 120 real life seconds, 15 minutes ingame should be skipped

It also requires a game logic with the name Server

Sickboy
Dec 17 2006, 19:48
Will reply to the rest soon ---
Just found this one.. as a replacement for @<hidden> in sqs&#33;&#33; Saves a script loop&#33;&#33;
http://community.bistudio.com/wiki/waitUntil
altough the function is sort of a replacement for the loop, I think this will be more optimized than executing an if and a sleep every 1 second?