Jump to content
Sign in to follow this  
jcae2798

pushback Broken?

Recommended Posts

Is the below code wrong?  Or is Arma broken?  I'm driving myself nuts here for the past 2 hours.  I want the addEventHandler to only apply to new spawned units once.   Thanks

While {Alive Player} do {

_excludedVehicles = [s01,s02,s03,s04];
_toCheck = (allunits - _excludedVehicles);
player sidechat format ["%1",_excludedVehicles];
sleep 0.3;
{
    if (!(isPlayer _x) ) then
    {
        _x addEventHandler ["killed", killedEH];
		_excludedVehicles pushBackUnique _x;
    };
} forEach _toCheck;
 
player sidechat format ["%1",_toCheck];
sleep 3;
};

Share this post


Link to post
Share on other sites

So buddy of mine game a code to use in Description file for PreInt which will work.  Still pissed i spent so much time on above when i know it worked in other scenarios.  if anyone see where i may have screwed up, let me know.

Share this post


Link to post
Share on other sites

Why not just add the EH during whatever process you use to spawn the vehicles rather than have some loop running constantly?  Even though it only seems to be an EH for itself to not be counted in the seemingly unnecessary loop...  What exactly are you trying to do?

Share this post


Link to post
Share on other sites

 

Is the below code wrong?  Or is Arma broken?  I'm driving myself nuts here for the past 2 hours.  I want the addEventHandler to only apply to new spawned units once.   Thanks

While {Alive Player} do {

_excludedVehicles = [s01,s02,s03,s04];
_toCheck = (allunits - _excludedVehicles);
player sidechat format ["%1",_excludedVehicles];
sleep 0.3;
{
    if (!(isPlayer _x) ) then
    {
        _x addEventHandler ["killed", killedEH];
		_excludedVehicles pushBackUnique _x;
    };
} forEach _toCheck;
 
player sidechat format ["%1",_toCheck];
sleep 3;
};

You need to rework your code a bit.

As of now you're adding the eventhandler every 0.3 seconds to every non player unit.

 

Like kylania said, a bit more info on what you're trying to achieve would possibly lead to a simpler solution.

 

Cheers

Share this post


Link to post
Share on other sites

That whole script makes no sense. Where are you executing it, on the server I guess. However, player is not known to the server. Additionally, what is killedEH? Is that some sort of function? Otherwise there is no code excuted when your EH fires.

#define EXLUDEDVEHICLES [s01,s02,s03,s04]

while {true} do
{
    {
        if !(_x getVariable ['EH_added',false]) then
        {
            _x addEventHandler ["killed", killedEH]; //What's killed EH?
            EXLUDEDVEHICLES pushBackUnique _x;
        };
        false;
    } count allPlayers;
    sleep 3;
};

I have no clue what you actually try to achieve so I just rewrote the code to what I think would be an improvment. Though, you should still try to add the EH once the vehicle or whatever you are checking when it's spawned.

  • Like 1

Share this post


Link to post
Share on other sites

One time in init.sqf

addMissionEventHandler ["EntityKilled", {
	private _victim = _this select 0;
	if (_victim IS_SATISFIES_THE_CONDITIONS) then {
	
	}
}];

Share this post


Link to post
Share on other sites
One time in init.sqf

 

 

In fact, now that I think about it, the initPlayerLocal.sqf would be the best solution.

Share this post


Link to post
Share on other sites

Ok, so great feedback guys, and take it easy on me as when i work on codes, i dont always think or know what would be best based on performance. :D

 

So first off just to clarify, the code above is not the whole picture.  Basically what i am trying to accomplish is on missions where units are dynamically spawned, i want this eventhandler to be added to their INIT.  The EH code is added above this script in the same SQF file.

 

So for exampke

killedEH = {};  //where the code is there and working.

Blow = code then with loop

 

Now what i want is all units + newly spawned units to have this code executed on their INIT except for BLUFOR and/or Units in my group.  I can play around with the qualifiers to filter this out once i get it going.

While {Alive Player} do {
_excludedVehicles = [s01,s02,s03,s04];
_toCheck = (allunits - playableUnits - allplayers - vehicles - _excludedVehicles);
sleep 0.3;
{
    if (!(isPlayer _x) ) then
    {
        _x addEventHandler ["killed", killedEH];
		_excludedVehicles pushback _x;
    };
} forEach _toCheck;

sleep 3;
};

Basically the whole idea is i am trying to add a kill counter script which will add skill points to units as they increase kills.  What i was going to do is work on this some more once i get it somewhat working, and then ask the community for some help with performance enhancements and other ideas to make it more enjoyable that i could have not accomplish.  While i work on this, also playing around with the GUI editor.  Fun times :386:

Share this post


Link to post
Share on other sites

 

One time in init.sqf

addMissionEventHandler ["EntityKilled", {
	private _victim = _this select 0;
	if (_victim IS_SATISFIES_THE_CONDITIONS) then {
	
	}
}];

 

So this code looks very promising!  Does this mean it would execute on every unit classifed as "Entity" even after mission starts?  So for units spawned during missions?  Also is it both SP/MP supported?  Wiki doesnt seem to state this unless i missed it.   Thanks!

Share this post


Link to post
Share on other sites

So this code looks very promising!  Does this mean it would execute on every unit classifed as "Entity" even after mission starts?  So for units spawned during missions?  Also is it both SP/MP supported?  Wiki doesnt seem to state this unless i missed it.   Thanks!

So i used this code and it works great!!  Thanks for this!

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
Sign in to follow this  

×