thereaper 1 Posted January 31, 2015 Hi, I'm trying to get a function working where the target will take damage at a reduced rate, and will go down at a certain damage threshold. I got in the init: this addEventHandler["handleDamage",{_this call fn_hit;}]; This didn't work at all, I placed everything of the function in comment and just made it call bis_fnc_endmission, and that didn't work either. I made a non-function version of the function as well, I got that working using: this addEventHandler["handleDamage",{_this execVM "Damage.sqf";}]; In the execVM script, instead of returning the damage, I am using setdamage to injure the target. The target however sometimes regains health because of how the eventhandler works (going through all the body parts individually). How can I make the call function work? And is there a better eventhandler for this or should the function where damage is returned instead of using setdamage fix this as well? Share this post Link to post Share on other sites
jshock 513 Posted January 31, 2015 I think you need to spawn the function, in the EH, as it's a scheduled environment, so you can't suspend within it. Turn on -showScriptErrors in Steam startup parameters if you haven't because I believe this would have thrown "Error- Generic Error in Expression" or similar. Share this post Link to post Share on other sites
das attorney 858 Posted January 31, 2015 AS Mr Shock says, it's probably unscheduled/sleep problem. (Most likely will say "suspending not allowed in this context") Hard to tell without seeing contents of fn_hit or error message. Share this post Link to post Share on other sites
jshock 513 Posted January 31, 2015 AS Mr Shock says, it's probably unscheduled/sleep problem. (Most likely will say "suspending not allowed in this context")Hard to tell without seeing contents of fn_hit or error message. Well technically doesn't call suspend? Because it waits for a return? Share this post Link to post Share on other sites
das attorney 858 Posted January 31, 2015 (edited) It's not really waiting as such, just reading code from another location as if were inline within the script/function it is called from. It's like ripping a page out of a book and placing it somewhere else in your house. You still have to read the page in order to read the book, even though you're now reading the page in it's new location (like on your desk or in the garden for example). The rest of the book isn't "waiting" for you to finish the page. It's just information ordered into a sequence that can only be understood by reading it in the right order (even if the physical location is different). Edited January 31, 2015 by Das Attorney Share this post Link to post Share on other sites
jshock 513 Posted January 31, 2015 (edited) Makes sense, I just wasn't visualizing it all properly in my head :p. I get how to use it all correctly for sure, just didn't really think on how it all worked I guess, idk, it's the weekend, brain no work for 2 more days :). Edited January 31, 2015 by JShock Share this post Link to post Share on other sites
das attorney 858 Posted January 31, 2015 Yay weekend! :) Share this post Link to post Share on other sites
boriz 1 Posted January 31, 2015 (edited) I think I have the same problem. This might be related. If not then I'll start a new threat about this. This script spawns a helicopter, adds a crew into it and adds an even handler for getting hit by bullets. Everything works fine in singleplayer and in multiplayer as long as the server is hosted from the game. However when the server is hosted from a Dedicated Server, the event for catching "HitPart" (the bold code) doesn't work. The event is simply not called. Can someone please explain me why and how to fix it? I've tried changing addEventHandler to addMPEventHandler but that didn't worked at all. _heli = createVehicle [_type, _spawnLocation, [], 0, "FLY"]; _heli setdamage enemySpawnDamage; 0 = [_heli] execVM "BV_killWhenUseless.sqf"; 0 = [_heli] execVM "BV_heightLimit.sqf"; createVehicleCrew (_heli); crew _heli join _group; AIunits = AIunits + crew _heli; 0 = driver _heli execVM "BV_killWhenOnFoot.sqf"; 0 = gunner _heli execVM "BV_killWhenOnFoot.sqf"; { _x setSkill _skill; }forEach crew _heli; _wp = _group addWaypoint [posTarget, 0]; [_group, 1] setWaypointType "SAD"; _group setCombatMode "RED"; _group setBehaviour "SAFE"; _group allowFleeing 0; _heli flyInHeight 30; [b]_heli spawn { // Critical damage event _this addEventHandler ["HitPart", { if (random 1 > 0.90) then { _heli = (_this select 0) select 0; _heliPos = getPosASL _heli; _bulletPos = (_this select 0) select 3; _bomb = createVehicle ["CMflare_Chaff_Ammo", _bulletPos, [], 0, "NONE"]; _heli setDamage (damage _heli + 0.1); _bomb attachTo [_heli, [ ((_heliPos select 0) - (_bulletPos select 0)) * 0.3, ((_heliPos select 1) - (_bulletPos select 1)) * 0.3, ((_heliPos select 2) - (_bulletPos select 2)) * 0.3 ]]; }; }]; }[/b] This code is executed only on the server. Edited January 31, 2015 by Boriz Share this post Link to post Share on other sites
thereaper 1 Posted January 31, 2015 Sorry I didn't include the fn_hit code. Here it is, it is based on Altis Life's life_fnc_handledamage. In altis life its also added using the handledamage EVH and call life_fnc_handledamage. So I wonder why it didn't work for me. _unit = _this select 0; _part = _this select 1; _damage = _this select 2; _source = _this select 3; _projectile = _this select 4; if(!isNull _source) then { if(_source != _unit) then { if (damage _unit != 0) then { [[(_this select 0), "AcinPercMstpSrasWrflDnon_agony"], "switchMove",true,false] call BIS_fnc_MP; } else { _damage = damage _unit; _randomizedDamage = random 0.5; _damage = _damage + _randomizedDamage; }; }; }; _damage But as I mentioned in the OP, I also tried setting everything in comments and just made this function call endmission, that didn't work either. And using -showscripterrors, I get nothing. Not a single error :\ Share this post Link to post Share on other sites
killzone_kid 1332 Posted January 31, 2015 Type in debug console hint str [fn_hit]; If you see something like [any] in the hint, your function is not defined. Share this post Link to post Share on other sites
thereaper 1 Posted January 31, 2015 It returns [any] but I got functions.h class Reaper { class functions { file = "Functions"; class Hit {}; }; }; and description.ext class CfgFunctions { #include "Functions.h" }; I get no error at start and if I change the class Hit {} to class Hits {} it says: Script Functions\fn_Hits.sqf not found. I don't get that error with Hit, so it does find the script. Share this post Link to post Share on other sites
killzone_kid 1332 Posted January 31, 2015 I suggest you read this: https://community.bistudio.com/wiki/Functions_Library_%28Arma_3%29 then on how to correctly define and use function library Share this post Link to post Share on other sites
thereaper 1 Posted January 31, 2015 Added tag = "Reaper"; to the class and used call Reaper_fnc_hit and now it works. So dumb. Share this post Link to post Share on other sites