Jump to content
kromka

Access from init.sqf

Recommended Posts

Hello.

Is it possible to use external global funtions in init.sqf?

I have no problem with using them in other sqf scripts, but when i try to call any in init.sqf i recieve message than function doesn't exist.

Second question: is there any other method to preload function in init.sqf other than execVM "function.sqf"

BR.

 

Share this post


Link to post
Share on other sites

You could try to use

call compile preprocessFileLineNumbers

at the beginning of the init.sqf, however, I'm not sure if this has any effect.Other method would be to define the function in the description.ext

Share this post


Link to post
Share on other sites

And any mistake will crash your game to desktop, but hey right?  :)

 

Just make no mistake then;)

  • Like 1

Share this post


Link to post
Share on other sites

And any mistake will crash your game to desktop, but hey right?  :)

Only if your definition of CfgFunctions is wrong, your code wont CTD if wrong. Once you've got CfgFunction down and working you can use it as a template for next time.

Its not that hard, three classes and then a class for each script file.

class CfgFunctions {
	class myTag {	//TAG for your functions
		class myCategory {	//Category to go in functions viewer
			file = "myScripts";	//Path in mission folder where your scripts are
			class myFunction1 {};	//Each function name, file looked for will be fn_myFunction.sqf
			class myFunction2 {};
		};
	};
};

//Will create a function called
//myTag_fnc_myFunction from the file missionFolder\myScripts\fn_myFunction.sqf
  • Like 1

Share this post


Link to post
Share on other sites

Thank you for advices.

They turned out to be helpful.

 

In init.sqs:

[10, some_object] spawn tag_fnc_showTimeHint;

In description.ext:

class CfgFunctions
{
    class tag
    {
        class Category
        {
            class showTimeHint {file = "scripts\showTimeHint.sqf";};
        };
    };
};

In scripts\showTimeHint.sqf:

_time = _this select 0;
_objToDisplay = _this select 1;

hint format["%1", _objToDisplay];
sleep _time;
hint "";

// destructor
_time = nil;
_objToDisplay = nil;

End everything works fine.

 

BTW. Is there any reason to do such "destructor" in sqf files? Or maybe there is some kind of garbage collector?

Share this post


Link to post
Share on other sites

Local variables auto deconstruct at the end of a script.

Share this post


Link to post
Share on other sites

A basic garbage collector is automatically enabled, check the wiki about description.ext, there are some values you can change. However, for some missions a more advanced garbage collector is suggested.

Share this post


Link to post
Share on other sites

I have another doubts:

1) Are there in A3 short if:

if ? do_something : do_something_else

2) Is there overriding of functions?

3) When i do

for({_i = 0}, {_i<10}, {_i++}) do
{
    obj joinSilent createGroup east;
};

Is it means i create 10 times east group or is there some default east group where obj will be joint?

Share this post


Link to post
Share on other sites

1.

 

https://community.bistudio.com/wiki/if

https://community.bistudio.com/wiki/switch_do

 

2.

You can overwrite a function by assigning new code to the function name.

 

Example:

 

My_function = {hint "Hello World"};

My_function = {hintSilent "Hello World};

 

My_function would then return hintSilent "Hello World";

 

3.

I believe it would create 10 new groups. (Would need to test this myself)

Share this post


Link to post
Share on other sites

I have another doubts:

1) Are there in A3 short if:

if ? do_something : do_something_else
2) Is there overriding of functions?

3) When i do

for({_i = 0}, {_i<10}, {_i++}) do
{
    obj joinSilent createGroup east;
};
Is it means i create 10 times east group or is there some default east group where obj will be joint?

1. No tertiary operator in sqf closest is either

if ? then [{true},{false}]
or

[false,true] select ?
2.Sqf is not a OOP based language although through heavy macro use it can be made to operate similar.

Not quite sure what your after a function is just a variable, you would have to be more specific on what you want to achieve.

3.Yes that would create 10 groups on the east side. If nothing from a side is placed in the editor then yes a new group will need to be created before adding stuff to it.

Share this post


Link to post
Share on other sites
2.Sqf is not a OOP based language although through heavy macro use it can be made to operate similar.

Not quite sure what your after a function is just a variable, you would have to be more specific on what you want to achieve.

3.Yes that would create 10 groups on the east side. If nothing from a side is placed in the editor then yes a new group will need to be created before adding stuff to it.

 

 

2) I am just curious is it possible to call my own functions based on amount of parameters.

3) Is it resource consuming? I mean, generally i don't need specific group, i need just some side. Because of this i try to figure out a way to make simple universal script to switch quick side switching:

 

