muj Mobil 0 Posted January 24, 2023 Hello, I would like to use Event Handlers for Fired but I am little lost. I want create trigger area for example 10x10 m and if anyone, AI or player shoot inside that trigger it will activate code trigger. I do not really know what to write inside condition area. flrObj = "F_40mm_white" createvehicle ((player) ModelToWorld [0,100,200]); flrObj setVelocity [0,0,-10]; Share this post Link to post Share on other sites
Ibragim A 163 Posted January 24, 2023 Since the shot happens quite quickly, you will most likely have to add an event handler to the units, and not check the trigger state. To get started, just put a trigger or create it in a script. Give it a name (variable name), for example, trg_1. Then add a shot handler to all units that need it: _units = allUnits; // As an example { _x addEventHandler ["FiredMan", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle"]; // Here is your block called on every fired shot: if (_weapon in ["Throw","Put"] or !alive trg_1) exitWith {}; // Will not continue, if unit throws some grenade or put an explosive or trigger is deleted if (_unit inArea trg_1) then { // Here is your block called in case _unit fired while in area of trg_1 call Your_script.sqf // As an example deleteVehicle trg_1; // If you do not need to call Your_script.sqf on every shot } }]; } forEach _units; This handler will check at each shot whether the unit is inside the trigger trg_1, and if so, then run the script that you need. So, if you need the script to run only once, and not from each shot in the trigger, that you need to delete the trigger at the first shot in it, as you can see it in the code. 3 1 Share this post Link to post Share on other sites
Joe98 92 Posted January 26, 2023 So if anybody fires a shot within a trigger area, you want that shot to cause the trigger to fire? I don't know sorry. You can start by finding out how to do it for yourself. That is, you walk into a trigger area, fire your weapon and that causes the trigger to fire. Once you have learnt that, you can apply it to other soldiers on the map. 1 Share this post Link to post Share on other sites
Harzach 2518 Posted January 26, 2023 36 minutes ago, Joe98 said: I don't know sorry. @Ibragim A already provided the answer. 1 Share this post Link to post Share on other sites
bLAcKmAgE87 13 Posted January 26, 2023 ...forget this top one I can't move it... just note the globals at the top which get called as a script off init.sqf... haveDamageBat... etc... its important...also notice how this is integrated with a firing drill... Spoiler haveDamageBat = 0 ; hitObjIdsBat = [] ; hitObjPosBat = [] ; battle_guy addEventHandler ["Fired", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; [] execVM "battleShot.sqf" ; }]; battle_guy addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; selectPlayer BIS_FD_Competitor ; [] execVM "init.sqf" ; }]; Suppose there's a handler that goes off when I shoot...and when that handler is called... it runs some code, and also calls another script or file.... Spoiler sleep 6 ; _listObj = nearestObjects [ killBox, [], 150] ; _hasDamage = 0 ; { _damage = getDammage _x ; if( _damage == 1 ) then { _hasDamage = 1 ; _placeOfHit = getPos _x ; hitObjIds pushback (str _x ) ; hitObjPos pushback _placeOfHit ; //_x setDamage [ 0 , false ] ; hitObjs pushback _x ; deleteVehicle _x ; } } forEach _listObj ; if( _hasDamage == 1 ) then { haveDamage = 1 ; hint "theres some damage" ; sleep 2 ; } That's your puzzle... what is "killBox"... I look for triggers in my sqm... virtual object or trigger..... there's things inside INIT Spoiler /* BIS_FD_target2_1 hideObject true ; BIS_FD_target2_2 hideObject true ; BIS_FD_target2_3 hideObject true ; BIS_FD_target3_1 hideObject true ; BIS_FD_target3_2 hideObject true ; BIS_FD_target3_3 hideObject true ; BIS_FD_target3_4 hideObject true ; BIS_FD_target3_5 hideObject true ; BIS_FD_target4_1 hideObject true ; BIS_FD_target4_2 hideObject true ; BIS_FD_target4_3 hideObject true ; BIS_FD_target4_4 hideObject true ; BIS_FD_target5_1 hideObject true ; BIS_FD_target5_2 hideObject true ; hideObjectGlobal BIS_FD_target2_1 ; hideObjectGlobal BIS_FD_target2_2 ; hideObjectGlobal BIS_FD_target2_3 ; hint "exec" ; sleep 5; */ hint "executed init..." ; sleep 3; haveDamage = 0 ; hitObjIds = [] ; hitObjPos = [] ; hitObjs = [] ; _markerSni = createMarker ["sniperMark", position sniper_guy ] ; _markerSni setMarkerType "loc_Frame"; _markerSni setMarkerDir getDir sniper_guy ; _markerBat = createMarker ["battleMark", position weed ] ; _markerBat setMarkerType "loc_Frame"; _markerBat setMarkerDir getDir weed ; [] execVM "snipersHandle.sqf" ; [] execVM "spawnBatGuy.sqf" ; [] execVM "spawnGuy.sqf" ; Spoiler _ourFOV = 0.76 ; sleep 2 ; _counterLast = count hitObjPos ; _counterLast = _counterLast - 1 ; _blownPos = hitObjPos select _counterLast ; _whatPx = _blownPos select 0 ; _whatPy = _blownPos select 1 ; _whatPz = _blownPos select 2 ; _whatPy = _whatPy + 90 ; // use player _whatPz = _whatPz + 90; _whatLx = _blownPos select 0 ; _whatLy = _blownPos select 1 ; _whatLz = _blownPos select 2 ; _camera = "camera" camCreate [0,0,0] ; _camera cameraEffect ["Internal","back"] ; _camera camPrepareTarget [ _whatLx , _whatLy , _whatLz ] ; _camera camPreparePos [ _whatPx , _whatPy , _whatPz ] ; _camera camPrepareFOV _ourFOV ; _camera camCommitPrepared 0 ; sleep 4 ; _camera cameraEffect ["terminate","back"]; camDestroy _camera ; haveDamage = 0 ; //5147.123 4508.843 5024.336 4489.908 4.459 Spoiler //deleteVehicle sniper_guy ; sleep 2 ; sniper_guy addEventHandler ["Respawn", { params ["_unit", "_corpse"]; }]; sniper_guy addEventHandler ["Fired", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; //[] execVM "snipers.sqf" ; [] execVM "hitters.sqf" ; _count = player ammo primaryWeapon player; if(_count == 0 ) then { sniper_guy addPrimaryWeaponItem "5Rnd_127x108_APDS_Mag"; sniper_guy addPrimaryWeaponItem "5Rnd_127x108_APDS_Mag"; } ; }]; sniper_guy addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; [] execVM "spawnGuy.sqf" ; }]; I'll post a vid in a sec... A look at the sqm and trigger going off in my sniper's range.... the trigger constantly repeats... checking for my haveDamage variable... Spoiler class Item41 { dataType="Trigger"; position[]={6875.5742,2.5,3466.1338}; class Attributes { condition="haveDamage == 1 "; onActivation="[] execVM ""snipers.sqf"" ;"; sizeA=222; sizeB=222; sizeC=12; repeatable=1; }; id=139; type="EmptyDetector"; }; in retrospect haveDamage... my variable... goes back to 0 on camera termination... the trigger starts the camera script if you can find it above 1 Share this post Link to post Share on other sites
ZaellixA 383 Posted January 26, 2023 I believe @Ibragim A has provided a nice solution. I would alter it just a bit to incorporate a small change. The changed version would look like (reusing the code provided by Ibragim A) _units = allUnits; // As an example { // For each _x addEventHandler ["FiredMan", { // Event handler code params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle"]; // Here is your block called on every fired shot: // HERE I CHECK WHETHER THE TRIGGER IS "ALIVE" SEPARATELY if (!alive _trg_1) exitWith {_unit removeEventHandler [_thisEvent, _thisEventHandler]}; // If the trigger is not "alive" remove the event handler completely if (_weapon in ["Throw","Put"]) exitWith {}; // Will not continue, if unit throws some grenade or put an explosive or trigger is deleted if (_unit inArea trg_1) then { // Here is your block called in case _unit fired while in area of trg_1 call Your_script.sqf // As an example deleteVehicle trg_1; // If you do not need to call Your_script.sqf on every shot // REMOVE THE EVENT HANDLER IF YOU DELETE THE TRIGGER _unit removeEventHandler [_thisEvent, _thisEventHandler]; } }]; } forEach _units; So, the actual change is that I remove the event handler if the trigger is deleted. I do that for the unit which calls the deletion of the trigger right after the deletion of the trigger, which of course should be deleted along with the deletion line if you don't intend to delete the trigger or do it in another place outside the event handler. For the rest of the units I added a separate check (Ibragim A was already checking for it in order to skip the event handler's execution, so I just moved the check into a separate check) on the top of the code to be executed by the event handler to test whether the trigger exists or not and if not the event handler terminates and its removal is called. Of course, these changes are relevant (as well as Ibragim A's check for the status (alive/dead) of the trigger) if you intend to delete the trigger some time or make the code more generic. I hope this provides an alternative, improvement or at least some insight. Have fun with ArmA. 1 Share this post Link to post Share on other sites
ZaellixA 383 Posted January 26, 2023 On 1/26/2023 at 7:00 AM, Joe98 said: So if anybody fires a shot within a trigger area, you want that shot to cause the trigger to fire? I don't know sorry. Although I understand that interacting with people can manytimes provide insights and instigate discussion and provide new solutions, I am not sure how helpful a comment like "I don't know" is... There's but a minuscule portion of the forum users who can say the opposite for the majority of the topics here. So, I believe that posting to say you don't know how to do something and/or you cannot provide the solution is not very helpful to the OP. 1 1 Share this post Link to post Share on other sites
Larrow 2822 Posted January 27, 2023 On 1/24/2023 at 11:38 AM, Ibragim A said: _units = allUnits; // As an example { _x addEventHandler ["FiredMan", //snip } forEach _units; Be careful here if adding to remote units. Take note of the warning on the events page... Quote Special multiplayer behaviour: When added to a remote unit or vehicle, this EH will only fire if said entity is within range of the camera. That range is determined by the fired ammo's highest visibleFire and audibleFire config value. In case of units, muzzle attachment coefficients are applied too. FiredMan Event 2 Share this post Link to post Share on other sites
Joe98 92 Posted January 27, 2023 On 1/26/2023 at 11:16 PM, ZaellixA said: So, I believe that posting to say you don't know how to do something and/or you cannot provide the solution is not very helpful to the OP. I did provide a first step. You probably missed it. I note the OP has not returned. Most likely because he has not understood anything that has been said. A new point: Many activities in the editor have an easy solution. The editor is designed that way. Many have stopped playing the game because they were given a complex solution they did not understand. Yet another point. When I have made the same comment before I have been told those other people were lazy. . Share this post Link to post Share on other sites
Harzach 2518 Posted January 27, 2023 28 minutes ago, Joe98 said: I did provide a first step. You probably missed it. "Figure it out for yourself" isn't a first step. And yes, not applying yourself is lazy. The cognitive dissonance is just wonderful. The OP already stated an interest in a scripted solution, so your suggestion of nothing was not helpful. 1 Share this post Link to post Share on other sites
ZaellixA 383 Posted January 28, 2023 I'll agree with @Harzach here. Encouraging someone to find a solution doesn't seem like a step (first or not) towards a solution. Nevertheless, I just wanted to make a point that, in my opinion, it would be quite instructive to post when we have something to add to the knowledge base of the community in some way. 11 hours ago, Joe98 said: I note the OP has not returned. Most likely because he has not understood anything that has been said. Not much to be done about it, if this is the case. I am sure we've all seen people posting once or twice and then abandoning their question (for various reasons) and others that insisted "until the end" in an attempt to solve their problem at hand. All we can do is provide educated and well structured solutions and suggestions to the people here in order to increase the overall level in the community and help people. 11 hours ago, Joe98 said: Many have stopped playing the game because they were given a complex solution they did not understand. I don't think (just my opinion though) that scripting and modding is necessarily, directly, related to playing the game. I had been playing ArmA for quite some time (about 5 to 6 years) prior to start scripting. I haven't really put much research effort in finding out if this is the case so it may be otherwise. 1 Share this post Link to post Share on other sites