SealTeam3 0 Posted August 20, 2018 So I am trying to add a script whenever a player takes a certain item out of any container/vehicle it adds another to their inventory. I am still new to EHs and a little confused. Here is what I have tried thus far: player addEventHandler ["Take", { _this call {this, " if({_x == "rhs_weap_m72a7"} && count magazines player == 0) then {player addMagazine rhs_ammo_m72a7_rocket};" }]; Additionally, do I add this to the playerInit.sqf file or somewhere else? Share this post Link to post Share on other sites
Dedmen 2714 Posted August 20, 2018 4 hours ago, SealTeam3 said: I am still new to EHs and a little confused. Here is what I have tried thus far: Yes. Good. And you problem is? That it doesn't work I guess? Let's split it up player addEventHandler ["Take", { _this call { //What use does this call have? this, //What is this comma supposed to do? " if({_x /* Where does _x come from all of the sudden?? */ == "rhs_weap_m72a7"} /* Why is this wrapped in {}???*/ && count magazines player == 0) then {player addMagazine rhs_ammo_m72a7_rocket};" //You are just dumping this string and doing nothing with it. } //Missing } for line 2. ]; Just removing all the nonsense and actually executing that code inside your string. player addEventHandler ["Take", { if({_x == "rhs_weap_m72a7"} && count magazines player == 0) then { player addMagazine rhs_ammo_m72a7_rocket }; } ]; Still doesn't work at all because _x is undefined. And that && operator that you are trying to call doesn't exist. And also you are giving addMagazine a undefined variable while it expects a string. Fixing all that to how I think you intend it to work. player addEventHandler ["Take", { params ["_unit", "_container", "_item"]; if(_item == "rhs_weap_m72a7" && count magazines player == 0) then { player addMagazine "rhs_ammo_m72a7_rocket"; }; } ]; Now optimizing the code a little player addEventHandler ["Take", { params ["_unit", "_container", "_item"]; if (_item == "rhs_weap_m72a7" && {magazines player isEqualTo []}) then { player addMagazine "rhs_ammo_m72a7_rocket"; }; }]; Though i still don't understand why you only add it when the player has absolutely no magazines in his inventory. But I'm sure you have a good reason for that. Share this post Link to post Share on other sites
SealTeam3 0 Posted August 20, 2018 6 hours ago, Dedmen said: Yes. Good. And you problem is? That it doesn't work I guess? Let's split it up player addEventHandler ["Take", { _this call { //What use does this call have? this, //What is this comma supposed to do? " if({_x /* Where does _x come from all of the sudden?? */ == "rhs_weap_m72a7"} /* Why is this wrapped in {}???*/ && count magazines player == 0) then {player addMagazine rhs_ammo_m72a7_rocket};" //You are just dumping this string and doing nothing with it. } //Missing } for line 2. ]; Just removing all the nonsense and actually executing that code inside your string. player addEventHandler ["Take", { if({_x == "rhs_weap_m72a7"} && count magazines player == 0) then { player addMagazine rhs_ammo_m72a7_rocket }; } ]; Still doesn't work at all because _x is undefined. And that && operator that you are trying to call doesn't exist. And also you are giving addMagazine a undefined variable while it expects a string. Fixing all that to how I think you intend it to work. player addEventHandler ["Take", { params ["_unit", "_container", "_item"]; if(_item == "rhs_weap_m72a7" && count magazines player == 0) then { player addMagazine "rhs_ammo_m72a7_rocket"; }; } ]; Now optimizing the code a little player addEventHandler ["Take", { params ["_unit", "_container", "_item"]; if (_item == "rhs_weap_m72a7" && {magazines player isEqualTo []}) then { player addMagazine "rhs_ammo_m72a7_rocket"; }; }]; Though i still don't understand why you only add it when the player has absolutely no magazines in his inventory. But I'm sure you have a good reason for that. Server is having issues with RHS, and the M72 Law is supposed to have ammo when you take it out of a box; however, when we take it out, it doesn't have a 'mag (rocket round)' and you cannot fire it. Thus adding one to the inventory (from my testing) allows you to load and fire the launcher. Following this I have 2 questions: Does this work for the container you take the M72 from? Would this be added to the PlayerInit ? Thanks for the help!!! Share this post Link to post Share on other sites
Dedmen 2714 Posted August 21, 2018 17 hours ago, SealTeam3 said: Does this work for the container you take the M72 from? Afaik it doesn't matter what container. 17 hours ago, SealTeam3 said: Would this be added to the PlayerInit ? You can do that yes. I'd recommend initPlayerLocal Share this post Link to post Share on other sites
SealTeam3 0 Posted August 21, 2018 On 8/20/2018 at 3:20 AM, Dedmen said: Though i still don't understand why you only add it when the player has absolutely no magazines in his inventory. But I'm sure you have a good reason for that. Sorry for misleading you, I didn't mean absolutely no mags. I meant no mags for the M72. I am assuming it would look like this: player addEventHandler ["Take", { params ["_unit", "_container", "_item"]; if (_item == "rhs_weap_m72a7" && {!(_x isEqualTo "rhs_ammo_m72a7_rocket")}forEach soldierMagazines player) && {secondaryWeaponMagazine player isEqualTo []}) then { player addMagazine "rhs_ammo_m72a7_rocket"; }; }]; I might be wrong however, feedback would be appreciated. Thanks Share this post Link to post Share on other sites
Dedmen 2714 Posted August 22, 2018 12 hours ago, SealTeam3 said: {!(_x isEqualTo "rhs_ammo_m72a7_rocket")}forEach soldierMagazines player forEach just returns the value of the last iteration. So this only checks if the last magazine is not a rocket. Also isEqualTo is case sensitive which is a bad idea with classnames soldierMagazines findIf {_x == "rhs_ammo_m72a7_rocket"} == -1 Find the magazine called "rhs_ammo_m72a7_rocket" and check if nothing was found. Share this post Link to post Share on other sites