/*
 *	Set side of players.
 *
 *	@call
 *		[[u1, ...], side] execVM "setObjSide.sqf"
 *	@args
 *		[u1, ...]: [Object]		- whom side should be changed
 *		side: String			- abbreviation of which side should be choosen
 *	@return
 *		none
**/

_side = _this select 1;
{
	switch (_side) do
	{
		case "rn":
		{
			_x addRating -10000; 
			hint "ren";
		};
		case "ca":
		{
			_x setCaptive true; 
		};
		case "we":
		{
			[_x] joinSilent createGroup west;
		};
		case "ea":
		{
			[_x] joinSilent createGroup east;
		};
		case "ci":
		{
			[_x] joinSilent createGroup civilian;
		};
		case "re":
		{
			[_x] joinSilent createGroup resistance;
		};
	};
}forEach (_this select 0);

 

Maybe this isn't elegant solution, however this language isn't also sophisticated. I am not sure adding additional argument with group to add isn't a better solution . Because otherwise in a

large scale there can be many small unnecessary objects (groups).

 

 

 

I am not sure where should i look.

Share this post


Link to post
Share on other sites
/*
 *    Set side of players.
 *
 *    @call
 *        [[u1, ...], side] execVM "setObjSide.sqf"
 *    @args
 *        [u1, ...]: [Object]        - whom side should be changed
 *        side: String            - abbreviation of which side should be choosen
 *    @return
 *        none
**/

_unit = [_this select 0];
_side = _this select 1;

switch (_side) do
{
    case "rn":
    {
        _unit addRating -10000;
        hint "ren";
    };
    case "ca":
    {
        _unit setCaptive true;
    };
    case "we":
    {
        _unit joinSilent createGroup west;
    };
        case "ea":
    {
        _unit joinSilent createGroup east;
    };
    case "ci":
    {
        _unit joinSilent createGroup civilian;
    };
    case "re":
    {
        _unit joinSilent createGroup resistance;
    };
};
//delete all empty groups
{
if (count units _x == 0) then
    {
        deleteGroup _x;    
    };
} forEach allGroups;

 

I removed the forEach and added a bit of code which will delete all empty groups at the end.

 

 

I am not sure where should i look.

 

 

I did not really get your question to begin with, so I thought maybe the wiki pages will have what you  are looking for.

Share this post


Link to post
Share on other sites

Well...

forEach was there because array of units may be an argument (i mean main intention of this script is quick change players side in coop mission).

Honestly i don't understand purpose of removing of empty groups. My version of script doesn't generate empty ones (isn't it)?

I suppose this is just a general group cleaner, but why? Only reason i see is that after units death, this unit is removed from his group.

 

I forgot... can i run scripts during mission on server from console (I have no possibility to check it on my own).

Share this post


Link to post
Share on other sites

You can also do it like this, disadvantage would be that players of the same side would be in the same group, but since I do not know what type of mission you are building I can't judge whether that's the better approach or not. I also removed the setCaptive true bit, because that's basically the same as joining a civilian group.

 

/*
 *    Set side of players.
 *
 *    @call
 *        [[u1, ...], side] execVM "setObjSide.sqf"
 *    @args
 *        [u1, ...]: [Object]        - whom side should be changed
 *        side: String            - abbreviation of which side should be choosen
 *    @return
 *        none
**/

_units = _this select 0;
_side = _this select 1;
_groupWest = createGroup West;
_groupEast = createGroup East;
_groupIndependent = createGroup Independent;
_groupCivilian = createGroup Civilian;

{
    switch (_side) do
    {

        case "rn":
        {
            [_x] addRating -10000;
            hint "ren";
        };
        case "we":
        {
            [_x] joinSilent _groupWest;
        };
            case "ea":
        {
            [_x] joinSilent _groupEast;
        };
        case "ci":
        {
            [_x] joinSilent _groupCivilian;
        };
        case "re":
        {
            [_x] joinSilent _groupIndependent;
        };
    };
} forEach _units;
My version of script doesn't generate empty ones (isn't it)? I suppose this is just a general group cleaner, but why? Only reason i see is that after units death, this unit is removed from his group.

 

You were worried about unecessary groups, so I thought it would be a good start to get rid of all empty groups. If you use the code or not is of course up to you.

forEach was there because array of units may be an argument (i mean main intention of this script is quick change players side in coop mission).

That was my fault, I did not read your arguments at the top of the script.

Share this post


Link to post
Share on other sites

My intention is to make a PvE mission for up to 5 persons.

This will be mixture of MCC and Zeus with predefined enemy structures.

Accordingly to manual there is small differece between captive and civilian. As i understand there may be situation that civilians may be an enemy for some side. And captive is always ignored during firefight.

