Jump to content
Sign in to follow this  
jw custom

Still confused about isServer!

Recommended Posts

I'm really confused about when to use and not use isServer/!isServer when hosting mission locally and on dedi server.

If i have a script that are executed by a trigger and it spawns a tank.

If i start script with:

if (!isServer) exitWith {};

What will happen on a dedicated server and what will happen on a locally hosted game...

The dedicated server:

Will the script only get executed on the dedicated server and spawn 1 tank and will it be visible to all connected players?

If i remove the !isServer line will every connected players execute script and spawn a tank each?

Locally hosted game:

Is it only me as host that will execute script and spawn 1 tank and is it visible to all players connected?

If i die before script is executed by trigger will my computer(the host/server) still run script and spawn that tank?

Another similar question:

Is there a difference in adding ammo/weapons to a crate and spawning units... I'm using a ammo crate filler script, should it get executed on all players connected computers or just on host/server?

I have made a mission where theres a ammo crate which execute a crate filler script from its init line, the script start with:

if (!isServer) exitWith {};

On locally hosted game the crate is filled but on dedicated servers it's empty, now i'm really confused because i thought that when executing ammo/weapons crate filler script on server each

client would be updated with that new info. I also thought that if i executed script on each client the client would pass info on to server which would pass it on to the other clients and the

crate would end up with tons of ammo/weapons :confused:

I really hope someone can make me understand this so i can start making some MP missions :cool:

Edited by JW Custom

Share this post


Link to post
Share on other sites

if (isServer) then {
//..local hosted server
//..single player
//..dedicated server
};
if (!isServer) then {
//..client on local hosted server (not the host itself!!!)
//..client on dedicated server
};
if (isDedicated) then {
//..dedicated server only
};
if (!isDedicated) then {
//..local hosted server
//..singleplayer
//..all clients
};
if (!isDedicated and isServer) then {
//..local hosted server
//..singleplayer
};
if (!isDedicated and isServer and not isMultiplayer) then {
//..local hosted server
};

Bout all I could think of, hope that helps.

If you run the code ten times, ten tanks will be made. If you run it on 10 computers, that is equivalent to ten times == ten tanks. Unless of course its a local command, in which it may be 10 times,but only effect on the local machine (ie switchmove).

I found this VERY VERY helpful.

http://community.bistudio.com/wiki/6thSense.eu:EG

Particularly this for you:

http://community.bistudio.com/wiki/6thSense.eu:EG#Determining_if_machine_is_Ingame_Server.2C_Ded_Server.2C_Player_or_JIP_Player

Execute the ammo on all computers, or in the INIT line, if it is local to server, you won't be able to get ammo, if its just one player, only one player can get the ammo. This can be useful if used properly.

Edited by Rommel

Share this post


Link to post
Share on other sites

So if i use this on a dedicated server...

if (isDedicated) then {

myCrate addWeaponCargo ["G36a", 100];

};

...the line in bold will only get executed on the dedicated server correct?

Will the 100 G36'er be visible/accessable by all connected players?

Share this post


Link to post
Share on other sites

...the line in bold will only get executed on the dedicated server correct?

roger, yes, correct

Will the 100 G36'er be visible/accessable by all connected players?

no, none, nay

Share this post


Link to post
Share on other sites
roger, yes, correct

no, none, nay

So far so good :p

But what about this:

if (isDedicated) then {

HQ1 = "BMP2_HQ_INS_unfolded" createVehicle (getPos HQ_Pos);

};

Will the BMP2 HQ be visible for all connected players( i have the feeling you will say no :p ).

But if i execute the spawn line on each computer the there will be a BMP2 HQ on all players screens on different locations as HQ_Pos is a random position!

What i need is to spawn ONLY 1 which is visible to all connected players and on same location.

Thanks a lot for taking your time with me :D

Share this post


Link to post
Share on other sites
If you spawn a vehicle on the server it will be seen by all. No problems :).

Ahh that clear up things a bit. I thought adding ammo or spawning units on server were the same.

Thank you :)

Here's how i thought it all worked.

You add 10 magazines to a crate from dedi server/local host, the server/host then spread the info to all clients. If a client takes a magazine it's reported to server host which will update all clients with new status.

*EDIT*

Now i'm getting confused again lol :p

//ammo.sqf

