Jump to content
cap42

server side mission independent script

Recommended Posts

Hi,

I was wondering if there's a way to have a script running on the server, independent of the mission currently playing?

For example, I found a very convenient earplug script and I'd like to have that available for all missions without having to edit them.

I suppose, it could be packaged into a mod, but I was hoping for a less involved solution - I haven't been able to find anything. Thanks!

Share this post


Link to post
Share on other sites

Mod would be the obvious solution

Sent from my D6503 using Tapatalk

Share this post


Link to post
Share on other sites
2 hours ago, cap42 said:

Hi,

I was wondering if there's a way to have a script running on the server, independent of the mission currently playing?

For example, I found a very convenient earplug script and I'd like to have that available for all missions without having to edit them.

I suppose, it could be packaged into a mod, but I was hoping for a less involved solution - I haven't been able to find anything. Thanks!

Well, you do not have to make a mod, you can also make a addon, PVAR the function and then use it client-side in mission :f:

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, tirpitz said:

Mod would be the obvious solution

ok, but I was looking for another solution as every client needs that mod installed, correct? or are there server mods that don't need to exist on client?

 

3 hours ago, SimZor said:

you can also make a addon, PVAR the function and then use it client-side in mission :f:

 

If I understand that correctly, all that would do is hide the functionality to the client, but the mission would still need to be altered so the function is loaded on the client?

 

Let me try explaining my problem again:

I'd like to create a script that only exists on the server, but is executed every time a mission is loaded without having to edit the mission files, or any need to act for clients connecting.

Basically an init/playerinit that is run regardless of mission files or client setup.

Share this post


Link to post
Share on other sites

this is possible by a server side mod.

you can create a mod which is needed by server only.

Share this post


Link to post
Share on other sites

You could make to mod server side only, only the server would have to run it

Sent from my D6503 using Tapatalk

Share this post


Link to post
Share on other sites
1 hour ago, cap42 said:

ok, but I was looking for another solution as every client needs that mod installed, correct? or are there server mods that don't need to exist on client?

 

If I understand that correctly, all that would do is hide the functionality to the client, but the mission would still need to be altered so the function is loaded on the client?

 

Let me try explaining my problem again:

I'd like to create a script that only exists on the server, but is executed every time a mission is loaded without having to edit the mission files, or any need to act for clients connecting.

Basically an init/playerinit that is run regardless of mission files or client setup.

 

If you need an example,study Duda's Advanced Rappelling Mod.  It works exactly as @SimZor described, so only the server needs the mod and sends the relevant files to the client without modifying the mission.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

thanks guys :) good to know.

1 hour ago, das attorney said:

 

If you need an example

awesome, thanks a million!

This'll be very useful. On that note, I've had an issue packing pbo files and was wondering if I'm using the wrong tool. In the arma tools on steam there's and addon builder but when I use that to pack the folder of advanced rappeling after extracting it, most of the original content is missing after extracting again. I've seen pbo manager, is that still the go-to tool? I was wondering, because it hasn't been updated in a few years on armaholic.

Share this post


Link to post
Share on other sites
5 hours ago, cap42 said:

ok, but I was looking for another solution as every client needs that mod installed, correct? or are there server mods that don't need to exist on client?

 

If I understand that correctly, all that would do is hide the functionality to the client, but the mission would still need to be altered so the function is loaded on the client?

 

Let me try explaining my problem again:

I'd like to create a script that only exists on the server, but is executed every time a mission is loaded without having to edit the mission files, or any need to act for clients connecting.

Basically an init/playerinit that is run regardless of mission files or client setup.

 

Just PVAR it on server init. Using 

publicVariable "myFunc";

Just make sure function is compiled before, no need to alter mission in order to do this.

 

For those who says "Server Side Mod", it's not a mod, it's an addon.

Share this post


Link to post
Share on other sites

I think we're getting lost in terminology and semantics here.

 

From my pov, you load it as a mod to the server (in batch file or w/e) so I would just say it's a "server mod".  However @SimZor I totally get your pov (an addon).

 

Let's not lose sight of the issue though.

 

