Jump to content
Touhou

ACE3 EventHandler

Recommended Posts

Hi everyone !

 

I recently use ACE3 for the first time and I fall in love with it,

 

but I don't understand how to use his Events Framework.

 

I try to add an event like : If player load  a body bag in cargo  then the objetive is done.

 

I found this but don't know how to use it to make it work properly : 

 

Event : ace_addCargo     [_item (CLASSNAME or OBJECT), _vehicle, _cargoCount]    

 

Add Event : ["Event name", Code block, Event ID] call CBA_fnc_addEventHandler;

 

so, if someone understand it and know how to do it, it will be sooooo good if you can explain me how to turn it into something that work. :D

Share this post


Link to post
Share on other sites

The eventhandler runs the function that you provide it with.

 

Here this should work for what you mentioned in your other post:

["ace_cargoLoaded", myfnc_load_special] call CBA_fnc_addEventHandler;
["ace_cargoUnloaded", myfnc_unload_special] call CBA_fnc_addEventHandler;

myfnc_load_special = {
	params ["_item","_vehicle"];
	local ["_special"];
	_special = _item getVariable ["special",""];
	if (_special isEqualTo "") exitWith {};
	_vehicle setVariable [format["%1_special",typeOf _item], _special, true];
};

myfnc_unload_special = {
	params ["_item","_vehicle"];
	local ["_special"];
	_special = _vehicle getVariable [format["%1_special", typeOf _item], ""];
	if (_special isEqualTo "") exitWith {};
	_item setVariable ["special", _special, true];
	_vehicle setVariable [format["%1_special",typeOf _item], nil, true];
};

 

This basically makes it so you can have a variable (named "special") set on an object that you load into cargo and that variable will be restored upon unloading it.

Way I wrote it, you can store several "special" objects in a vehicle as long as they have different classnames.

 

 

mybodybag setVariable ["special", "mrX", true];

 

the above also means that you can retrieve the variable directly from the vehicle as long as the cargo is in it by accessing the "classnameoftheobject_special" Variable.

 

 

 

 

 

 

ps.: not sure if _item for the cargoLoaded eventhandler is an actual object pointer or just a classname. The latter would make things a bit more complicated...

Share this post


Link to post
Share on other sites

So, if I understand...

 

Whan I load the body bag (that has none variable cause he's created ingame) into the helico, the body bag get the variable "special" ? And when I unload it, he always get the variable "special", so I can check if special exist ?

 

Thanks a lot men for your help and your time, I'm not too good at scripting.

Share this post


Link to post
Share on other sites

Hmm you'll actually have to assign it the "special" variable first.

 

The script (if it works) just makes sure that the variable is saved and reassigned when you put it into cargo.

 

ps.: I just did a search on the matter on found this ticket:

https://github.com/acemod/ACE3/issues/3021

 

Sounds like they already have some sort of mechanic for it?

Share this post


Link to post
Share on other sites

Okay but I dont know how to assign the variable "special" to the body bag ingame, I only know the classname that is "ACE_bodyBagObject"... :/

 

If I follow your script, are you able to make the same for the Target who was killed ?

 

I found this eventhandler

 

ace_placedInBodyBag  [_target, _bodyBag]

 

so the target name is for exemple "Target_one".

 

And are you able to explain me how to activate a trigger when the target are placed in the bodybag ? Something like : If Target_one placeinbodybag the {true}

 

Thanks

 

Share this post


Link to post
Share on other sites

Why would you need a trigger when you have an eventhandler ?

 

ace_placedInBodyBag <-- just use that and check if the _target is the one you want.

Share this post


Link to post
Share on other sites

I don't know how to use that... I know nothing about how eventhandler works

Share this post


Link to post
Share on other sites

An evenhandler simply executes a function (which you provide it) when a certain event happens.

 

So all you have to do is write a function and put in the eventhandler.

 

simple really:

["ace_placedInBodyBag", yourfunctionname] call CBA_fnc_addEventHandler;
 
 yourfunctionname = {
 	params ["_target", "_bodyBag"];
 	if (_target isEqualTo varnameofyourtargetperson) then {
 		systemChat "hurray, you bagged him!";
 	};
 };

 

  • Like 1

Share this post


Link to post
Share on other sites

Okay !!!! Thanks men ! You're my hero !

Share this post


Link to post
Share on other sites

I tried this and it works but.... it told me that a local variable is in global variable

 

fnc_BenInABag = {
     params ["_target", "ACE_bodyBagItem"];
     if (_target isEqualTo BenLaden) then {
         hint "hurray, you bagged him!";
     };
 };
 
 ["ace_placedInBodyBag", fnc_BenInABag] call CBA_fnc_addEventHandler;


but it works, I have the hint in the screen.

 

[EDIT] I deleted "params" behind ["_target"....]; and no more error message ! Works fine !

Share this post


Link to post
Share on other sites

Now, to load the bag into the helico... not a piece of cake.

 

I tried this : 

 

_vehcile = Hawk_1

 

fnc_BenInCargo = {
    ["_item","_vehicle"];
    if (_item isEqualTo "ACE_bodyBagObject") then {
        hint "hurray, you loaded him!";
     };
};

["ace_cargoloaded", fnc_BenInCargo] call CBA_fnc_addEventHandler;
 

but it doesn't work... but if I change "ACE_bodyBagObject" by a varname it works.. so.. I need to set a variable to the generated body bag when Ben is bagged... don't know how to do it

Share this post


Link to post
Share on other sites

That is the part that you deleted in your previous post:

 fnc_BenInABag = {
     params ["_target", "_bag"];
     if (_target isEqualTo BenLaden) then {
         hint "hurray, you bagged him!";

         missionNamespace setVariable ["BenInABag", _bag, true];
     };
 };

The "params" command takes the parameters of a function and stores them in variables. You can't put global variables in it though, which is why you got an error.

 

 

 

fnc_BenInCargo = {
    ["_item","_vehicle"];
    if (_item isEqualTo BenInABag) then {
        hint "hurray, you loaded him!";
     };
}; 


 

Share this post


Link to post
Share on other sites

Okay I understand now, but there is a subtlety,

 

In the inventory of the player, the body bag are called "ACE_bodyBagItem" and when he bagged someone, this "ACE_bodyBagItem" turn into "ACE_bodyBagObject" that is a different object so the variable of "ACE_bodyBagItem" are not the variable of "ACE_bodyBagObject.

 

So, I try 

fnc_BenInCargo = {
    ["_item","_vehicle"];
    if (_item isEqualTo BenInABag) then {
        hint "hurray, you loaded him!";
     };
}; 

But doesn't work :/

Share this post


Link to post
Share on other sites

I'm on mobile and try to type my solution before I arrive at my station... sorry for the formatting.  I would try this (calls of functions stay the same).

 

fnc_BenInABag = {
     params ["_target", "_bag"];
     if (_target isEqualTo BenLaden) then {
         hint "hurray, you bagged him!";

         _bag setVariable ["benInside",true,true]; // marks the bodybag as occupied by mr. laden
     };
 };

 

 

 

fnc_BenInCargo = {
    params ["_item","_vehicle"];
    if (typeOf _item isEqualTo "ACE_bodyBagObject" && _item getVariable ["benInside",false]) then {
        hint "hurray, you loaded him!";
     };
}; 

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

×