aie-boshell 22 Posted January 9, 2018 Hello, I'm fairly new at multiplayer scripting on dedicated servers. I just learned that some commands don't work on dedicated servers so I've just been trying to cover every basis to make sure my scripts work on dedicated by using both publicvariable and publicvariableserver for every variable I create. I'm now getting to where I have so many variables I'm worried that I may be unnecessarily affecting performance by adding both of these commands to each variable. Would someone like to clarify this for us? Does publicvariableserver only send the variable to the server or does it also send the variable to each client computer as well as the server? Any info is appreciated very much :-) Share this post Link to post Share on other sites
Tankbuster 1744 Posted January 9, 2018 Publicvariableserver sends the variable to the server. Publicvariable sends it everywhere, clients and server. 1 Share this post Link to post Share on other sites
mrcurry 496 Posted January 9, 2018 As for network performance the key is to send as little data across the network as possible i.e. only send data if required. If the data is only required by the current machine you should probably not broadcast it. If you have a lot of network calls with few possible values consider enumerating the data. If you can send a (small) number instead of a word it's going to save bandwidth. Also avoid broadcasting unless the value has changed. 1 1 Share this post Link to post Share on other sites
Belbo 462 Posted January 9, 2018 setVariable has the great perk of giving you the option to both define or change a variable value and broadcast it at the same time. missionNamespace setVariable ["var",1,true]; does the same as var = 1; publicVariable "var"; But you can as well grab the original value with getVariable and change it - getVariable offers the additional option to define a standard value if the variable is not yet defined: missionNamespace setVariable ["var",(missionnamespace getVariable ["var",0])+1,true]; That still doesn't change anything in regard of network traffic though, so you still have to consider whether or not you want a variable to be broadcasted. To be a little more helpful: There are very few commands that don't work on a dedicated server. There are certain commands that have to be executed on the dedicated server only in order to work globally (like setFog - you recognize those commands with the green sE-icon at the top of their page in the biki). The only thing you have to keep in mind for scripting for dedicated servers is that you don't have a player on the server - in hosted games the server is the client of the host, so player is defined as the host's player unit. That is not the case on the dedicated server. But that aside there's fairly little that has to be changed for something to work on both hosted and dedicated environments. Locality is always an issue. 2 1 Share this post Link to post Share on other sites
aie-boshell 22 Posted January 9, 2018 Excellent information from all three of you. You guys are fantastic, I should have asked a long time ago. Thank you so much! I guess I should ask one more question to avoid making more work for myself again. I know it's complex and I will likely have to learn a lot and make decisions myself but is there any info you can offer about what type of commands should only be broadcast on the server? 1 Share this post Link to post Share on other sites
Belbo 462 Posted January 9, 2018 The Biki is a really great place: https://community.bistudio.com/wiki/Category:Commands_requiring_server_side_execution 2 1 Share this post Link to post Share on other sites
austin_medic 109 Posted January 10, 2018 13 hours ago, aie-boshell said: Excellent information from all three of you. You guys are fantastic, I should have asked a long time ago. Thank you so much! I guess I should ask one more question to avoid making more work for myself again. I know it's complex and I will likely have to learn a lot and make decisions myself but is there any info you can offer about what type of commands should only be broadcast on the server? Basically any commands that will have a global effect should only happen on the server. Ask the question, will what this script is doing effect everyone? If the answer is yes, do it on the server only. If it will only effect a couple other clients then you could target those machines directly instead of doing broadcast to optimize bandwidth usage. This way you can avoid duplicating behavior caused by multiple clients running the script at the same time (and also a bit out of sync, depending on many factors) If you spawn a car through a script that is running on each client, you'll get a crap load of duplicates and probably a large explosion will follow. This is because each car that each client spawned got sent across the network to all the other machines, and they all spawned their own copies of that vehicle. However, if we do it on the server, only one vehicle will be created. Each client will spawn their own respective copy of that single vehicle instead of a whole bunch depending on how many players you have. 1 Share this post Link to post Share on other sites
pierremgi 4851 Posted January 10, 2018 You have four main types of commands, along with their argument A and Effect E, both could be local L or global G. So AL EL, AL EG, AG EL, AG EG plus SE (must run on server) See the icons given in header of each command. Now, mind for the context where you fire your command (or function), and the expected effect. For example, initServerLocal.sqf, or addAction, or event handlers (EH) environment (local most of the time) will fire their code locally. No problem to use AL EG or AG EG here. If you want some EL like hint command for the player who trigger the code, no problem also. On the other end, you will have to remoteExec the EL if you need something everywhere (global hint for instance), and even remoteExec on server the famous SE commands. Example EH "killed" something changing the score, you will have to remoteExec <addScore> command on <2> (server). See remoteExec details. Note: BI created multiplayer EH (MPEH) for some behaviors like "MPKilled". These MPEH run their code globally. That's must be taken into account! In global (MP in fact) environment, the code will run on any PC, like in init field of edited object, init.sqf, basic trigger,... Here you have to cope with some other problems like: - duplication : spawned unit is a good example. But you can filter that with the <isServer> or <local> commands, or server only trigger. - reset: Most of the time, each join in player (JIP) will run the code as written, running mission.sqm (all init fields of edited object), init.sqf, description.ext.. and other event sqf. So, without if (isServer) then {..}; You can experience some unit loadout reset (displayed on every PC if you used EG command, generally the case for equipments). Some commands will not work here, like setObjectTextureGlobal which like to be run once and never ever on every PC (same for all global version of command). See also <local> command. In global, context, some AL commands will fire easily on the local PC: if (local something) then {AL commands code} Other related question: Where are you? Difficult to say where the locality is. As reminder, player is local. On hosted server, player is on server. On dedicated one, there is no player and it's useless to script with player command. On client, player is local on the player's PC. But for AIs and vehicles? See here. If you master all of these points, here is a good exercise: In MP session, make any player able to push a shored rubber boat in order to make it float. In this "simple" scenario, use addAction, setVelocity on an empty rubber boat edited on a beach. Hint: the empty rubber boat belongs to server, standard player is on his local PC. Don't cheat jumping into boat (then changing its locality) before "pushing" it. 1 Share this post Link to post Share on other sites
aie-boshell 22 Posted January 11, 2018 That should cover everything I need to know. I can't thank you all enough :-) Share this post Link to post Share on other sites