@cap42 It would be useful if you documented what you're trying to do more thoroughly.  I would say it would benefit you if you took the structure from Duda's mod and re-wrote it rather than repacking his mod.  If you're unsure, then PM him.  He's a really nice guy (from my dealings with him), so don't be afraid to ask!  :)

  • Like 1

Share this post


Link to post
Share on other sites
21 minutes ago, das attorney said:

you load it as a mod to the server (in batch file or w/e)

since it's a mod, it'd have to be packed as a pbo, right? sorry if I'm being a bit daft, but never done a mod for arma, only recently started scripting...

 

23 minutes ago, das attorney said:

It would be useful if you documented what you're trying to do more thoroughly.

right, so to give you a for instance, I'd like this script to be loaded for every player, no matter what the mission is. It's an earplug script I nicked off a mission I downloaded from steam workshop..

sepa = ["<t color='#ffff33'>Put on ear plugs</t>",{
	_u = _this select 1;
	_i = _this select 2;
	if (soundVolume == 1) then {
		1 fadeSound 0.3;
		_u setUserActionText [_i,"<t color='#ffff33'>Take off ear plugs</t>"]
	} else {
		1 fadeSound 1;
		_u setUserActionText [_i,"<t color='#ffff33'>Put on ear plugs</t>"]
	}
},[],-90,false,true,"","_target == vehicle player"];
_this addAction sepa;
_this addEventHandler ["Respawn",{
	1 fadeSound 1;
	(_this select 0) addAction sepa;
}];

there's other scripts that I'd probably like to add, but for now I'd like to test it with this one.

Regarding the repacking, I wasn't so much trying to repack Duda's mod with the above, but just testing if the pbo packing tool worked, and it the packaged pbo was missing most of the files for some reason. I haven't really found a good source for explaining the modding basics. I'll probably just have to wrap my head around it. Thanks for letting me know that Duda probably won't mind a PM. I'll play around a bit more first and then do that very likely when stuck.

Share this post


Link to post
Share on other sites

@cap42 It will have to be packed in a PBO, yes.

 

You will have to make a config.cpp with relative configs. And then just use CfgFunctions Framework if that floats your boat, or just preProc. yourself. Just make sure everything is compiled final.

  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, SimZor said:

@cap42 It will have to be packed in a PBO, yes.

 

You will have to make a config.cpp with relative configs. And then just use CfgFunctions Framework if that floats your boat, or just preProc. yourself. Just make sure everything is compiled final.

@SimZor @das attorney: Thanks to the both of you, I got it working! Awesome, this will be a gamechanger and will take away the pain of editing/saving/syncing missions to server. For now, I just have that earplug script working, but this is perfect!

 

I was wondering, is there a preferred approach to do this, or one that performs better for complicated things(CfgFunctions vs preProc)? Also, I'm not sure how to implement the latter, could you give me a for instance? I know about preProc in scripts, would that just be that?

Also, I'd appreciate it, if one of you could take a peek at what I did and let me know if there's something redundant/wrong.

I wasn't sure about the CfgFunctions part and basically just copied and altered it a bit... is there a need to have all these subclasses?

Also, I'd like to make sure again, the script isn't mine and I don't intend to publish it in this state...

folder layout:

@cap_earplug

-mod.cpp
    -addons

          - cap_earplug.pbo

          - cap_earplug

                - config.cpp

                - functions

                        -earplug.sqf

  

anyway, here the files:

config.cpp:

Quote

#include "BIS_AddonInfo.hpp"
#define _ARMA_

class CfgPatches
{
    class cap_earplug
    {
        units[] = {};
        weapons[] = {};
        requiredAddons[] = {};
        author[] = {"Cap"};
    };
};

class CfgFunctions
{
    class cap_earplug
    {
        class LS {
            class Init
            {
              file = "\cap_earplug\functions\earplug.sqf";
              postInit = 1;
            };
        };
    };
};

 

earplug.sqf:

if (!isServer) exitWith {};



