infiltrator_2k 28 Posted October 22, 2013 I've searched out 3 different lines that allow a trigger to activate on condition upon a player adding an item to his inventory slot, vest or anywhere on the player, although it doesn't seem to work when a player picks up a Bergen. I've located the correct 'class name' and understand it's all case sensitive. The code works as I've tested it when picking up ItemMap and ItemGPS, although it doesn't work when I pickup a Bergen. Can anyone please tell me the line of code I need to add so the trigger condition detects when a player has found/wearing a Bergen please. Cheers Ian Share this post Link to post Share on other sites
Von Quest 1049 Posted October 23, 2013 Name your Unit P1 (or whatever) Condition: "Backpack_Classname" == Backpack P1; Share this post Link to post Share on other sites
infiltrator_2k 28 Posted October 23, 2013 (edited) Name your Unit P1 (or whatever)Condition: "Backpack_Classname" == Backpack P1; Thanks chap. I take it if you want the trigger from any player of a side you place the player name with Opfor/Blufor? I'm going to have to get my head around this SQF scripting. It doesn't look easy though :/ Edited October 23, 2013 by Infiltrator_2K Share this post Link to post Share on other sites
das attorney 840 Posted October 23, 2013 (edited) You could check out the new event handlers (EH) for best performance. It may seem trivial for things like this, but if you want a lot of scripted checks in your missions/mods, then using multiple triggers/loops adds up to a drain on performance after a while. Don't get me wrong, triggers and loops have their uses, but there are certain situations where use of an EH is more appropriate. Plus, once you get your head around how to use them, you'll start to see how useful they are and end up using them a lot of the time. If you're new to scripting, then an EH is very similar to a trigger, but does not poll the game repeatedly to check if a condition is fulfilled. So with a trigger to check if a player is dead, it would check every 0.5 seconds if the player is alive (alive player). Once the player is dead, then the trigger stops checking. In contrast, the "killed" EH sits there idle and is only executed when the player dies. (So it only ever runs once). In respect to your situation, we can use the new "take" EH to check every item the player picks up (it fires every time you add something to your inventory and you can filter the returned object to check if it is a Bergen). What happens then is up to you (it runs your code). Also, something to consider is that you can remove the EH if you choose to. (So you have the option of it running your code every time you pick up a Bergen, or you could delete the EH, so any further Bergen's picked up, or the same Bergen multiple times doesn't run the code). Just as a disclaimer, let's do this for SP. If we think about MP then it may get difficult to explain. (Get it working in SP and then convert it to MP later if you need to). So let's look at addEventHandler. Put this in your unit's init line: Infiltrator_2K_BergenEH_Index = this addEventHandler ["take", _this call Infiltrator_2K_BergenPickUp]; This tells Arma that every time this unit picks up something, it will run some code that we decided to name Infiltrator_2K_BergenPickUp We have also determined a reference to the EH ( Infiltrator_2K_BergenEH_Index ), which we can use to remove the EH if need be. some data is passed to the code we are running. In this case it's [your _unit name, the _source of the item, the classname of the _item]; So if you want some code to run every time you pick up a Bergen, then put this in your init.sqf. Infiltrator_2K_BergenPickUp = { _unit = _this select 0; _source = _this select 1; _item = _this select 2; if (_item == "Bergen_Backpack_Classname") then { // run your code here }; }; If you wanted it so that you only ever run your code once (the first time you pick up a Bergen) then change it to this: Infiltrator_2K_BergenPickUp = { _unit = _this select 0; _source = _this select 1; _item = _this select 2; if (_item == "Bergen_Backpack_Classname") then { // run your code here _unit removeEventHandler ["take", Infiltrator_2K_BergenEH_Index]; }; }; We could go on and on with different examples (and the possibilities are endless) but I just wanted to mention this in case you want to find out a little bit more about where you can go with Arma scripting. :) Edited October 23, 2013 by Das Attorney Wrong className Share this post Link to post Share on other sites
infiltrator_2k 28 Posted October 24, 2013 You could check out the new event handlers (EH) for best performance. It may seem trivial for things like this, but if you want a lot of scripted checks in your missions/mods, then using multiple triggers/loops adds up to a drain on performance after a while. Don't get me wrong, triggers and loops have their uses, but there are certain situations where use of an EH is more appropriate.Plus, once you get your head around how to use them, you'll start to see how useful they are and end up using them a lot of the time. If you're new to scripting, then an EH is very similar to a trigger, but does not poll the game repeatedly to check if a condition is fulfilled. So with a trigger to check if a player is dead, it would check every 0.5 seconds if the player is alive (alive player). Once the player is dead, then the trigger stops checking. In contrast, the "killed" EH sits there idle and is only executed when the player dies. (So it only ever runs once). In respect to your situation, we can use the new "take" EH to check every item the player picks up (it fires every time you add something to your inventory and you can filter the returned object to check if it is a Bergen). What happens then is up to you (it runs your code). Also, something to consider is that you can remove the EH if you choose to. (So you have the option of it running your code every time you pick up a Bergen, or you could delete the EH, so any further Bergen's picked up, or the same Bergen multiple times doesn't run the code). Just as a disclaimer, let's do this for SP. If we think about MP then it may get difficult to explain. (Get it working in SP and then convert it to MP later if you need to). So let's look at addEventHandler. Put this in your unit's init line: Infiltrator_2K_BergenEH_Index = this addEventHandler ["take", _this call Infiltrator_2K_BergenPickUp]; This tells Arma that every time this unit picks up something, it will run some code that we decided to name Infiltrator_2K_BergenPickUp We have also determined a reference to the EH ( Infiltrator_2K_BergenEH_Index ), which we can use to remove the EH if need be. some data is passed to the code we are running. In this case it's [your _unit name, the _source of the item, the classname of the _item]; So if you want some code to run every time you pick up a Bergen, then put this in your init.sqf. Infiltrator_2K_BergenPickUp = { _unit = _this select 0; _source = _this select 1; _item = _this select 2; if (_item == "Bergen_Backpack_Classname") then { // run your code here }; }; If you wanted it so that you only ever run your code once (the first time you pick up a Bergen) then change it to this: Infiltrator_2K_BergenPickUp = { _unit = _this select 0; _source = _this select 1; _item = _this select 2; if (_item == "Bergen_Backpack_Classname") then { // run your code here _unit removeEventHandler ["take", Infiltrator_2K_BergenEH_Index]; }; }; We could go on and on with different examples (and the possibilities are endless) but I just wanted to mention this in case you want to find out a little bit more about where you can go with Arma scripting. :) Cheers Das. You explained that in layman's terms which as new to scripting I grasped immediately, so thanks for that. In short, from what I understand you're saying is that EH is the way forward, as its a lot more efficient as if you repeatedly keeping adding triggers to a mission they'll eventually place a burden on system resources given its continuous polling requirements, thus causing a drop in frame rate. Just curious, but do you still use triggers? And are there situations where EH cannot replace triggers? Also, do you still use a trigger's axis when using EH? Share this post Link to post Share on other sites