Drink Water v2.0

tested this script working in the editor. So its working, finding the objects, and firing the action. Suggest you simplify your script until its working then add the different 'features' until you find what is broken. Start with a simple addaction to replace all your _candrink stuff just to make sure the basic addaction is working in that location. Then add in the _candrink codes .. While I am sure you are completely capable, if you want me to take a look at your mission files, I would be glad to help.

Here is what I did to test it.
this is my init.sqf
Code:
//this initialized the selfactions handle.  This should be in your variables.sqf 
s_player_drinkWater = -1;

//these two lines were required to find the _pond and _well words in the found objects.  These I copied out of the compiles.sqf so they are surely correct (I changed the locations to the local folder)
fnc_param =    compile preprocessFileLineNumbers "fn_param.sqf";
fnc_inString =     compile preprocessFileLineNumbers "fn_inString.sqf";

//this is my selfactions file 
execvm "selfactions.sqf";

This is the code that you pasted onto the bottom of your selfactions. All I did was add the while{true} loop so it keeps testing, and I edited the addaction line to a simple "Drink"
Code:
private["_playerPos","_canDrink","_isPond","_isWell","_pondPos","_objectsWell","_objectsPond","_display"];

 while {true} do{
_playerPos = getPosATL player;
_canDrink = count nearestObjects [_playerPos, ["Land_pumpa","Land_water_tank"], 4] > 0;
_isPond = false;
_isWell = false;
_pondPos = [];
_objectsWell = [];

if (!_canDrink) then {
    _objectsWell = nearestObjects [_playerPos, [], 4];
    {
        //Check for Well
        _isWell = ["_well",str(_x),false] call fnc_inString;
        if (_isWell) then {_canDrink = true};
    } forEach _objectsWell;
};

if (!_canDrink) then {
    _objectsPond = nearestObjects [_playerPos, [], 50];
    {
        //Check for pond
        _isPond = ["pond",str(_x),false] call fnc_inString;
        if (_isPond) then {
            _pondPos = (_x worldToModel _playerPos) select 2;
            if (_pondPos < 0) then {
                _canDrink = true;
            };
        };
    } forEach _objectsPond;
};

if (_canDrink) then {
        if (s_player_drinkWater < 0) then {
            s_player_drinkWater = player addaction[("Drink"),"drink_water.sqf"];
        };
    } else {
        player removeAction s_player_drinkWater;
        s_player_drinkWater = -1;
    };
sleep 2;
    };

 
Back
Top