CAP_earplug_install = {

// Prevent earplug from installing twice
if(!isNil "cap_earplug_init") exitWith {};
cap_earplug_init = true;
diag_log "earplug loading";


CAP_earplug_player_action = {
		sepa = ["<t color='#ffff33'>Put on ear plugs</t>",{
			_u = _this select 1;
			_i = _this select 2;
			if (soundVolume == 1) then {
				1 fadeSound 0.3;
				_u setUserActionText [_i,"<t color='#ffff33'>Take off ear plugs</t>"]
			} else {
				1 fadeSound 1;
				_u setUserActionText [_i,"<t color='#ffff33'>Put on ear plugs</t>"]
			}
			},[],-90,false,true,"","_target == vehicle player"];
		_this addAction sepa;
		_this addEventHandler ["Respawn",{
		1 fadeSound 1;
		(_this select 0) addAction sepa;
		}];
	/*
	params ["_player"];
		
	_player addAction ["Rappel Self", { 
		[player, vehicle player] call AR_Rappel_From_Heli_Action;
	}, nil, 0, false, true, "", "[player, vehicle player] call AR_Rappel_From_Heli_Action_Check"];
	
	_player addAction ["Rappel AI Units", { 
		{
			if(!isPlayer _x) then {
				sleep 1;
				[_x, vehicle _x] call AR_Rappel_From_Heli_Action;
			};
		} forEach (units player);
	}, nil, 0, false, true, "", "[player] call AR_Rappel_AI_Units_From_Heli_Action_Check"];
	
	_player addAction ["Detach Rappel Device", { 
		[player] call AR_Rappel_Detach_Action;
	}, nil, 0, false, true, "", "[player] call AR_Rappel_Detach_Action_Check"];
	
	_player addEventHandler ["Respawn", {
		player setVariable ["AR_Actions_Loaded",false];
	}];
	*/
};



if(!isDedicated) then {
	[] spawn {
		while {true} do {
			if(!isNull player && isPlayer player) then {
				if!(player getVariable ["cap_earplug_action_loaded",false] ) then {
					player call CAP_earplug_player_action;
					player setVariable ["cap_earplug_action_loaded",true];
				};
			};
			sleep 5;
		};
	};
};


};



publicVariable "CAP_earplug_install";

[] call CAP_earplug_install;
// Install earplug on all clients (plus JIP) //
remoteExecCall ["CAP_earplug_install", -2,true];

 

Share this post


Link to post
Share on other sites

Sorry, if I understood it bad but.

 

This may work?

 

initServer.sqf

coolFunction = {_number = _this; hint format ["The server told me this secret number: %1",_number]};

publicVariable "coolFunction";
sleep 10;
(random 10) remoteExec ["coolFunction",-2];

 

Share this post


Link to post
Share on other sites

@cap42 CfgFunctions framework is the same as preProc, just that it does it for you with some magic variables attached like _fnc_scriptName etc, and should be just as fast.

 

If you are using CfgFunctions framework, you do not have to do myFunc = {}, I saw you did that somewhere in the script.

 

Just make sure you add the tag, like "CAP", and the function will automatically be made a mission namespace variable CAP_fnc_myFunction. Also, it is really unsecure to add code in a global variable as that can then later be changed by a hacker etc. If you want to do it that way, make sure to compile it finally so it cannot be changed later.

Share this post


Link to post
Share on other sites
58 minutes ago, SimZor said:

should be just as fast.

good to know.

 

58 minutes ago, SimZor said:

you do not have to do myFunc = {}

are you talking about in the actual script file? that's how you define a function though?  I don't see where else I used anything like that

58 minutes ago, SimZor said:

Also, it is really unsecure to add code in a global variable as that can then later be changed

ok, so in my example I wouldn't have to worry, as the cfg frameworks takes care of the pre-processing, right?

 

Do i need to add the tag somewhere in the config as well?

 

@barbolani: the initServer.sqf would be the obvious choice for editing the mission, but I'm trying to activate things mission independently.

Share this post


Link to post
Share on other sites

Oh! Then yes, an addon with that function which broadcasts the function to all clients and executes it with remote exec.

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

×