Jump to content
Gen. MERICA

addEventHandler selectively working?

Recommended Posts

I am trying to get it so if a player kills an AI unit it increases their score.

 

this addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];

 

Pasting this into a unit from the editor works just fine, the player the correct amount.

However doing the same thing for spawned in units such as a helicopter crew, do not give any points.

 

{_x addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];}foreach units _helicrew;

 

Helicopter spawn script

for [{_i=2}, {_i!=0}, {_i=_i-1}] do{
_helicrew = [];
_heli = [];
hint "test1";
//_helicrew = creategroup INDEPENDENT;
_helicrew = creategroup east;
_heli = [getMarkerPos "FriendlyAirspawn", 61, "CUP_I_Mi24_Mk4_AT_AAF", _helicrew] call BIS_fnc_spawnVehicle;

{_x addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];}foreach units _helicrew;

_wp1 = _helicrew addWaypoint [(getmarkerpos "Base"), 0];
_wp1 setWaypointType "SAD";
_wp1 setWaypointSpeed "FULL";
sleep 5;
};

fnc_AIKilled

fnc_AIKilled = {
hint "hello";
if(player == (_this select 1)) then {
hint "hello 2";
Cash = Cash + (Points / Players);
uiNameSpace getVariable "myUI_DollarTitle" ctrlSetText format["$ %1", Cash];
};
};

Not quite sure what I am doing wrong here. 

Share this post


Link to post
Share on other sites

You can test (_heli select 2) instead of _helicrew...

but I guess you just need to wait a little delay for the return value for your _helicrew.

just place a sleep 0.5; (approx.) after spawning your group. It takes time to spawn it and return the result, despite the call of Bi function.

 

_helicrew = creategroup east;
_heli = [getMarkerPos "FriendlyAirspawn", 61, "CUP_I_Mi24_Mk4_AT_AAF", _helicrew] call BIS_fnc_spawnVehicle;
sleep 0.3;
{_x addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];}foreach units _helicrew;

Share this post


Link to post
Share on other sites
40 minutes ago, Grumpy Old Man said:

nevermind, forum software put this post in the wrong thread 0o

 

Cheers

 

Welcome to the club!

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

You can test (_heli select 2) instead of _helicrew...

but I guess you just need to wait a little delay for the return value for your _helicrew.

just place a sleep 0.5; (approx.) after spawning your group. It takes time to spawn it and return the result, despite the call of Bi function.

 


_helicrew = creategroup east;
_heli = [getMarkerPos "FriendlyAirspawn", 61, "CUP_I_Mi24_Mk4_AT_AAF", _helicrew] call BIS_fnc_spawnVehicle;
sleep 0.3;
{_x addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];}foreach units _helicrew;

 

 

It isn't that the command doesn't fire (probably should have notated this yesterday) but it calls the functions successfully and returns "hello". However it does not return "hello 2". Originally I thought maybe there was a mismatch between the killer or something but if I do

fnc_AIKilled = {
hint format["%1 == %2", player, (_this select 1)];
if(player == (_this select 1)) then {
hint "hello 2";
Cash = Cash + (Points / Players);
uiNameSpace getVariable "myUI_DollarTitle" ctrlSetText format["$ %1", Cash];
};
};

It shows R Alpha 1-1:1 (Jacob) == R Alpha 1-1:1 (Jacob)

It does not display "hello 2".

Like before if I do "this addMPEventHandler['mpkilled',{Points = 100;_this call fnc_AIKilled}];" on editor units, it works just fine on them and displays "hello 2".

I have tried with the sleep command for giggles but its the same result. 

I would test it with (_heli select 0 or 1) but it returns an error about being an array rather than an object, which I find odd as I can do (_heli select 0 or 1) setVelocity [500,0,0,] just fine. 

 

Share this post


Link to post
Share on other sites

why 'mpKilled' (single quote) instead of "mpKilled" (double quote) ?

Share this post


Link to post
Share on other sites
2 hours ago, pierremgi said:

why 'mpKilled' (single quote) instead of "mpKilled" (double quote) ?

Has no effect,

When I do _x only, it complains about expecting an object.

When. I do _x select 2, it complains about expecting an array?

Nothing seems to make this happy

Share this post


Link to post
Share on other sites

if you stop the code after hint "hello 2", that works. At least on my host PC. So, there is a possible problem/behavior after that which leads to skip the hint...

players?  uiNameSpace getVariable "myUI_DollarTitle" ctrlSetText format["$ %1", Cash] ?

Share this post


Link to post
Share on other sites
3 hours ago, Gen. MERICA said:

When I do _x only, it complains about expecting an object.

When. I do _x select 2, it complains about expecting an array?

Nothing seems to make this happy

{_x do something with this variable} foreach units <a group here> like _helicrew (units somegroup is an array of objects as far as units are created, an array is mandatory to make a forEach loop working);

{_x do something with this variable} foreach units (_heli select 2) // read what is returned by BIS_fnc_spawnVehicle

{_x do something with this variable} foreach (_heli select 1) // same as above as crew is already an array

Share this post


Link to post
Share on other sites

I tried a ton of different options, 

Although no matter what the if statement is

if(player == _killer) then {};

It would never trigger for me, with or without those two lines.

I just decided to do a blanket coverage, giving everyone an amount based on a kill. I saw other people in the forum having problems trying something like this as well so I will put it here for others.

fnc_AIKilled = {
_killer = _this select 1;
hint format["%1",(side _killer)];
if((side _killer) == resistance) then {
Cash = Cash + floor((Points / Players)/Players);
["actions\trustfund\Update.sqf","BIS_fnc_execVM",true,false] spawn BIS_fnc_MP;
};
if((side _killer) == EAST) then {
OpForCash = OpForCash + floor(Points/Players);
publicVariable "OpForCash";
["actions\trustfund\Update.sqf","BIS_fnc_execVM",true,false] spawn BIS_fnc_MP;
};
if((side _killer) == WEST) then {
BluForCash = BluForCash + floor(Points/Players);
publicVariable "BluForCash";
["actions\trustfund\Update.sqf","BIS_fnc_execVM",true,false] spawn BIS_fnc_MP;
};
};

As for the event handler others had issues as well, the only work around I could find was either to do the crew individually and return what vehicle they are in or avoid BIS_fnc_spawnVehicle

Decided to just go with createVehicle

_group = createGroup independent;
_heli = createVehicle ["CUP_I_Mi24_Mk4_AT_AAF", getMarkerPos "FriendlyAirspawn",[],0,"FLY"];
createVehicleCrew _heli;
_heli setDir 61;
(crew _heli) joinSilent _group;

_heli addMPEventHandler["mpkilled",{Points = 100;_this call fnc_AIKilled}];

Thanks for trying though, not quite sure why the if statement never triggered.

**EDIT**

Side note, the if statement works fine on infantry.

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

×