clearMagazineCargo _this;
clearWeaponCargo _this;
myCrate addWeaponCargo ["G36a", 100];

If i as player on a server goes to a crate and drop my NV Googles they will be accessable for all other clients, so if the above ammo script is called from the crates init line on all clients wouldn't that give the crate 500 G36's if 5 players are connected?

Where and how should i execute the script to add a total of 200 G36's which should be accessable to all players even if 5 player are connected?

Is there any difference in how it should be done if game should be hosted on local or dedicated server?

Edited by JW Custom

Share this post


Link to post
Share on other sites

Check the Biki entries for both commands :

addMagazineCargo

createVehicle

You'll notice on many Biki entries these 2 icons :

effects_local.gif on addMagazineCargo

effects_global.gif on createVehicle

These icons indicated the scope of the command effect : local or global.

Local effect (the first icon) are not transferred over the network and stay local to PC where the command is used. In our case, only the machine where addMagazineCargo is launched will have the magazines added to the cargo. No other client will see them

Global effect (the second icon) means commands results are transfered over the network and visible to everyone.

If you want effects seen everywhere for a command with local effects only, launch it everywhere.

If you want effects seen everywhere for a command with global effects, launch it on server only to avoid mutiple results of the same command launch on every machine

If you want effects seen only on 1 machine for a command with local effects only, just launch the command on said machine.

If you want effects seen only on 1 machine for a command with global effects, well, you can't :)

Share this post


Link to post
Share on other sites
Check the Biki entries for both commands :

addMagazineCargo

createVehicle

You'll notice on many Biki entries these 2 icons :

effects_local.gif on addMagazineCargo

effects_global.gif on createVehicle

These icons indicated the scope of the command effect : local or global.

Local effect (the first icon) are not transferred over the network and stay local to PC where the command is used. In our case, only the machine where addMagazineCargo is launched will have the magazines added to the cargo. No other client will see them

Global effect (the second icon) means commands results are transfered over the network and visible to everyone.

If you want effects seen everywhere for a command with local effects only, launch it everywhere.

If you want effects seen everywhere for a command with global effects, launch it on server only to avoid mutiple results of the same command launch on every machine

If you want effects seen only on 1 machine for a command with local effects only, just launch the command on said machine.

If you want effects seen only on 1 machine for a command with global effects, well, you can't :)

Hey thanks that was very informative :cool:

A question regarding the addMagazineCargo command. So i run the script with ammo/weapons on each client so they all see lets say 10 grenades in the crate, if a player takes a handgrenade from a crate will there then be 9 left for all players or only for the player who took the granade?

Share this post


Link to post
Share on other sites

AFAIK, only one grenade missing on the PC of the player who took the nade

Share this post


Link to post
Share on other sites
AFAIK, only one grenade missing on the PC of the player who took the nade

Ok thanks its starting to clear up a little bit for me now :D

Yet another question:

I have this variable:

getMsg = false;

in my init.sqf

and i got this:

if (getMsg) then {
hint format["Hello world"];
getMsg = false;
};

running in a script on a client.

If i set getMsg = true; from server only will the client running the above script then get the message "Hello world"?

After the the message i set getMsg = false; again but it's done client side so will this be updated globally so server knows its set to false again?

Share this post


Link to post
Share on other sites

Hint wont show if you set it true on server without publicvariable.

A global variable does not mean it's global in sense of clients and server. Rather, it can be used anywhere (triggers, scripts etc) on the machine in question (client or server). Every machine has their own global variables. To update/sync them you use publicvariable command.

Share this post


Link to post
Share on other sites
Hint wont show if you set it true on server without publicvariable.

A global variable does not mean it's global in sense of clients and server. Rather, it can be used anywhere (triggers, scripts etc) on the machine in question (client or server). Every machine has their own global variables. To update/sync them you use publicvariable command.

Could you please show me how to do my example using publicVariable?

Is this what you mean?

publicvariable "getMsg";

getMsg = false;

*EDIT*

What i'm trying to figure out is how to pass a variable from server to client. I have a script that is run server side which spawn some vehicles. At the end it does a waituntil !alive vehicles and then i would like to pass a variable to clients letting them know all vehicles is out!

Edited by JW Custom

Share this post


Link to post
Share on other sites

Init.sqf

