Jump to content
Sign in to follow this  
BEAKSBY

"Killed" event handle not working on created units from addAction

Recommended Posts

When I create a unit from an addAction scripted in the initPlayerLocal.sqf then destroy it the "killed" EVH that is ran from the initServer.sqf is not executed. However "killed" EVH is executed on killed units that are placed in the mission from the Editor?

What could be causing this?

initPlayerLocal.sqf

player addAction ["O_HMG_01_high_F", {_OPPGun = createVehicle ["O_HMG_01_high_F",position player, [], 0, "NONE"]; }];

initServer.sqf

{
_x addeventhandler ["killed",{hint "unit killed as executed from the Killed EVH";}]; 
} foreach allUnits+vehicles+allUnitsUAV; 

Thanks in advance...

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

make the snippet from initServer.sqf look like this:

_nul = [] spawn {
_checklist = [];
while {alive player} do {

{
if !(_x in _checklist) then {
_x addeventhandler ["killed",{hint "unit killed as executed from the Killed EVH";}]; 
_checklist set [count _checklist,_x];
};

} foreach allUnits+vehicles+allUnitsUAV;
sleep 5;
}; 
};

This will check if all your specified units are in a checklist, if not they'll get the eventhandler, runs every 5 seconds. You could add a marvelous performancesleep within the foreach command for performance reasons.

Cheers

Share this post


Link to post
Share on other sites
make the snippet from initServer.sqf look like this:

_nul = [] spawn {
_checklist = [];
while {alive player} do {

{
if !(_x in _checklist) then {
_x addeventhandler ["killed",{hint "unit killed as executed from the Killed EVH";}]; 
_checklist set [count _checklist,_x];
};

} foreach allUnits+vehicles+allUnitsUAV;
sleep 5;
}; 
};

This will check if all your specified units are in a checklist, if not they'll get the eventhandler, runs every 5 seconds. You could add a marvelous performancesleep within the foreach command for performance reasons.

Cheers

Thanks, was having similar issue so will try this out.

Share this post


Link to post
Share on other sites

http://forums.bistudio.com/newthread.php?do=newthread&f=162

make the snippet from initServer.sqf look like this:

_nul = [] spawn {
_checklist = [];
while {alive player} do {

{
if !(_x in _checklist) then {
_x addeventhandler ["killed",{hint "unit killed as executed from the Killed EVH";}]; 
_checklist set [count _checklist,_x];
};

} foreach allUnits+vehicles+allUnitsUAV;
sleep 5;
}; 
};

This will check if all your specified units are in a checklist, if not they'll get the eventhandler, runs every 5 seconds. You could add a marvelous performancesleep within the foreach command for performance reasons.

Cheers

I tried it below but it did not work.

_nul = [] spawn {
_checklist = [];
while {alive player} do {

{
if !(_x in _checklist) then {

// add correct EVH's to vehicle types

{
switch (true) do {

case   (_x iskindof "StaticWeapon") : { 
           _x addeventhandler ["killed",{_this execvm "reward_veh.sqf";}]; 
           _x addeventhandler ["EpeContact",{if((_this select 1) iskindof "landvehicle") then {(_this select 0) setvariable ["collision",driver (_this select 1)]};}];               

		}; 
}; //end switchcase

_checklist set [count _checklist,_x];
};
} foreach allUnits+vehicles+allUnitsUAV;
sleep 5;
}; 
};
};

---------- Post added at 13:14 ---------- Previous post was at 12:42 ----------

How do I run the foreach allUnits+vehicles+allUnitsUAV; throughout the game without affecting performance? Starting new thread as I think this is a different issue?

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Your code is a bit sloppy. Use proper indentation and an editor with syntax highlighting (Poseidon is really good) and you'll easily spot the issues.

_nul = [] spawn {
private ['_checklist'];
_checklist = [];
while {alive player} do {
	{
		if !(_x in _checklist) then {
			// add correct EVH's to vehicle types
			switch (true) do {
				case (_x iskindof "StaticWeapon"): { 
					_x addeventhandler ["killed",{_this execvm "reward_veh.sqf";}]; 
					_x addeventhandler ["EpeContact",{if((_this select 1) iskindof "landvehicle") then {(_this select 0) setvariable ["collision",driver (_this select 1)]};}];               
				}; 
			}; //end switchcase

			_checklist set [count _checklist,_x];
		};
	} foreach allUnits+vehicles+allUnitsUAV;
	sleep 5;
}; 
};

Why would you need a new thread for that?

ps.: You should consider to remove the "alive player" loop and rather run this code only on the server.

Edited by Tajin

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  

×