Jump to content
mxstylie

if (is server) then question

Recommended Posts

Hello,

 

Can you have more than one  if(isServer) then in your init, or does everything need to go between (in) the same one? I am asking because I was running a heli crash/drop script and it is working great, I wanted to add player save data (position, loadout etc) for my MP mission. I can only get the player save data scripts to work when I remove the heli crash/drop script. Both use the if(isServer) then command. Both work great on their own I think I just nee help putting them together. Thanks.

 

Save Script init:

 

enableSaving [FALSE,FALSE];
 
//ADD THIS TO YOUR MISSION'S INIT FILE
waitUntil {time > 0};
 
execVM "statSave\saveFuncs.sqf";
waitUntil {!isNil "saveFuncsLoaded"};
 
if(isServer) then
{
 
_serverHasID = profileNameSpace getVariable ["ss_ServerID",nil];
if(isNil "_serverHasID") then
{
_serverID = str(round((random(100000)) + random 10000));
profileNameSpace setVariable ["SS_ServerID",_serverID];
};
serverID = profileNameSpace getVariable "ss_ServerID";
publicVariable "serverID";
};
 
waitUntil {!isNil "serverID"};
 
 
if(!isDedicated) then
{
execVM "statSave\loadAccount.sqf";
execVM "statSave\saveLoop.sqf";
 
 
};
//========================================================================
 
Heli Script init:
 
//ETG Heli Crash And Drop Script
if (isServer) then {
     fn_crashdrop = compile preprocessFile "fn_crashdrop.sqf";
     [2] call fn_crashdrop; 
};
 

Share this post


Link to post
Share on other sites

Thank you for the reply. I suppose I should have mentioned that I am running this MP mission on my computer and friends are connecting to my game. When I tried running an initServer.sqf with the scripts it did not load the players saved data, so I assumed the heli was not working either. I went back to my original init.sqf and the data was still there and players are able to join with their gear position etc. When I had the Heli script running before the save script the save script was not working. I now have the save scripts running before the Heli script and it is working fine. I'm going to test and see if the heli is spawing. I basically just pasted the entire heli script from above right below the save script in the init.sqf. Thanks again for the help I really appreciate it, I am new to this. 

Share this post


Link to post
Share on other sites

I've tried a few different combinations and still can't seem to get both of these scripts working at the same time. I went back to just using the player data save stuff as it is the most important at this point. Any other help/ideas would be appreciated. If not no worries and thanks for reading my post.

Share this post


Link to post
Share on other sites

to answer ur 1st question, u can have as many if(isServer) constructs as u need and u can use it in any script u want. isServer returns just a boolean which is true when the machine is hosting the game.

why r u using isDedicated, too? i thought u dont use a dedicated server.

Share this post


Link to post
Share on other sites

Thanks for answering the question. There is no reason at all that I am using isDedicated. I just copied the script from here https://forums.bistudio.com/topic/149167-addon-free-stat-save-system-script/ it worked right away so I figured I would leave it alone. Maybe this is my problem? I will try to remove isDedicated from the script and see if I can then run the heli crash script.

Share this post


Link to post
Share on other sites

The difference between isServer and isDedicated is only that:

 

isServer = run code if executed machine is dedicated server or host pc

isDedicated = run code on dedicated server only

 

for example:

 

if you use isServer to run some script it will fire even when you preview your mission in editor.

if you use isDedicated instead it will not fire when you preview your mission in editor.

Share this post


Link to post
Share on other sites

Thanks davidoss for the description. When I remove isDedicated, no matter if I run from the editor or from the multiplayer , the save scripts doesn't run. When I add isDedicated back in, I spawn in my location with my loadout.

Share this post


Link to post
Share on other sites

Thank you guys for the direction, I got them both running together like this:

 

enableSaving [FALSE,FALSE];
 
waitUntil {time > 0};
 
execVM "statSave\saveFuncs.sqf";
waitUntil {!isNil "saveFuncsLoaded"};
 
if(isServer) then
{
 
_serverHasID = profileNameSpace getVariable ["ss_ServerID",nil];
if(isNil "_serverHasID") then
{
_serverID = str(round((random(100000)) + random 10000));
profileNameSpace setVariable ["SS_ServerID",_serverID];
};
serverID = profileNameSpace getVariable "ss_ServerID";
publicVariable "serverID";
 
 
};
 
waitUntil {!isNil "serverID"};
 
 
if(!isDedicated) then
{
execVM "statSave\loadAccount.sqf";
execVM "statSave\saveLoop.sqf";
 
 
};
 
if (isServer) then {
     fn_crashdrop = compile preprocessFile "fn_crashdrop.sqf";
     [2] call fn_crashdrop; 
};

Share this post


Link to post
Share on other sites

Hi folks - im having a question for the isServer command. 

Im trying to make a paradrop with the players in the mission im making. I used the trigger activation code:

P1 allowDamage false;
 

on the drop itself, just to prevent players playing the mission dying on trees, as this is Tanoa we're speaking about. Then, at the "meet-up-point" i have a new trigger with this:

P1 allowDamage true;

to enable damage again, so that the players could be killed if they did something stupid. 

This works fine when im hosting multiplayer on my own local computer, or in singleplayer - but this does not work on my dedicated server. I came across this isServer command conserning my radio chat messages, which solved the whole problem for chat messages not showing on dedicated servers. However, i was wondering if this also work for the allowDamage command. 

I've tried these now:

if isServer then {P1 allowDamage false};

if isServer then {P1 allowDamage true};

Any other advice on the matter from those who knows more? 

Answers would be greatly appreciated :)

Share this post


Link to post
Share on other sites

It must be run on the players PC, not the dedi server, so if your script runs on the server, then use remoteExec or remoteExecCall to send a request for the player to execute it locally on their PC

[p1,false] remoteExec ["allowDamage",p1]; // invulnerable

[p1,true] remoteExec ["allowDamage",p1]; // vulnerable

Share this post


Link to post
Share on other sites

Thanks for the reply - i dont use scripts on this particular mission, but trigger activations - which i know for the most part are local, but in my experience there are codes that would apply for multiplayer on dedicated servers as well - as i luckily found out with the side/vehicle chat commands with the isServer code. 

I'll try what you gave me and see how it goes - thanks again! 

Kind regards!

Share this post


Link to post
Share on other sites

These commands did not work - still dying if i hit the trees on the way down. 

However, i guess i could just abandon this quest for "streamlining" the mission as such, and leave it in there as a natural difficulty. One really should not land in trees anyway....

Share this post


Link to post
Share on other sites
Guest

These commands did not work - still dying if i hit the trees on the way down. 

However, i guess i could just abandon this quest for "streamlining" the mission as such, and leave it in there as a natural difficulty. One really should not land in trees anyway....

You must add CfgRemoteExec to your description.ext to allow the execution of allowDamage with remoteExec (witch I don't recommend for popular mission - just use a custom fnc).

Here you can find all the details.

https://community.bistudio.com/wiki/Description.ext#CfgRemoteExec

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

×