if (isserver) then {
 //do the spawning stuff
 spawningDone = true;
 publicvariable "spawningDone";
} else {
 [] spawn {
   waituntil {!isnil "spawningDone"};
   hint "spawning finished";
 };
};

Edited by Shuko

Share this post


Link to post
Share on other sites

This code only works on dedicated server, on hosted game, the hint won't appear on the hosting machine because it is also server

Share this post


Link to post
Share on other sites
Init.sqf

if (isserver) then {
 //do the spawning stuff
 spawningDone = true;
 publicvariable "spawningDone";
} else {
 [] spawn {
   waituntil {!isnil "spawningDone"};
   hint "spawning finished";
 };
};

Thanks :)

So i can have this in my init.sqf

spawningDone = false;

publicvariable "spawningDone";

and this in my serverside only spawn script at the end:

spawningDone = true;

publicvariable "spawningDone";

and have a trigger checking if spawningDone = true and if true showing a message which all clients see?

Share this post


Link to post
Share on other sites

Basically yes, however you dont need to PV the false value if it's set for everyone at the start.

Share this post


Link to post
Share on other sites
Basically yes, however you dont need to PV the false value if it's set for everyone at the start.

Thank you so much for your patience, this has been a problem for me understanding but now i'm progressing. It's REALLY appreciated :cool:

Thanks to all who took the time and replied :)

Edited by JW Custom

Share this post


Link to post
Share on other sites

ok so heres my problem, ive got a script that i want to run once and only once, the team leader is the only person who can activate it how ever any member of the group can trigger the add action that sets the script in motion

how ever once the script is triggerd (it deletes from the leaders action list and any other lists that might have it up) if one of the other team members is close and looks at the team leader the addiction apears and the script can be re activated, how do i set it up so that once its activated it happens once (on the server - host or dedicated) then under no circumstances can it be triggerd again?

ive tryd

if (isserver) then {

and that stopd the team leader from being able to trigger the add action and even the script,

im way outta my depth here, any help would be so very apreciated

thanks heaps

heres the current script - as last tested

if (isServer) then {

(_this select 0) removeAction (_this select 2);

{_x removeAction actionName} forEach allUnits;

{_x removeAction actionName} forEach allDead;

{_x removeAction actionName} forEach vehicles;

_one_who_used_action = _this select 1;

_id_of_action = _this select 2;

_one_who_used_action removeAction _id_of_action;

hint "Take cover, Arty's on the way in. Marked white";

motar fire "M252";

waitUntil sleep 1.5;

bomb = "SmokeShell" createVehicle [(getmarkerPos "smoke" select 0),( getmarkerPos "smoke" select 1), 150];

M119c fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_WP" createVehicle [(getmarkerPos "burn" select 0),( getmarkerPos "burn" select 1), 2500];

waitUntil sleep 0.5;

M119c fire "M119";

waitUntil sleep 0.5;

M119b fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_WP" createVehicle [(getmarkerPos "burn2" select 0),( getmarkerPos "burn2" select 1), 2500];

waitUntil sleep 0.5;

M119D fire "M119";

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn3" select 0),( getmarkerPos "burn3" select 1), 2500];

waitUntil sleep 0.5;

M119c fire "M119";

waitUntil sleep 0.5;

M119d fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn4" select 0),( getmarkerPos "burn4" select 1), 2500];

waitUntil sleep 0.5;

M119b fire "M119";

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn5" select 0),( getmarkerPos "burn5" select 1), 2500];

waitUntil sleep 0.5;

M119b fire "M119";

waitUntil sleep 0.5;

M119c fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_WP" createVehicle [(getmarkerPos "burn6" select 0),( getmarkerPos "burn6" select 1), 2500];

waitUntil sleep 0.5;

M119A fire "M119";

waitUntil sleep 0.5;

M119d fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn7" select 0),( getmarkerPos "burn7" select 1), 2500];

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

M119b fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn8" select 0),( getmarkerPos "burn8" select 1), 2500];

waitUntil sleep 0.5;

M119c fire "M119";

waitUntil sleep 0.5;

M119d fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "burn9" select 0),( getmarkerPos "burn9" select 1), 2500];

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

M119D fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_WP" createVehicle [(getmarkerPos "wp2" select 0),( getmarkerPos "wp2" select 1), 2500];

waitUntil sleep 0.5;

