Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add actions to main class #2576

Closed
Giallustio opened this issue Sep 23, 2015 · 28 comments
Closed

Can't add actions to main class #2576

Giallustio opened this issue Sep 23, 2015 · 28 comments
Assignees

Comments

@Giallustio
Copy link
Contributor

It seems that i can not attach an action to a main class, like LandVehicle, the same action works for a defined class:

_action = ["Logistic","Logistic","",{hint "CIAO"},{true}] call ace_interact_menu_fnc_createAction; ["LandVehicle", 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToClass;

//////////////////////////////////////////////////////////////////////////

_action = ["Logistic","Logistic","",{hint "CIAO"},{true}] call ace_interact_menu_fnc_createAction; ["B_Truck_01_transport_F", 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToClass;

@commy2
Copy link
Contributor

commy2 commented Sep 23, 2015

Try it with Car, Tank, Helicopter, Plane and Ship_F.

@Giallustio
Copy link
Contributor Author

Same result

@commy2
Copy link
Contributor

commy2 commented Sep 23, 2015

Oh yes. Checked the code and createAction is not meant to work with base classes.

@Giallustio
Copy link
Contributor Author

Could it be changed?

@commy2
Copy link
Contributor

commy2 commented Sep 23, 2015

Not that easily. But you really don't need it on base classes. Here is how we do it:

class Extended_InitPost_EventHandlers {
class StaticWeapon {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
};
};

_type = typeOf _vehicle;

You just have to make sure that the action is only added to each vehicle type once if you place multiple copies of one type:

// do nothing if the class is already initialized
if (_type in _initializedClasses) exitWith {};
// set class as initialized
_initializedClasses pushBack _type;
SETMVAR(GVAR(initializedClasses),_initializedClasses);

If this is for a mission, then you can simply put the Extended_InitPost_Eventhandler into the description.ext.

@commy2 commy2 self-assigned this Sep 23, 2015
@Giallustio
Copy link
Contributor Author

I'm gonna check it later, ty commy!

Side question, in this way i can add an action to every object and to every class. What's the best option for performance? I don't know how the action system work, so i can't judge

@commy2
Copy link
Contributor

commy2 commented Sep 23, 2015

It should make no noticable difference.

@PabstMirror
Copy link
Contributor

It's minor, but I think it's slightly faster to add to class.

Plus you have less total variables on each object

@Giallustio
Copy link
Contributor Author

Thank you guys, it works perfectly now!

@commy2
Copy link
Contributor

commy2 commented Sep 23, 2015

yay

@commy2 commy2 closed this as completed Sep 23, 2015
@Giallustio
Copy link
Contributor Author

Sorry Commy to bring it up again, but i've a problem with your solution.

It works perfectly in SP editor, but not in MP.

class Extended_InitPost_EventHandlers {
    class Man {
        class ADDON {
            init = "_this call btc_fnc_eh_unit_init";
        };
    };
};

btc_fnc_eh_unit_init:

private ["_unit"];

_unit = _this select 0;

switch true do {
    case (side _unit == btc_enemy_side) : {
        private ["_type", "_action"];
        if (isServer) then {_unit call btc_fnc_mil_unit_create;};
        _type = typeOf _unit;
        if (isNil "btc_actions_units") then {btc_actions_units = [];};
        if !(_type in btc_actions_units) then {
            btc_actions_units pushBack _type;
            _action = ["Search_intel", "Search for intel", "", {(_this select 0) spawn btc_fnc_info_search_for_intel;}, {!Alive (_this select 0)}] call ace_interact_menu_fnc_createAction;
            [_type, 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToClass;
        };
    };
};

@PabstMirror
Copy link
Contributor

When is btc_enemy_side defined?

init.sqf runs at different times in SP and MP

@Giallustio
Copy link
Contributor Author

call compile preprocessFile "core\def\mission.sqf";

called by init.sqf

All the units are spawned during the game

@PabstMirror
Copy link
Contributor

class Extended_PreInit_EventHandlers {
    class yourmission {
        init = 'call compile preprocessFile "core\def\mission.sqf";';
    };
};

@jokoho48
Copy link
Member

jokoho48 commented Nov 9, 2015

i think you need to use this

class Extended_Init_Eventhandlers {
    class CAManBase {
        class yourmission_init {
            init = "call compile preprocessFile 'core\def\mission.sqf'";
        };
    };
};

@Giallustio
Copy link
Contributor Author

nope, i've tried to define it inside the same fnc and it's not working

private ["_unit"];

_unit = _this select 0;
btc_enemy_side = east;
switch true do {
    case (side _unit == btc_enemy_side) : {

@Giallustio
Copy link
Contributor Author

*not working

@Giallustio
Copy link
Contributor Author

Few more tests:

btc_enemy_side is initialized correctly.

type has been added to btc_actions_units.

if i spawn a sleep the action will be added correctly:

                _unit spawn {
                    sleep 1;
                    _action = ["Search_intel", "Search for intel", "", {(_this select 0) spawn btc_fnc_info_search_for_intel;}, {!Alive (_this select 0)}] call ace_interact_menu_fnc_createAction;
                    [(typeOf _this), 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToClass;

But sometime the action is not added even if the type has been added to the main array.

I tried to check the actions of the class and this is the result:

20:06:44 "[["ACE_MainActions","Interactions","\a3\ui_f\data\IGUI\Cfg\Actions\eject_ca.paa",{},{true},{},[],{_target selectionPosition 'pelvis'},4,[false,false,false,false,false],{}],[[["ACE_TeamManagement","Team Management","\z\ace\addons\interaction\UI\team\team_management_ca.paa",{},{[_player, _target] call ace_interaction_fnc_canJoinTeam && {ace_interaction_EnableTeamManagement} && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},0,[false,false,false,false,false],{}],[[["ACE_AssignTeamRed","Assign Red","\z\ace\addons\interaction\UI\team\team_red_ca.paa",{[_target, 'RED'] call ace_interaction_fnc_joinTeam},{[_player, _target] call ace_interaction_fnc_canJoinTeam && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},0,[true,false,false,false,false],{}],[]],[["ACE_AssignTeamGreen","Assign Green","\z\ace\addons\interaction\UI\team\team_green_ca.paa",{[_target, 'GREEN'] call ace_interaction_fnc_joinTeam},{[_player, _target] call ace_interaction_fnc_can
20:06:45 "[["ACE_Torso","Torso","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  1] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'spine3'},1.75,[false,false,false,true,false],{[_target, _player, 1, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'body',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'body',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,true,false,false,false],{}],[]],[["PlaceInBodyBag","Place body in bodybag","",{[_player,  _target,  'body',  'BodyBag'] call ace_medical_fnc_treatment},{[_player,  _target,  'body',  'BodyBag'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} }
20:06:45 "[["ACE_Head","Head","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  0] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'pilot'},1.75,[false,false,false,true,false],{[_target, _player, 0, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'head',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'head',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,false,false,false,false],{}],[]],[["FieldDressing","Field Dressing","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'head',  'FieldDressing'] call ace_medical_fnc_treatment},{[_player,  _target,  'head',  'FieldDressing'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,
20:06:45 "[["ACE_ArmLeft","Left Arm","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  2] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'LeftForeArm'},1.75,[false,false,false,true,false],{[_target, _player, 2, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'hand_l',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'hand_l',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,false,false,false,false],{}],[]],[["FieldDressing","Field Dressing","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'hand_l',  'FieldDressing'] call ace_medical_fnc_treatment},{[_player,  _target,  'hand_l',  'FieldDressing'] call ace_medical_fnc_canTreatCached && {[
20:06:45 "[["ACE_ArmRight","Right Arm","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  3] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'RightForeArm'},1.75,[false,false,false,true,false],{[_target, _player, 3, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'hand_r',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'hand_r',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,false,false,false,false],{}],[]],[["FieldDressing","Field Dressing","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'hand_r',  'FieldDressing'] call ace_medical_fnc_treatment},{[_player,  _target,  'hand_r',  'FieldDressing'] call ace_medical_fnc_canTreatCached &&
20:06:45 "[["ACE_LegLeft","Left Leg","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  4] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'LKnee'},1.75,[false,false,false,true,false],{[_target, _player, 4, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'leg_l',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'leg_l',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,false,false,false,false],{}],[]],[["FieldDressing","Field Dressing","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'leg_l',  'FieldDressing'] call ace_medical_fnc_treatment},{[_player,  _target,  'leg_l',  'FieldDressing'] call ace_medical_fnc_canTreatCached && {[ACE_player
20:06:45 "[["ACE_LegRight","Right Leg","\z\ace\addons\medical\UI\icons\medical_cross.paa",{[_target,  true,  5] call ace_medical_fnc_displayPatientInformation},{ace_medical_menuTypeStyle == 0 && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'RKnee'},1.75,[false,false,false,true,false],{[_target, _player, 5, _this select 3] call ace_medical_fnc_modifyMedicalAction}],[[["Bandage","Bandage","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'leg_r',  'Bandage'] call ace_medical_fnc_treatment},{[_player,  _target,  'leg_r',  'Bandage'] call ace_medical_fnc_canTreatCached && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[true,false,false,false,false],{}],[]],[["FieldDressing","Field Dressing","\z\ace\addons\medical\UI\icons\bandage.paa",{[_player,  _target,  'leg_r',  'FieldDressing'] call ace_medical_fnc_treatment},{[_player,  _target,  'leg_r',  'FieldDressing'] call ace_medical_fnc_canTreatCached && {[ACE_play
20:06:45 "[["ACE_Weapon","Weapon","",{},{true && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{call ace_interaction_fnc_getWeaponPos},1.5,[false,false,false,false,false],{}],[[["ace_reload_LinkBelt","Link belt","",{[_player,  _target] call ace_reload_fnc_startLinkingBelt},{[_player,  _target] call ace_reload_fnc_canLinkBelt && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[false,false,false,false,false],{}],[]],[["ace_reload_CheckAmmo","Check Ammo","",{[_player,  _target] call ace_reload_fnc_checkAmmo},{[_player,  _target] call ace_reload_fnc_canCheckAmmo && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0]},2,[false,false,false,false,false],{}],[]],[["ace_rangecard_copyRangeCard","Copy Range Card","\z\ace\addons\rangecard\UI\RangeCard_Icon.paa",{_target call ace_rangecard_fnc_updateClassNames},{_target call ace_rangecard_fnc_canCopy && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{[0,0,0
20:06:45 "[["ACE_TapShoulderRight","Tap Shoulder","",{[_player,  _target,  0] call ace_interaction_fnc_tapShoulder},{[_player,  _target] call ace_interaction_fnc_canTapShoulder && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'rightshoulder'},2,[false,false,false,false,false],{}],[]]"
20:06:45 "[["ACE_TapShoulderLeft","Tap Shoulder","",{[_player,  _target,  1] call ace_interaction_fnc_tapShoulder},{[_player,  _target] call ace_interaction_fnc_canTapShoulder && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'leftshoulder'},2,[false,false,false,false,false],{}],[]]"
20:06:45 "[["ace_reloadlaunchers_ReloadLauncher","Load launcher","",{},{true && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{_this call ace_reloadlaunchers_fnc_addMissileReloadActions},[],{_target selectionPosition 'launcher'},4,[false,false,false,false,false],{}],[]]"
20:06:45 "[["ACE_ApplyHandcuffs","Take Prisoner","\z\ace\addons\captives\UI\handcuff_ca.paa",{[_player,  _target] call ace_captives_fnc_doApplyHandcuffs},{[_player,  _target] call ace_captives_fnc_canApplyHandcuffs && {[ACE_player,  _target,  []] call ace_common_fnc_canInteractWith} },{},[],{_target selectionPosition 'righthand'},2,[false,false,false,false,false],{}],[]]"
20:06:45 "[["ace_dragging_drop","Release","",{[_player, _target] call ace_dragging_fnc_dropObject},{[_player, _target] call ace_dragging_fnc_canDrop},{},[],{[0, 0, 0]},2,[false,false,false,false,false],{}],[]]"

The class was O_G_Soldier_F

@PabstMirror
Copy link
Contributor

Description.ext:

//This defines the function:
class Extended_PreInit_EventHandlers {
    class yourPreInitToDefineFunc {
        init = "btc_fnc_eh_unit_init = compile preProcessFileLineNumbers 'btc_fnc_eh_unit_init.sqf';";
    };
};

//This runs func at initPost:
class Extended_InitPost_EventHandlers {
    class CAManBase {
        class addMyAction {
            init = "_this call btc_fnc_eh_unit_init";
        };
    };
};

btc_fnc_eh_unit_init.sqf:

private ["_unit"];

_unit = _this select 0;

diag_log text format ["running unit init on [%1]-[%2]", _unit, typeOf _unit];

_type = typeOf _unit;
if (isNil "btc_actions_units") then {btc_actions_units = [];};

if !(_type in btc_actions_units) then {
    btc_actions_units pushBack _type;

    _action = ["Search_intel", "Search for intel on dead guy", "", {systemChat "searching..."}, {!alive _target}] call ace_interact_menu_fnc_createAction;
    [_type, 0, ["ACE_MainActions"], _action] call ace_interact_menu_fnc_addActionToClass;
};

This works in SP and MP

@jokoho48
Copy link
Member

@PabstMirror
class Extended_InitPost_EventHandlers { class CAManBase { class addMyAction { init = "_this call btc_fnc_eh_unit_init"; }; }; };

dont work you must use Extended_Init_EventHandlers

@Giallustio
Copy link
Contributor Author

still not working for me.
If you want to take a look:

Giallustio/HeartsAndMinds@ab5e675

@jokoho48
Copy link
Member

https://github.com/jokoho48/AWPublicMission/blob/DCGAW/data/SEN_XEH.hpp#L9-L15
this are the right config entry for this

@jokoho48 jokoho48 reopened this Nov 11, 2015
@Giallustio
Copy link
Contributor Author

It fails on some units class and i can't reproduce the error. I'm gonna change approach

@jokoho48
Copy link
Member

the unit classes where it fail are not compatible with CBA XEH than you must contact the author of the mod and say him to fix this

@Giallustio
Copy link
Contributor Author

Arma vanilla units. Guerilla opfor faction.
The code runs because the class is in the array, but the action won't show up on some units. I checked all the variables of missionnamespace and the action is not there for those units.

Units spawned with zeus are fine tho (CSAT)

@jokoho48
Copy link
Member

did you load RHS?

@Giallustio
Copy link
Contributor Author

yep! CBA, ACE, RHS

@jokoho48
Copy link
Member

then try it without RHS because RHS break CBA XEH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants