steam-76561198013707443 0 Posted March 21, 2021 I want to make a script in which there will be a task to mine the road. I need the task to be completed when more than 3 bombs are placed on the road. I try to accomplish this using a script, but it does not work for me. Anyone have any ideas? this exec "S1.sqs" itemsDelivered = 0; player1 addeventhandler ["Put",{ _player1 = _this select 0; _object = _this select 1; _type = _this select 2; if (isServer) then if (_type == "_SatchelCharge_F") then {itemsDelivered = itemsDelivered + 1;}; } [] spawn { waituntil {sleep 1; itemsDelivered == 3}; sleep 1; }; Share this post Link to post Share on other sites
pierremgi 4850 Posted March 21, 2021 welcome to the forum Try to write a title which can help the search for future readers. sqs is totally outdated. Use sqf syntax. it's possible to translate sqs code into sqf. Your event handler is wrong. You must use the "take" (pick from a container, here your backpack) one, not the "put" EH (inside a container). The code is effect local (EL) so if you are in MP you must broadcast the value itemsDelivered, but there is no need of waitUntil as you can run a code from the EH. IsServer is not a way to remoteExec a code from local PC (the player who triggered the EH) to server. Furthermore, there is no player on dedicated server... "_SatchelCharge_F" can't work. It's not a valid class but a useless stringed undefined local variable... You must use the magazine class "SatchelCharge_remote_Mag" So, try something like: in initServer.sqf (add it in root folder where mission.sqm is) itemsDelivered = 0; publicVariable "itemsDelivered"; This way, the server stats with a zero counter, not garbled by JIP starts (incoming players) or, in init.sqf but you need to filter like this: if (isServer) then { itemsDelivered = 0; publicVariable "itemsDelivered"; }; because init.sqf is run by any player and you don't want a player resets the counter. then, in init.sqf or better, in initPlayerLocal.sqf: player addEventhandler ["Take", { params ["_plyr","_cont","_item"]; if (_item == "SatchelCharge_Remote_Mag" && isNull _cont) then { itemsDelivered = itemsDelivered + 1; publicVariable "itemsDelivered"; if (itemsDelivered == 3) then { "Mining done!" remoteExec ["hint"]; _plyr removeEventHandler ["take", _thisEventHandler] }; }; }]; The code to be executed (here a hint for all players) is on your side. 2 Share this post Link to post Share on other sites
wogz187 1086 Posted March 21, 2021 @steam-76561198013707443, a) the "take" EH is triggered by collecting explosives from a box b) "... more than 3 bombs..." c) "... (bombs) are placed on the road..." I'm not an expert on locality but I think the public variable is unnecessary. Spoiler this addEventhandler ["Take", { params ["_unit", "_container", "_item"]; private _pos= isOnRoad _unit; if (_pos && {_item == "SatchelCharge_Remote_Mag"} && {isNull _container}) then { _unit setVariable ["mines_placed", (_unit getVariable ["mines_placed", 0])+1]; if (_unit getVariable ["mines_placed", 0]>3) then { "Mining done!" remoteExec ["hint"]; _unit removeEventHandler ["take", _thisEventHandler] } } }]; Only counts explosives placed from backpack and on road. Counts 3+ explosives. Pasted directly in unit init or added via script. Have fun! 1 Share this post Link to post Share on other sites
pierremgi 4850 Posted March 21, 2021 47 minutes ago, wogz187 said: @steam-76561198013707443, a) the "take" EH is triggered by collecting explosives from a box b) "... more than 3 bombs..." c) "... (bombs) are placed on the road..." I'm not an expert on locality but I think the public variable is unnecessary. Hide contents this addEventhandler ["Take", { params ["_unit", "_container", "_item"]; private _pos= isOnRoad _unit; if (_pos && {_item == "SatchelCharge_Remote_Mag"} && {isNull _container}) then { _unit setVariable ["mines_placed", (_unit getVariable ["mines_placed", 0])+1]; if (_unit getVariable ["mines_placed", 0]>3) then { "Mining done!" remoteExec ["hint"]; _unit removeEventHandler ["take", _thisEventHandler] } } }]; Only counts explosives placed from backpack and on road. Counts 3+ explosives. Pasted directly in unit init or added via script. Have fun! The difference is simple: - my script manages a publicVariable for a common quantity of mines shared by players. So, a common task, no matter who placed them. - yours, acts for each player, counting individual placed mines, no matter the final global quantity. 2 Share this post Link to post Share on other sites
Joe98 91 Posted March 21, 2021 Mines and satchel charges are available as individual items in the editor. Select your mines and place them on the ground for people to pick up. Give each mine a name. Then you can test in a trigger whether each individual mine is present. When all 3 are present the trigger fires. Or, place 3 triggers on a map, one trigger for each mine. As the mine is present the individual trigger fires. After all 3 triggers fire, this causes a 4th trigger to fire and you have your result. . Share this post Link to post Share on other sites
pierremgi 4850 Posted March 22, 2021 1 hour ago, Joe98 said: Mines and satchel charges are available as individual items in the editor. Select your mines and place them on the ground for people to pick up. Give each mine a name. Then you can test in a trigger whether each individual mine is present. When all 3 are present the trigger fires. Or, place 3 triggers on a map, one trigger for each mine. As the mine is present the individual trigger fires. After all 3 triggers fire, this causes a 4th trigger to fire and you have your result. . Really? Why placing mines + 4 triggers when you can script just 1 eventHandler? 3 Share this post Link to post Share on other sites
Joe98 91 Posted March 23, 2021 On 3/22/2021 at 12:16 PM, pierremgi said: Really? Why placing mines + 4 triggers when you can script just 1 eventHandler? He has only made one post. He may not be familiar with scripting so this is just another way of doing it. . Share this post Link to post Share on other sites