Tex Hasselhoff Posted March 18 Share Posted March 18 Hello, I'm making a life server on the latest 5.0 version of Altis Life Framework, its up and running smooth. I would like to make gathering toggled/automatic so players don't have to keep hitting the Windows Key to keep gathering ingredients on the map. Basic Description of desired result: User hits Windows Key to start gathering ingredients and the character will do so until full or until user hits the TAB key to stop gathering ingredients. "Olympus Entertainment" has this functionality on their life server so, I know its possible, I just don't know how. What I have done so far is inserted a "while true" statement in the "fn_gather.sqf" file to loop the gathering script which works so far. Now I just need help making the "TAB" key stop/interrupt/cancel/suspend/terminate/pause/exit the "fn_gather.sqf" script. I would also like to adapt this to processing as well to cancel processing by hitting TAB. Any and all help is much appreciated, thanks for reading and have a great day. #include "..\..\script_macros.hpp" /* File: fn_gather.sqf Author: Devilfloh Description: Main functionality for gathering. */ autogather = 1; while {autogather > 0} do { private ["_maxGather","_resource","_amount","_maxGather","_requiredItem"]; if (life_action_inUse) exitWith {}; if !(isNull objectParent player) exitWith {}; if (player getVariable "restrained") exitWith {hint localize "STR_NOTF_isrestrained";}; if (player getVariable "playerSurrender") exitWith {hint localize "STR_NOTF_surrender";}; life_action_inUse = true; _zone = ""; _requiredItem = ""; _exit = false; _resourceCfg = missionConfigFile >> "CfgGather" >> "Resources"; for "_i" from 0 to count(_resourceCfg)-1 do { _curConfig = _resourceCfg select _i; _resource = configName _curConfig; _maxGather = getNumber(_curConfig >> "amount"); _zoneSize = getNumber(_curConfig >> "zoneSize"); _resourceZones = getArray(_curConfig >> "zones"); _requiredItem = getText(_curConfig >> "item"); { if ((player distance (getMarkerPos _x)) < _zoneSize) exitWith {_zone = _x;}; } forEach _resourceZones; if (_zone != "") exitWith {}; }; if (_zone isEqualTo "") exitWith {life_action_inUse = false;}; if (_requiredItem != "") then { _valItem = missionNamespace getVariable "life_inv_" + _requiredItem; if (_valItem < 1) exitWith { switch (_requiredItem) do { //Messages here }; life_action_inUse = false; _exit = true; }; }; if (_exit) exitWith {life_action_inUse = false;}; _amount = round(random(_maxGather)) + 1; _diff = [_resource,_amount,life_carryWeight,life_maxWeight] call life_fnc_calWeightDiff; if (_diff isEqualTo 0) exitWith { hint localize "STR_NOTF_InvFull"; life_action_inUse = false; }; switch (_requiredItem) do { case "pickaxe": {[player,"mining",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT]}; default {[player,"harvest",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT]}; }; for "_i" from 0 to 4 do { player playMoveNow "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon"; waitUntil{animationState player != "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";}; sleep 0.5; }; if ([true,_resource,_diff] call life_fnc_handleInv) then { _itemName = M_CONFIG(getText,"VirtualItems",_resource,"displayName"); titleText[format [localize "STR_NOTF_Gather_Success",(localize _itemName),_diff],"PLAIN"]; }; sleep 1; life_action_inUse = false; //switch (_code) do { //case 15: { //exitWith { //hint localize "Action Cancelled"; //life_action_inUse = false;} //}; //}; }; 1 Quote Link to comment Share on other sites More sharing options...
gustavseitztestarma3 Posted March 21 Share Posted March 21 https://native-network.net/forum/thread/2422-farming-abbau-massenproduktion/ dont know if it works for 5.0 though Quote Link to comment Share on other sites More sharing options...
KllTA Posted May 20 Share Posted May 20 (edited) To make the provided script toggle-able instead of clicking windows every time, you can introduce a variable that controls the execution of the script. Here's an updated version of the script with the toggle functionality: #include "..\..\script_macros.hpp" /* File: fn_gather.sqf Author: Devilfloh Description: Main functionality for gathering. */ private ["_maxGather","_resource","_amount","_maxGather","_requiredItem"]; autogather = false; // Set to true to enable autogather while {autogather} do { if (life_action_inUse) exitWith {}; if !(isNull objectParent player) exitWith {}; if (player getVariable "restrained") exitWith {hint localize "STR_NOTF_isrestrained";}; if (player getVariable "playerSurrender") exitWith {hint localize "STR_NOTF_surrender";}; life_action_inUse = true; _zone = ""; _requiredItem = ""; _exit = false; _resourceCfg = missionConfigFile >> "CfgGather" >> "Resources"; for "_i" from 0 to count(_resourceCfg)-1 do { _curConfig = _resourceCfg select _i; _resource = configName _curConfig; _maxGather = getNumber(_curConfig >> "amount"); _zoneSize = getNumber(_curConfig >> "zoneSize"); _resourceZones = getArray(_curConfig >> "zones"); _requiredItem = getText(_curConfig >> "item"); { if ((player distance (getMarkerPos _x)) < _zoneSize) exitWith {_zone = _x;}; } forEach _resourceZones; if (_zone != "") exitWith {}; }; if (_zone isEqualTo "") exitWith {life_action_inUse = false;}; if (_requiredItem != "") then { _valItem = missionNamespace getVariable ["life_inv_" + _requiredItem, 0]; if (_valItem < 1) exitWith { switch (_requiredItem) do { // Messages here }; life_action_inUse = false; _exit = true; }; }; if (_exit) exitWith {life_action_inUse = false;}; _amount = round(random(_maxGather)) + 1; _diff = [_resource, _amount, life_carryWeight, life_maxWeight] call life_fnc_calWeightDiff; if (_diff isEqualTo 0) exitWith { hint localize "STR_NOTF_InvFull"; life_action_inUse = false; }; switch (_requiredItem) do { case "pickaxe": {[player,"mining",35,1] remoteExecCall ["life_fnc_say3D", RCLIENT]}; default {[player,"harvest",35,1] remoteExecCall ["life_fnc_say3D", RCLIENT]}; }; for "_i" from 0 to 4 do { player playMoveNow "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon"; waitUntil {animationState player != "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";}; sleep 0.5; }; if ([true, _resource, _diff] call life_fnc_handleInv) then { _itemName = M_CONFIG(getText, "VirtualItems", _resource, "displayName"); titleText [format [localize "STR_NOTF_Gather_Success", (localize _itemName), _diff], "PLAIN"]; }; sleep 1; life_action_inUse = false; //switch (_code) do { //case 15: { //exitWith { //hint localize "Action Cancelled"; //life_action_inUse = false;} //}; //}; }; To make the script toggle-able, I introduced a variable called autogather and set it to false initially. If you want the script to run automatically, you can set autogather to true. The script runs in a continuous while loop as long as autogather is true. When autogather is false, the script will exit the loop and stop executing. To toggle the script on or off, you can modify the value of autogather manually in your code or create a separate trigger or event to change its value based on specific conditions or player input. Please note that the code provided assumes you have the necessary functions and variables defined elsewhere in your code or mission. You may need to adjust or adapt the code to fit your specific context and requirements. Edit @09:03: Moved the variable declarations (_maxGather, _resource, _amount, _requiredItem) outside the while loop. This is done to prevent re declaration on each iteration of the loop and improve performance. Adjusted the line where _valItem is assigned to missionNamespace.getVariable by using square brackets to access the variable instead of parentheses. Added spaces around the comma in the switch cases to improve code readability. Edited May 20 by KllTA Quote Link to comment Share on other sites More sharing options...
Tex Hasselhoff Posted June 22 Author Share Posted June 22 Been while but I finally found the answer. Looping the code wasn't rocket appliance but, getting the code to stop upon pressing tab wasn't obvious at first. My friend noticed that while gutting an animal, moving around cancelled it. That lead me to find life_interrupted in the fn_key_handler.sqf so, I used that and added Tab (key 15) to the life_interrupted keys in the fn_key_handler.sqf private _interruptionKeys = [17, 30, 31, 32, 15]; //A,S,W,D Heres the raw code I got from fn_gutAnimal.sqf life_interrupted = false; autogather = 1; while {autogather > 0} do { if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; CODE YOU WANT LOOPED UNTIL TAB PRESSED }; Heres my fn_gather.sqf file: #include "..\..\script_macros.hpp" /* File: fn_gather.sqf Author: Devilfloh Description: Main functionality for gathering. */ life_interrupted = false; autogather = 1; while {autogather > 0} do { if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; private ["_maxGather","_resource","_amount","_maxGather","_requiredItem"]; if (life_action_inUse) exitWith {}; if !(isNull objectParent player) exitWith {}; if (player getVariable "restrained") exitWith {hint localize "STR_NOTF_isrestrained";}; if (player getVariable "playerSurrender") exitWith {hint localize "STR_NOTF_surrender";}; life_action_inUse = true; _zone = ""; _requiredItem = ""; _exit = false; _resourceCfg = missionConfigFile >> "CfgGather" >> "Resources"; for "_i" from 0 to count(_resourceCfg)-1 do { _curConfig = _resourceCfg select _i; _resource = configName _curConfig; _maxGather = getNumber(_curConfig >> "amount"); _zoneSize = getNumber(_curConfig >> "zoneSize"); _resourceZones = getArray(_curConfig >> "zones"); _requiredItem = getText(_curConfig >> "item"); { if ((player distance (getMarkerPos _x)) < _zoneSize) exitWith {_zone = _x;}; } forEach _resourceZones; if (_zone != "") exitWith {}; }; if (_zone isEqualTo "") exitWith {life_action_inUse = false;}; if (_requiredItem != "") then { _valItem = missionNamespace getVariable "life_inv_" + _requiredItem; if (_valItem < 1) exitWith { switch (_requiredItem) do { //Messages here }; life_action_inUse = false; _exit = true; }; }; if (_exit) exitWith {life_action_inUse = false;}; if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; _amount = round(random(_maxGather)) + 1; _diff = [_resource,_amount,life_carryWeight,life_maxWeight] call life_fnc_calWeightDiff; if (_diff isEqualTo 0) exitWith { hint localize "STR_NOTF_InvFull"; life_action_inUse = false; }; switch (_requiredItem) do { case "pickaxe": {[player,"mining",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT]}; default {[player,"harvest",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT]}; }; if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; for "_i" from 0 to 4 do { player playMoveNow "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon"; waitUntil{animationState player != "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon";}; sleep 0.5; }; if ([true,_resource,_diff] call life_fnc_handleInv) then { _itemName = M_CONFIG(getText,"VirtualItems",_resource,"displayName"); titleText[format [localize "STR_NOTF_Gather_Success",(localize _itemName),_diff],"PLAIN"]; }; if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; sleep 1; life_action_inUse = false; //switch (_code) do { //case 15: { //exitWith { //hint localize "Action Cancelled"; //life_action_inUse = false;} //}; //}; }; And my fn_mine.sqf file: #include "..\..\script_macros.hpp" /* File: fn_mine.sqf Author: Devilfloh Editor: Dardo Description: Same as fn_gather,but it allows use of probabilities for mining. */ life_interrupted = false; autogather = 1; while {autogather > 0} do { if (life_interrupted) exitWith {life_interrupted = false; titleText[localize "STR_NOTF_ActionCancel","PLAIN"]; life_action_inUse = false;}; private ["_maxGather", "_resource", "_amount", "_requiredItem", "_mined"]; if (life_action_inUse) exitWith {}; if !(isNull objectParent player) exitWith {}; if (player getVariable "restrained") exitWith { hint localize "STR_NOTF_isrestrained"; }; _exit = false; if (player getVariable "playerSurrender") exitWith { hint localize "STR_NOTF_surrender"; }; life_action_inUse = true; _zone = ""; _requiredItem = ""; _resourceCfg = missionConfigFile >> "CfgGather" >> "Minerals"; _percent = (floor random 100) + 1; //Make sure it's not 0 for "_i" from 0 to count(_resourceCfg)-1 do { _curConfig = _resourceCfg select _i; _resources = getArray(_curConfig >> "mined"); _maxGather = getNumber(_curConfig >> "amount"); _zoneSize = getNumber(_curConfig >> "zoneSize"); _resourceZones = getArray(_curConfig >> "zones"); _requiredItem = getText(_curConfig >> "item"); _mined = ""; if (_resources isEqualTo []) exitWith {}; //Smart guy :O for "_i" from 0 to count (_resources) do { if (count _resources isEqualTo 1) exitWith { if (!((_resources select 0) isEqualType [])) then { _mined = _resources select 0; } else { _mined = (_resources select 0) select 0; }; }; _resource = (_resources select _i) select 0; _prob = (_resources select _i) select 1; _probdiff = (_resources select _i) select 2; if ((_percent >= _prob) && (_percent <= _probdiff)) exitWith { _mined = _resource; }; }; { if ((player distance(getMarkerPos _x)) < _zoneSize) exitWith { _zone = _x; }; } forEach _resourceZones; if (_zone != "") exitWith {}; }; if (_zone isEqualTo "") exitWith { life_action_inUse = false; }; if (_requiredItem != "") then { _valItem = missionNamespace getVariable "life_inv_" + _requiredItem; if (_valItem < 1) exitWith { switch (_requiredItem) do { case "pickaxe": { titleText[(localize "STR_NOTF_Pickaxe"), "PLAIN"]; }; }; life_action_inUse = false; _exit = true; }; }; if (_exit) exitWith { life_action_inUse = false; }; _amount = round(random(_maxGather)) + 1; _diff = [_mined, _amount, life_carryWeight, life_maxWeight] call life_fnc_calWeightDiff; if (_diff isEqualTo 0) exitWith { hint localize "STR_NOTF_InvFull"; life_action_inUse = false; }; [player,"mining",35,1] remoteExecCall ["life_fnc_say3D",RCLIENT]; for "_i" from 0 to 4 do { player playMoveNow "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon"; waitUntil { animationState player != "AinvPercMstpSnonWnonDnon_Putdown_AmovPercMstpSnonWnonDnon"; }; sleep 0.5; }; if (([true, _mined, _diff] call life_fnc_handleInv)) then { _itemName = M_CONFIG(getText, "VirtualItems", _mined, "displayName"); titleText[format [localize "STR_NOTF_Mine_Success", (localize _itemName), _diff], "PLAIN"]; }; sleep 2.5; life_action_inUse = false; }; I'm sure theres many other use cases for this and can have multiple life_interrupted variables for different functions including but not limited to: Canceling Processing, capturing an objective, repairing something, or reviving someone. Anyways, I hope some people find this useful and I'll try to post more fixes as I find them. Thank y'all for trying to help and have a great night. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.