M119B fire "M119";

waitUntil sleep 0.5;

M119C fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_Wp" createVehicle [(getmarkerPos "wp" select 0),( getmarkerPos "wp" select 1), 2500];

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

M119D fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_Wp" createVehicle [(getmarkerPos "wp1" select 0),( getmarkerPos "wp1" select 1), 2500];

waitUntil sleep 0.5;

M119B fire "M119";

waitUntil sleep 0.5;

M119C fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "MISS" select 0),( getmarkerPos "MISS" select 1), 2500];

waitUntil sleep 0.5;

M119a fire "M119";

waitUntil sleep 0.5;

M119D fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_Wp" createVehicle [(getmarkerPos "MISS2" select 0),( getmarkerPos "MISS2" select 1), 2500];

waitUntil sleep 0.5;

M119D fire "M119";

waitUntil sleep 0.5;

M119A fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "MISS3" select 0),( getmarkerPos "MISS3" select 1), 2500];

waitUntil sleep 0.5;

M119B fire "M119";

waitUntil sleep 0.5;

M119C fire "M119";

waitUntil sleep 0.5;

bomb = "ARTY_Sh_105_HE" createVehicle [(getmarkerPos "MISS4" select 0),( getmarkerPos "MISS4" select 1), 2500];

(_this select 0) removeAction (_this select 2);

{_x removeAction actionName} forEach allUnits;

{_x removeAction actionName} forEach allDead;

{_x removeAction actionName} forEach vehicles;

_one_who_used_action = _this select 1;

_id_of_action = _this select 2;

_one_who_used_action removeAction _id_of_action;

};

once i iron out this little kink the mission will be complete and 100% bug free and completely ready for release!

Share this post


Link to post
Share on other sites

Concerning weapon crates that are meant to be treated equally for the server (dedicated or not) and all clients:

in the initline of a crate named "box" or in a trigger for that box:

[box] exec "box.sqf";

box.sqf:

if !(isServer) then { exit };

_box = _this select 0;

clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;

_box addweaponcargoGlobal ["m16a2", 4];
_box addmagazinecargoGlobal ["30Rnd_556x45_Stanag", 50];

exit;

Share this post


Link to post
Share on other sites

I've tried using isServer, isServer && isDedicated and isDedicated ..... none did work for a trigger that createvehicles lgb bomb? I use it for IEDs. Any clues what would work in trigger?

Share this post


Link to post
Share on other sites

in the condition field of the trigger use the isServer etc commands.

in the on act, make sure you create the bomb correctly, works just fine.

best way is to use createVehicle Array and not just normal createVehicle

Share this post


Link to post
Share on other sites
in the condition field of the trigger use the isServer etc commands.

in the on act, make sure you create the bomb correctly, works just fine.

best way is to use createVehicle Array and not just normal createVehicle

will this work on my script?

Share this post


Link to post
Share on other sites
will this work on my script?

yes, in the radio alpha trigger condition for example, use:

this AND isServer

in on act do your create vehicle (bombs) part, dont use the if IsServer part there as you already did it in condition.

now when you activate the radio alpha trigger, the bombs are created only on server (correctly).

ofc sleeps or waitUntils do not work in on act fields of triggers.

'

but its ofc much better to use scripts run instead of wall of code in the on act field for the sleeps and waituntils to work, and you can also use spawn with some limitations.

Share this post


Link to post
Share on other sites

Just so this information is in this thread:

Here is a list of machine types (singleplayer, servers, client) and how various condition checks will return if run on that machine. For example, if you wanted to make sure a machine was a MP host and not a dedicated server you could run:

Code:

if ((isServer) and (!isDedicated)) then {...);

You don’t usually need to check more than two (and sometimes one will do) but here is a list of how all three SP/MP condition checks return for all SP/MP game modes:

EDITOR PREVIEW / SINGLEPLAYER:

isMultiplayer returns false

isServer returns true

isDedicated returns false

MULTIPLAYER (NON-DEDICATED) HOST SERVER

isMultiplayer returns true

isServer returns true

isDedicated returns false

MULTIPLAYER DEDICATED SERVER

isMultiplayer returns true

isServer returns true

isDedicated returns true

MULTIPLAYER CLIENT

isMultiplayer returns true

isServer returns false

isDedicated returns false

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  

×