Jump to content
  • 0

Call function from another script - possible?


lima

Question

I want to call/spawn a function which is defined in my AH.sqf, but from another script. The AH.sqf runs at every server start, so I don't want to run it again.

 

How can I call/spawn that specific function from AH.sqf script without running the entire script again?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Well it depends on the script you are trying to run. If its a simple script like this:

            player_changeMySkin =
            {
                _humanityMorph = compile preprocessFileLineNumbers '\z\addons\dayz_code\compile\player_humanityMorph.sqf';
                _result = _this call _humanityMorph;
                _result
            };

Then you add the above function in a .sqf file (skin.sqf) and then add it to your compiles.sqf like this

change_skin = compile preprocessFileLineNumbers "custom\skin.sqf";   

Then from anywhere in your files where you want to execute it you do :

(Of course at the proper line....in this case after getting the skin name and add it to the _model value).

[dayz_playerUID, dayz_characterID, _model] spawn change_skin;

But like i said, depends on the function. Some are not meant to be run in the mission.pbo and only work in server.pbo.

 

The above way works with server.pbo files as well....instead of adding into compliles.sqf you add that line in the server_functions.sqf

Link to comment
Share on other sites

  • 0

Well it depends on the script you are trying to run. If its a simple script like this:

 

I think you misunderstand my question :-)

 

I want to run a specific function which is defined in my AH.sqf file. The entire file has more than 6000 lines of code - so I don't want to rerun the entire script, just that one function.

 

So I'm looking for a way to only run a specific function from that script, without running the entire thing. 

Link to comment
Share on other sites

  • 0

I think you misunderstand my question :-)

 

I want to run a specific function which is defined in my AH.sqf file. The entire file has more than 6000 lines of code - so I don't want to rerun the entire script, just that one function.

 

So I'm looking for a way to only run a specific function from that script, without running the entire thing. 

 

Change the local var to a global var (remove the leading _ ).

Be sure to change all references to the old variable name to the new variable name!!

 

Note: if you do this the global variable will be within the scope of the machine that ran the AH code. If it's run on the server then it is only within the scope of the server so it needs to be sent to clients via publicVariable.

I.e. publicVariable "YOURGLOBALVARNAME";

 

Then you can simply run the code on the client by calling or spawning it.

 

[] spawn YOURGLOBALVARNAME;

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...