Jump to content
kromka

Access from init.sqf

Recommended Posts

It's showing CIV because that's the argument of your addaction (_g)

 

I don't know about java, but you can store such a value in a variable in a specific namespace and then access it from an other script

 

I think there was a recent thread about locking a box for specific player, just look around here.

 

Also, may you open a new thread for upcoming questions? This has nothing to do with "access from init.sqf" anymore.

Share this post


Link to post
Share on other sites

It's showing CIV because that's the argument of your addaction (_g)

 

I can't agree. _g is equal to "west". I double/triple/quadruple/... check it.

Also for tests i changed players side and _g is always current side, not side in the moment of passing argument to addAction.

Because of this i asked for reference.

I don't know if you are familiar with general programming. Reference is a pointer to a variable in memory not a value of this variable itself. Then when value changes, pointer still points on memory area and because of this you recieve actual value.

Share this post


Link to post
Share on other sites

Okay, I've tested your snippet myself and I have to ask you, did you test this code? It was full of errors, missing brackets, objects instead of array etc.

// player side is WEST
_g = side player;
_box addAction ["title" {hint str ( side (_this select 3) ), [_g], 10, true, true, "text"]; //_this select 3 selects the array, but not the actual variable, in addition, the side after hint str is obsolete, simply incorrect, since the value _g already has the old side of the player,
furthermore, there's a comma missing behinde "title" and a curly bracket behind ( side (_this select 3) )
// some other code
player joinSilent createGroup civilian; // join silent expects an array of units, not an object

The corrected script below, returns all values as expected:

// player side is WEST
_g = side player;  //side player returns west
_box addAction ["title" ,{hint str ((_this select 3) select 0)}, [_g], 10, true, true, "text"]; //_this select 3 only refered to the array [_g] itself, but was not selecting the actualy variable
// some other code
[player] joinSilent (createGroup civilian); //after this line, side player is civilian

Share this post


Link to post
Share on other sites

I've pasted it from my sqf and for simplicyty i slightly modified it "from the hand".

Indeed now i see i've missed some code. I'm sorry for inconvenience, hovewer it is quiet weard.

Anyway, with your modification code looks exactly how it should.

 

To clarify:

I've expected

{hint str ((_this select 3) select 0)}

will show WEST ( but it shows CIV).

Do you claim in your case WEST is the result of script?

Share this post


Link to post
Share on other sites

Yes I claim that it returns WEST.

 

Is perchance setCaptive enabled for your unit?

Share this post


Link to post
Share on other sites

Hmmm... now i am realy confused. I have to back home to my second computer and make additional tests.

I am pretty sure i didn't set unit as captive anywhere.

However thank you that you've confirmed this works as i expected on the beginning. I will try figure out what happen and will inform about conclusions.

 

-----

 

Ufff... i know what happen.

Unit which i test the script is a civilian.

 

Because i do changes of side using

joinSilent createGroup

 i changed the group of unit, not a side.

 

Proper check of side should be then

 side (group unit);

Share this post


Link to post
Share on other sites

Once again a problem...

I am close to finish my script however i really don't understand behaviour of "add" functions.

 

I have such stuff on soldier:

_x forceAddUniform "rhs_uniform_FROG01_m81";
	_x addBackpack "B_AssaultPack_rgr";
	_x addVest "V_TacVest_oli";
	_x addItemToUniform "FirstAidKit";
	for "_i" from 1 to 2 do {_x addItemToUniform "rhs_mag_30Rnd_556x45_Mk318_Stanag";};
	_x addItemToVest "FirstAidKit";
	for "_i" from 1 to 3 do {_x addItemToBackpack "rhs_mag_m67";};
	for "_i" from 1 to 2 do {_x addItemToUniform "rhsusf_mag_7x45acp_MHP";};
	for "_i" from 1 to 2 do {_x addItemToVest "rhs_mag_30Rnd_556x45_Mk318_Stanag";};
	_x addItemToVest "rhs_mag_m18_green";
	_x addItemToVest "rhs_mag_an_m8hc";
	_x addItemToBackpack "MineDetector";
	_x addItemToBackpack "FirstAidKit";
	_x addItemToBackpack "acc_flashlight";
	for "_i" from 1 to 5 do {_x addItemToBackpack "rhs_mag_30Rnd_556x45_Mk318_Stanag";};
	_x addItemToBackpack "DemoCharge_Remote_Mag";
	_x addHeadgear "rhs_Booniehat_m81";

 

I save it to the box:

 {
_itemList = [];
	_itemList pushBack backpack _x;
	{ _itemList pushBack _x } forEach backpackItems _x;
	{ _itemList pushBack _x } forEach backpackItems _x;
	_itemList pushBack vest _x;
	{ _itemList pushBack _x } forEach vestItems _x;
	_itemList pushBack uniform _x;
	{ _itemList pushBack _x } forEach uniformItems _x;
	_itemList pushBack primaryWeapon _x;
	{ _itemList pushBack _x } forEach primaryWeaponItems _x;
	{ _itemList pushBack _x } forEach primaryWeaponMagazine _x;
	_itemList pushBack secondaryWeapon _x;
	{ _itemList pushBack _x } forEach secondaryWeaponItems _x;
	{ _itemList pushBack _x } forEach secondaryWeaponMagazine _x;
	_itemList pushBack handgunWeapon _x;
	_itemList pushBack headgear _x;
	_itemList pushBack goggles _x;
	_itemList pushBack hmd _x;
	_itemList pushBack binocular _x;
	
	// create container for players stuff
    _box = createVehicle["Box_IND_Support_F", position _x, [], 1, "CAN_COLLIDE"];
	_box allowDamage false;
	_box addAction ["<t color=""#00FFFF"">EXPOSE", _backToPreviousRole, [side (group _x), _itemList], 10, true, true];
	clearItemCargo _box;
	clearWeaponCargo _box;
	clearMagazineCargo _box;
    
 	// fill container with player's stuff
	{
		_box addItemCargo [_x, 1];
	} forEach _itemList;
	if(backpack _x != "") then
	{	
		_box addBackpackCargo [(backpack _x), 1];
	};
} forEach _who;

 

And this stuff is there. I can see it.

 

However function:

backToPreviousRole =
{   
    // [target, caller, ID, arguments]
    private ["_box", "_caller", "_id", "_args"];
    _box = _this select 0;
    _soldier = _this select 1;
    _args = _this select 3;
    
    {
        _soldier addWeapon _x;
    } forEach (getWeaponCargo _box select 0);
    {
        _soldier addBackpack _x;
        _soldier addUniform _x;
        _soldier addVest _x;
        _soldier addHeadgear _x;
        _soldier addWeapon _x;
        _soldier addPrimaryWeaponItem _x;
        _soldier addSecondaryWeaponItem _x;
    } forEach (getItemCargo _box select 0);
};

 

adds properly weapons, some items, and uniform. No backpack, vest or helmet. I've checked and those items are processed, hovewer it seems "addVest" or "addHeadgear" ignore them.

Why?

Share this post


Link to post
Share on other sites

It depends on the locality of the arguments and effect. The effect of most commands is global, which mean everyone sees the effect even if it wasn't executed on his machine, however, the arguments need to be local for some commands, means, they have to be executed where the unit is local.

 

I highly recommend you to read this BLOG from KK. He did an awesome job of explaining.

Share this post


Link to post
Share on other sites

R3vo thank you for your attention in this topic. Below you will find result of your advices.

This script switches player's (or players) side to civilian, creates "closed" ammo box (only specific player can use it) and after using it switches back the player to original side with original equipment.

 

Path to scripts should be "scripts\..."

 

It is probably quiet buggy because i tested it only in single with standard infrantry man.

 

I also solved problem with adding any reloaded weapons to unit (with using fake backpack). Not elegant but i can't figured out nothing better.

 

/**
 *	Changes players clothes, equipment and side to civilian with an ability to turn back.
 *	
 *	@author 
 *		Czarny
 *	@call
 *		[[who]] execVM "setRoleCivilian.sqf"
 *	@args
 *		who: [Object] 		- who should become a civilian
 *	@return
 *		none
 *	@dependencies
 *		setObjSide.sqf
**/


private ["_who", "_veh", "_itemList", "_box", "_clothesPool", "_itemList"];
_who = _this select 0;
_itemList = [];

_backToPreviousRole = 
{   
	// [target, caller, ID, arguments]
	private ["_box", "_soldier", "_args"];
	_box = ((_this select 3) select 1);
	_soldier = _this select 1;
	_args = _this select 3;
		
	// add stuff back to soldier
	_soldier addUniform ((_box select 0) select 0);
	_soldier addVest ((_box select 0) select 1);
	
	// proper distribution of ammo between weapons (includes previous amount of ammo in clips)
	_soldier addBackpack ("B_AssaultPack_Base");	// fake backpack
	{
		_soldier addItemToBackpack (_x select 0);
	} forEach (_box select 7);

	for[{_i = 3},{_i < 6},{_i = _i + 1}] do
	{
		_soldier addWeapon ((_box select 0) select _i);
	};
	_soldier setAmmo [primaryWeapon _soldier, (_box select 8) select 0];
	_soldier setAmmo [secondaryWeapon _soldier, (_box select 8) select 1];
	_soldier setAmmo [handgunWeapon _soldier, (_box select 8) select 2];
	removeBackpack _soldier;
	
	for[{_i = 6},{_i < count (_box select 0)},{_i = _i + 1}] do
	{
		_soldier addWeapon ((_box select 0) select _i);
	};

	_soldier addBackpack ((_box select 0) select 2);	//proper backpack

	{
		_soldier addItemToBackpack _x;
	} forEach (_box select 1);

	{
		_soldier addItemToVest _x;
	} forEach (_box select 2);

	{
		_soldier addItemToUniform _x;
	} forEach (_box select 3);

	{
		_soldier addPrimaryWeaponItem _x;
	} forEach (_box select 4);
	{
		_soldier addSecondaryWeaponItem _x;
	} forEach (_box select 5);

	{
		_soldier addHandGunItem _x;
	} forEach (_box select 6);
	
	// change side
	[[_soldier], _args select 0] call czarny_fnc_setObjSide;
	
	// remove the box
	(_this select 0) removeAction (_this select 2);
	deleteVehicle (_this select 0);
};


// Change the side and equipment of the player.
scopeName "break";
{
	if(!local _x) then
	{
		breakTo "break";
	};
	
	// switching sides in vehicle is forbidden
	if(vehicle _x != _x) exitWith
	{
		if(local _x) then
	    {
	        [5, "You can't be in vehicle!"] spawn czarny_fnc_showTimeHint;
	    };
	};
    
    // don't change queue!!!
	_itemList pushBack [];
	(_itemList select 0) pushBack uniform _x;
	(_itemList select 0) pushBack vest _x;
	(_itemList select 0) pushBack backpack _x;
	(_itemList select 0) pushBack primaryWeapon _x;
	(_itemList select 0) pushBack secondaryWeapon _x;
	(_itemList select 0) pushBack handgunWeapon _x;
	(_itemList select 0) pushBack headgear _x;
	(_itemList select 0) pushBack goggles _x;
	(_itemList select 0) pushBack hmd _x;
	(_itemList select 0) pushBack binocular _x;
	_itemList pushBack [];
	{(_itemList select 1) pushBack _x} forEach backpackItems _x;
	_itemList pushBack [];
	{(_itemList select 2) pushBack _x} forEach vestItems _x;
	_itemList pushBack [];
	{(_itemList select 3) pushBack _x} forEach uniformItems _x;
	_itemList pushBack [];
	{(_itemList select 4) pushBack _x} forEach primaryWeaponItems _x;
	_itemList pushBack [];
	{(_itemList select 5) pushBack _x} forEach secondaryWeaponItems _x;
	_itemList pushBack [];
	{(_itemList select 6) pushBack _x} forEach handGunItems _x;
	_itemList pushBack [primaryWeaponMagazine _x, secondaryWeaponMagazine _x, handgunMagazine _x];				// stupid but it is realy needed
	_itemList pushBack [_x ammo (primaryWeapon _x), _x ammo (secondaryWeapon _x), _x ammo (handgunWeapon _x)];
	
	// clear player's previous equipment
	removeAllWeapons _x;
	removeBackpack _x;
	removeHeadgear _x;
	_x unassignItem hmd _x;
	removeGoggles _x;
	removeVest _x;
	
	// create container for players stuff
    _box = createVehicle["Box_IND_Support_F", position _x, [], 1, "CAN_COLLIDE"];
	_box allowDamage false;
	_box addAction ["<t color=""#00FFFF"">EXPOSE", _backToPreviousRole, [side (group _x), _itemList], 10, true, true];
    _box addEventHandler ["ContainerOpened",  {[_x, true] spawn czarny_fnc_disableObjInventory}];
	clearItemCargo _box;
	clearWeaponCargo _box;
	clearMagazineCargo _box;
    
 	/* uncomment it if you want to check if everything is in the box */
	// {
		// _box addItemCargo [_x, 1];
	// } forEach _itemList;
	// if(backpack _x != "") then
	// {	
		// _box addBackpackCargo [(backpack _x), 1];
	// };
    
	// change player to civilian
	_clothesPool = ["U_C_Poor_1", "U_OG_Guerilla2_1", "U_OG_Guerilla3_1", "U_OG_Guerilla3_2", "U_BG_Guerilla2_2", "U_BG_Guerilla2_1","U_IG_Guerilla2_2"];
	_x forceAddUniform (_clothesPool select floor random count _clothesPool);
   [[_x],  "civ"] call czarny_fnc_setObjSide;
   
} forEach _who;

 

Here is additional script which is used.

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

private["_who", "_side"];

_who = _this select 0;
_side = _this select 1;

scopeName "break";
{
	if(!local _x) then 
	{
		breakTo "break";
	};
	
	switch (_side) do
	{
		case "enemy":
		{
			_x addRating -10000; 
		};
		case "cap":
		{
			_x setCaptive true; 
		};
		case "west":
		{
            [_x] joinSilent createGroup west;
		};
		case "east":
		{
			[_x] joinSilent createGroup east;
		};
		case "civ":
		{
            [_x] joinSilent createGroup civilian;
		};
        case "guer":
		{
			[_x] joinSilent createGroup resistance;
		};
	};
} forEach _who;

Share this post


Link to post
Share on other sites

I'm glad I could help.

I also solved problem with adding any reloaded weapons to unit (with using fake backpack). Not elegant but i can't figured out nothing better.

What do you mean by that?

Share this post


Link to post
Share on other sites

 

What do you mean by that?

 

I looked for a way of adding reloaded weapon to the player.

Every plot i found said that magazine to this weapon should be added first. But nobody said wat to do with ammo to launchers that AFAIK are too big to uniform. Then i simply add fake backpack to unit, add proper ammo to it, reload weapons with ammmo and remove backpack.

By the way it is quiet weard BI doesn't provide ability of adding reloaded weapon.

Generally after writing this script i see that there is too many things that must be done by workaround instead of stright coding.

Additionally all those "then" after "if", "do" after "for". This is little bit rusty if you know what i mean.

Share this post


Link to post
Share on other sites

Well, for me, that's the actual fun of scripting, findin' workarounds and such. It would be boring if everything was straight forward, wouldn't it ? ;)

Share this post


Link to post
Share on other sites

After some time i have another philosophical question.

 

There, may be couple of players (MP mission).

I have a trigger with area 100x100.

I would like to set it in this way when player enters the area - action is added (addAction), but when player leaves the area, this action is removed (removeAction).

Additionally when any of players will do this action when it is enabled, the action should be removed from every players menu.

 

In the real world: there is an alarm bell, but only one person can start evacuation with ringing. All other ringings are pointless.

 

Currently i have such code:

{
	if([alarmBell, _x] call BIS_fnc_inTrigger) then 
	{
		_x addAction ["<t color=""#00FFFF"">make an alarm", 
		{	
			{
				removeAllActions _x;
			}forEach playableUnits;
			{
				if([syrtaArea, _x] call BIS_fnc_inTrigger && _x side == civ) then 
				{
					_x  doMove [getPos evacZone select 0, getPos evacZone select 1];
				};
			}forEach allUnits;
		}, 
		nil, 10, true, true];
	};
}forEach playableUnits;

 

but it is easy to notice i can only remove all actions from each player - not this specific which i would like to.

Besides i don't know how remoe specific action when player will leave the area.

Regards.

Share this post


Link to post
Share on other sites

I've never understood the need to add and remove, when it's so much easier to use the condition parameter of the addaction.

Share this post


Link to post
Share on other sites

addAction ["Alarm",fnc_alarm,[],7,true,true,"","[alarmBell, player] call BIS_fnc_inTrigger"];

 

That way you dont need to add and remove the action every time player goes in and out of the trigger area.

Share this post


Link to post
Share on other sites

Shuko, this adds propely action, hovewer it doesn't remove it when player leave area of the trigger.

If player come back, it adds the same action once again.

 

I use this code:

 

evacuationStarted is a public variable,

alarmBell and syrtaArea are triggers

{   
    _x addAction ["<t color=""#FFFF00"">ring for alarm",
    {      
        evacuationStarted = true;
        (_this select 1) removeAction (_this select 2);
        {       
            if(([syrtaArea, _x] call BIS_fnc_inTrigger) && (side _x == civilian)) then       
            {        
                _x doMove [getPos evacZone select 0, getPos evacZone select 1];      
            };     
        }forEach allUnits;    
    }, [], 7, false, true, "([alarmBell, _x] call BIS_fnc_inTrigger) && (!evacuationStarted)"];
}forEach players;

This condition affects every time, because of this i asked earlier about removal.

Additionally i asked also about action removal in each players menu without knowing ID and only with knowledge about name, because i need to remove all the same actions.

I also don't understand why "evacuationStarted" is always false, even script will proceed properly.

Share this post


Link to post
Share on other sites

Solution:

 

description.ext

class CfgFunctions
{
    class myCode
    {
        class myCode

       {
            class actionEvac {file = "scripts_specific\actionEvac.sqf";};
        };
    };
};

init.sqf:

evacuationStarted = false;
evacActionList = [];
[] spawn myCode_fnc_actionEvac;

scripts_specific\actionEvac.sqf

while{!evacuationStarted} do
{
    {
        if((_x in list alarmBell) && !(_x in evacActionList)) then
        {
            evacActionList append
            [_x addAction ["<t color=""#FFFF00"">ring for alarm",
                {      
                    evacuationStarted = true;
                    alarmBell enableSimulation false;
                    for [{_i = 1}, {_i < (count evacActionList)}, {_i = _i + 2}] do
                    {
                        (evacActionList select _i) removeAction (evacActionList select (_i - 1));
                    };
                    evacActionList = [];

                    /* do something */  

                }, [], 7, true, true]];
            evacActionList append [_x];
        };
        if(!(_x in list alarmBell) && (_x in evacActionList)) then
        {    
            _index = evacActionList find _x;
            if(_index > -1) then
            {
                (evacActionList select _index) removeAction (evacActionList select (_index - 1));
                evacActionList = evacActionList  - [evacActionList select (_index - 1), evacActionList select _index];
            };
            
        };
    } forEach players;
    sleep 1;
};

alarmBell is my trigger with some area (repeatable, present, players are independent then trigger is independent)

 

This allows you in MP adds action to specific player if he is in the area of trigger and remove if he is outside.

In this case when player is in trigger area, he can ring a bell and start evac.

Share this post


Link to post
Share on other sites

Shuko, this adds propely action, hovewer it doesn't remove it when player leave area of the trigger.

If player come back, it adds the same action once again.

 

I know you already found a solution. However, you didn't quite use the condition the way I meant.

 

Below's how I would have done it. If you want to be clean and/or worry about performance, you can save the action ID to the player with setVariable and then remove the action after the alarm is fired with getVariable + removeAction.

 

init.sqf

if (isNil "evacuationStarted") then {evacuationStarted = false};

[] spawn {
  waituntil {evacuationStarted};
  // do something when alarm is fired
  hint "run baby run!";
};

initPlayerLocal.sqf

fnc_alarm = {
  evacuationStarted = true;
  publicVariable "evacuationStarted";
};

player addAction ["Alarm",fnc_alarm,[],7,true,true,"","[trg1, player] call BIS_fnc_inTrigger && !evacuationStarted"];

Share this post


Link to post
Share on other sites

Shuko,

I asked about piece of script that adds position to specific players menu when this player is near something, and remove this position when player is far. Additionally which remove all posititons from all players menus when action is done.

As i understand you focused on adding an action and i rather tried to gather info mainly about removing of action.

Bay the way, I've updated code (post #45) and now it works precisely as i've described above.

 

Can you explain to me why you used this one?

 

 

if (isNil "evacuationStarted") then {evacuationStarted = false};

 

Isn't this "if" will be always true because it is checked in init.sqf

Share this post


Link to post
Share on other sites

Shuko,

I asked about piece of script that adds position to specific players menu when this player is near something, and remove this position when player is far. Additionally which remove all posititons from all players menus when action is done.

As i understand you focused on adding an action and i rather tried to gather info mainly about removing of action.

Bay the way, I've updated code (post #45) and now it works precisely as i've described above.

 

Can you explain to me why you used this one?

 

 

Isn't this "if" will be always true because it is checked in init.sqf

 

The code above does both, add and remove the action from all players. Well, technically it doesn't remove it, but just hides it. That's the beauty of the condition parameter, you can easily show and hide an action.

 

example mission

 

That IF in init.sqf is to initialize the variable which is used in the condition. It's put inside an IF just incase JIP joins after the alarm is fired.

Share this post


Link to post
Share on other sites

Now i am confused.

It works (and code is much simpler than my), but i don't understand how.

Is this means when addAction condition isn't fulfilled action is hidden somhow?

You know... i don't see where is this hiding. Is this condition checked each frame or something?

--------------
Here is the key:

NOTE: condition is evaluated on each frame in non-scheduled environment. If action is added to some object and not to player, condition will only get evaluated IF player is closer than 15m to the object AND is looking at the object. If action is added to player, the condition is evaluated all the time.

Now i understand everything.

Share this post


Link to post
Share on other sites

I have another question.

I have group of civilians and two empty cars.

I try to mount them into vehicles sending them to te trigger "evacZone"

[] spawn {
	waituntil {evacuationStarted};
	_leader = syrtaCivils select 0;
	syrtaEvacVehs joinSilent group _leader;
	syrtaCivils joinSilent group _leader;
	{
		_x doMove [getPos evacZone select 0, getPos evacZone select 1]; 
	} forEach units group _leader;
        hint format["%1", count (units _leaderGroup)];
};

Hovewer hint shows zero. Why?

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

×