Because of this i've add this captive part.

About groups i just think about how many groups impact on performance. As i understand group is an Object (some kind) not just indexed collection. It means too many objects created just because i want to have more general code may be bad idea.

On the other side i have no experience what does it mean "too many objects" in A3. Is it 100 or 1K or 10K.

Anyway once again thank you for attention.

Share this post


Link to post
Share on other sites

There we go, the number of groups doesn't really have an impact on performance, especially in a mission with 5 players.

Also, don't worry to much about the amount of objects, in the end, you'll see for yourself how the mission runs and then you can take action to improve the performance if necessary e.g simulation manager module.

 

On the other side i have no experience what does it mean "too many objects" in A3. Is it 100 or 1K or 10K.

 

That's one of the major issues this game has, and it's the reason why there are so many complains about performance. However, BIS doesn't seem to care about this much, otherwise they would have added a proper guide into the game already, which shows people what to look after to get proper performance.

 

I didn't know about the difference between captive and cilvian, because the captive command put the player on civilian side. I did some quick research on that topic and it seems you were right, there seems to be a difference.

 

https://community.bistudio.com/wiki/Side_relations

Share this post


Link to post
Share on other sites

Dont worry too much about performance until you need to.

 

You might find you can build your scenario in half the time and performance will be great.

 

Sure is better than spending double the time for a tiny performance improvement.

 

Can always do a second pass once you're satisfied your scenario is fun and re-useable, to make things more performance-friendly and efficient. thats for later though.

 

first things first, get it fun and get it done

  • Like 2

Share this post


Link to post
Share on other sites

I have another question:

How to recieve Object of vehicle player is in?

I need to determine where player is when he will choose a menu action. Precisely if he is in a some vehicle, he will drop there his military stuff, but when he is outside he will put his stuff on the ground.

Or maybe such qualification is not necesary and there is general way of doing such thing?

 

I would like to ask once again if there is possibility to call scripts on server during mission from a console?

 

Also i've noticed that some scripts using checking "isServer". Why? What may go wrong with the script which works properly in the local editor?

 

PS. How to create "spoil" button on this forum for hiding long code?

Share this post


Link to post
Share on other sites
vehicle player

will return the vehicle of the player is in.

 

You can define

enableDebugConsole = 1;

in your descripton.ext, this will enable the debug console for the admin

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

 

 

The isServer check is important if want script to only on the server. A simple example would be as follows:

"SOMEVEHICLECLASSNAME" createVehicle _pos; //This will create a vehicle on the server AND for every client the script is executed one

If(isServer) then {"SOMEVEHICLECLASSNAME" createVehicle _pos;} //This will only create the vehicle ONCE

another example would be a change weather script. Since the weather is automatically synced to all clients, there is not need to execute the script on all clients.

 

All in all, there are tons of examples where it's necessary or recommended to execute a script only on the server.

Share this post


Link to post
Share on other sites

You can check whether a unit is in a vehicle, using this condition:

If (player != vehicle player) then {hint "player is in a vehicle"};

Some commands have global effect, so if you run them on every client + the server, it's effects will multiply.

Share this post


Link to post
Share on other sites

When i create a crate based on playes's position (getPosition player), this crate is spawned in some distance from the player (about 3 meters). I understand it is randomly snapped to some kind of mesh on the map.

However i would like to create this crate very close to the player (max 1 meter). Is such resolution is possible?

 

Is it possible to count how many units (players/vehicles/units) player has killed/destroyed?

Share this post


Link to post
Share on other sites
Is it possible to count how many units (players/vehicles/units) player has killed/destroyed?

 

This can be done with eventHandlers, there are other threads in this forum which discuss this question

 

When i create a crate based on playes's position (getPosition player), this crate is spawned in some distance from the player (about 3 meters). I understand it is randomly snapped to some kind of mesh on the map.

However i would like to create this crate very close to the player (max 1 meter). Is such resolution is possible?

 

 

https://community.bistudio.com/wiki/createVehicle

Look at the parameters "special" and "placement"

Share this post


Link to post
Share on other sites

Hello.

 

I have such piece of code:

// player side is WEST
_g = side player;
_box addAction ["title" {hint str ( side (_this select 3) ), [_g], 10, true, true, "text"];
// some other code
player joinSilent createGroup civilian;

After using action "title" on the _box, hint will show "CIV".

Why? Because _g is a reference to side of player?

How to copy value of such reference (i think about something what is called in Java deep copy)?

 

Other question:

Is it possible to lock a box? I think about some kind of personal box for specific player?

I've only foun some hints with manipulation of CfgActions however this is rather addonmakers job.

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

×