MINKA 14 Posted November 22, 2014 Server Sided Scripting Tutorial Skill Level Required: Intermmediate What is Serverside Scripting? Serversided scripting is where you execute scripts on a server only. Which enables you to do things like database storage or private functions and such. It is a good way to keep certain functions private from everyone, Since Serversided scripts are held server only, Examples of Serverside Scripting Usage Altis Life from Tonic has its own Serversided addon which holds all the functions which control things like weather, Stat Save etc. DayZ has a Server Sided addon which controls weather, and Stat Saves. Serversided scripting is also a good way to keep 2 servers linked together in a way. Like as commonly seen in Life servers, 1 Database is used by multiple servers. How to do it? There are a few methods to Server Sided scripting. Of course, Your mission file or client scripts will need to utilise this. For ArmA 3, BIS has praised us with the BIS_fnc_MP function. Which allows the scripter to execute functions remotely, Be it through different clients or on the server itself. hint_func = { _text = _this select 0; hint _text; }; [["Hello"],"hint_func",true] call BIS_fnc_MP; The above code is an example which will hint "Hello" to everyone connected to the server. I will break it down below. [[FUNCTION PARAM], "functionName",WhereToExecute] call BIS_fnc_MP; FUNCTION PARAM - Parameters you wish to send through to the function "functionName" - Name of your function you wish to execute WhereToExecute - Where to remotely execute. If set to [b]true[/b], Then it executes on every client. if set to [b]false[/b] it will execute on the server. You can also supply client ID(owner), or groups etc. As you could imagine, fn_MP makes life a lot easier. So, what about serverside scripting? well that part is simple. Everything is exactly the same as it being clientsided. Think of your server as an actual client itself. It can hold its own seperate configs, and functions library. So with that being said, We can realise how much simpler it would be to be to script that one would normally think. Where to get started? Well, Make a new folder in your ArmA 3 folder, call it "TestServerSide", without the quotations. Now in TestServerSide, which we will call TSS for now, Put a new file called init.sqf and put the following in: sample_log = { _log = _this select 0; diag_log format["I have received a new log on the server: %1",_log]; }; Congratulations! You have made your first Serversided script which has the ability to take a parameter and log it to a file so that we can view it. Now.. Where to execute it?? Well, go to your mission file's init.sqf, and put the following: if(isServer) then { [] execVM "TestServerSide\init.sqf"; }; [["Wow! It works!"],"sample_log",false] call BIS_fnc_MP; hint "Done!"; wait.. so what?? Okay. if(isServer) then{}; - This code will only execute on the server upon you joining the server. [] execVM "TestServerSide\init.sqf"; - Since it is in the isServer statement, The server will execute that file, which holds our function. [["Wow! It works!"],"sample_log",false] call BIS_fnc_MP; - As detailed above, This MP function allows remote execution, So, when we use it's location as false it sends it to the server. In our case, it executes our sample_log function. Okay so here is a little checklist: Define serverside function - Done! Make script to execute function on the server - Done! Now, download TADST(preferably), And when setting up, Be sure, in the "mods" section, enable "TestServerSide", and in the mission file section, enable the mission file which holds the isserver statement above in its init.sqf. Once you have seen the hint "Done!" come up on your screen, Go to TADST, then to the main section, then Open the arma2oaserver.rpt, Then press Ctrl+F and search "New Log"; Congrats! If you have any errors or issues, Feel free to post em in a reply and I will try my best to help out! 1 Share this post Link to post Share on other sites
dreadedentity 278 Posted November 22, 2014 There is also an initServer.sqf event script, it will only be run by the server. Share this post Link to post Share on other sites
jshock 513 Posted November 22, 2014 (edited) Would this information not be more appropriate in the Mission Scripting and Editing Forum, not the Addons Configs and Scripting? That's just my personal opinion :D. ---------- Post added at 21:28 ---------- Previous post was at 21:27 ---------- There is also an initServer.sqf event script, it will only be run by the server. And this is also an easy way to do everything server side without having to have all the extra checks within the script :p. https://community.bistudio.com/wiki/Event_Scripts And to clarify and add to what Dreaded stated, the initServer.sqf runs once on the server at the beginning of the mission, the initPlayerServer.sqf runs on the server at mission start and again on the server for every JIP that joins the server. So if you have a script that needs to run on the server, but every client that joins needs to run it, initPlayerServer.sqf would be the appropriate file to use. And another addition to this as well, if you wanted to access files that were on the server, and not on the clients, such as a ban.txt or an admin.txt file to check UIDs of the player, when writing the path to the file you would need to make sure to have a "\" in front of the directory path. path\file.txt; //Checks only in the missions folder \path\file.txt; //Checks the game root directory folder Edited November 22, 2014 by JShock 1 Share this post Link to post Share on other sites
Naiss 28 Posted December 27, 2014 hello, i just tested what i showed here and i get the logs in the log file thing but i want to get the msg back to the player so i tryed this but i never got the message back so if you can maybe help me out here please: init: if(isServer) then { [] execVM "RPPServer\initTest.sqf"; }; [[player,"Wow! It works!"],"sample_log",false] call BIS_fnc_MP; systemChat "Done!"; code Server side: sample_log = { _player = _this select 0; _log = _this select 1; diag_log format["I have received a new log on the server: %1 from %2",_log, name _player]; _msg = "Logs are now loaded and i will return it back to you with this message :D"; [[_msg], "get_log", _player] call bis_fnc_mp; }; get_log = { _log = _this select 0; hint format ["Debug: %1",_log]; }; ---------- Post added at 05:40 ---------- Previous post was at 05:08 ---------- neverminde i got it working i just did this command right under the get_log function, publicVariable "Get_log"; Share this post Link to post Share on other sites
jshock 513 Posted December 27, 2014 It's your third condition in BIS_fnc_MP, it's set to false, at which point the function will only be executed on the server, and sense you have if (isServer) around all of that the player variable won't work as you intend. Share this post Link to post Share on other sites