PLS Help - Need a knife to open a foodcan

Silver85

Member
Hello everyone,

maybe there is someone around to help me getting this to work. I m not good in scripting.
Like i said above i want to force players to have a knife for open/eat a foodcan. In addition to that i want to have a chance of 40% that the knife can break while open the can. I m searching around the code and find the player_eat.sqf. I modified it like this but i m not able to get this to work. Nothing happen after i clicked on eat ingame. Thanks in advance..

Code:
private ["_onLadder","_itemorignal","_hasfooditem","_rawfood","_hasoutput","_config","_text","_regen","_dis","_sfx","_itemtodrop","_nearByPile","_item","_display","_rawexceptions","_badfood","_invehicle"];
disableserialization;
call gear_ui_init;
_onLadder =        (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
if (_onLadder) exitWith {cutText [(localize "str_player_21") , "PLAIN DOWN"]};
 
//if (vehicle player != player) exitWith {cutText ["\n\nYou may not eat while in a vehicle", "PLAIN DOWN"]};
 
//Force players to wait 3 mins to eat again
//if (dayz_lastMeal < 180) exitWith {cutText ["You may not eat, you're already full", "PLAIN DOWN"]};
 
_itemorignal = _this;
_hasfooditem = _itemorignal in magazines player;
_rawfood = _itemorignal in meatraw;
_rawexceptions = _itemorignal in exceptionsraw;
_hasoutput = _itemorignal in food_with_output;
_badfood = _itemorignal in badfood;
_config =   configFile >> "CfgMagazines" >> _itemorignal;
_text =     getText (_config >> "displayName");
_regen =     getNumber (_config >> "bloodRegen");
 
_needknife = _itemorignal in food_need_knife;
_hasknife =  "ItemKnife" in _itemsPlayer;
_chance = floor(random 100);
 
if (!_hasfooditem) exitWith {cutText [format[(localize "str_player_31"),_text,"consume"] , "PLAIN DOWN"]};
 
if (_hasfooditem && _needknife) then {
    if (_hasknife) then {
        if (_chance > 40) then {
            player removeWeapon "ItemKnife";
            cutText ["The knife breaks. You couldnt open the can." , "PLAIN DOWN"];
        } else {
            player playActionNow "PutDown";
            player removeMagazine _itemorignal;
 
            _invehicle = false;
            if (vehicle player != player) then {
                _display = findDisplay 106;
                _display closeDisplay 0;
                _invehicle = true;
            };
 
            sleep 1;
 
            _dis=6;
            _sfx = "eat";
            [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
            [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
            if (_hasoutput and !_invehicle) then {
                // Selecting output
                _itemtodrop = food_output select (food_with_output find _itemorignal);
 
                sleep 3;
                _nearByPile= nearestObjects [(getposATL player), ["WeaponHolder","WeaponHolderBase"],2];
                if (count _nearByPile ==0) then {
                    _iPos = getPosATL player;
                    _radius = 0.0;
                    _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
                    _item setposATL _iPos;
                } else {
                    _item = _nearByPile select 0;
                };
                _item addMagazineCargoGlobal [_itemtodrop,1];
            };
       
            if (_badfood and (random 2 < 1)) then {
            r_player_infected = true;
            player setVariable["USEC_infected",true,true];
            };
       
            r_player_blood = r_player_blood + _regen;
            if (r_player_blood > r_player_bloodTotal) then {
            r_player_blood = r_player_bloodTotal;
            };
       
            player setVariable ["messing",[dayz_hunger,dayz_thirst],true];
            player setVariable["USEC_BloodQty",r_player_blood,true];
            player setVariable["medForceUpdate",true];
 
            //["PVDZE_plr_Save",[player,[],true]] call callRpcProcedure;
            PVDZE_plr_Save = [player,[],true,true];
            publicVariableServer "PVDZE_plr_Save";
 
            dayz_lastMeal =    time;
            dayz_hunger = 0;
 
            //Ensure Control is visible
            _display = uiNamespace getVariable 'DAYZ_GUI_display';
            (_display displayCtrl 1301) ctrlShow true;
 
            if (r_player_blood / r_player_bloodTotal >= 0.2) then {
            (_display displayCtrl 1300) ctrlShow true;
            };
            cutText [format[(localize  "str_player_consumed"),_text], "PLAIN DOWN"];
        };
    } else {
        cutText ["Uff..i m not able to open the can.", "PLAIN DOWN"]
    };
} else {
 
    if (_rawfood and !_rawexceptions and (random 15 < 1)) then {
    r_player_infected = true;
    player setVariable["USEC_infected",true,true];
    };
 
    if (_badfood and (random 2 < 1)) then {
    r_player_infected = true;
    player setVariable["USEC_infected",true,true];
    };
 
    r_player_blood = r_player_blood + _regen;
    if (r_player_blood > r_player_bloodTotal) then {
    r_player_blood = r_player_bloodTotal;
    };
 
    player setVariable ["messing",[dayz_hunger,dayz_thirst],true];
    player setVariable["USEC_BloodQty",r_player_blood,true];
    player setVariable["medForceUpdate",true];
 
    //["PVDZE_plr_Save",[player,[],true]] call callRpcProcedure;
    PVDZE_plr_Save = [player,[],true,true];
    publicVariableServer "PVDZE_plr_Save";
 
    dayz_lastMeal =    time;
    dayz_hunger = 0;
 
    //Ensure Control is visible
    _display = uiNamespace getVariable 'DAYZ_GUI_display';
    (_display displayCtrl 1301) ctrlShow true;
 
    if (r_player_blood / r_player_bloodTotal >= 0.2) then {
    (_display displayCtrl 1300) ctrlShow true;
    };
    cutText [format[(localize  "str_player_consumed"),_text], "PLAIN DOWN"];
};
 
food_need_knife;
I don't see this being referenced anywhere, but what I understand is that like with
food_with_output
and some of the others, they are referenced in another file. Also, are you fully re-routing this file, complete with compiles and everything? If not it won't work.
 
Hey Matt and thanks for your reply,

of course i have defined "food_need_knife" in variables first and i changed the path in compiles.
I think there is something wrong with my code but i dont see it.
 
You can feel free to add me on skype and i'll take a look at your mission pbo later tonight if you'd life
 
Its definitive the code. I tested it again. When i reroute my player_eat.sqf then i m not able to eat a can - nothing happen when i click the can and press "eat food". But none-can-food like tuna, pistachios is working..i only miss the "put down" animation..but should not be a problem.
 
Got it. If somebody is interested in here you go:

In variables.sqf add:
Code:
food_need_knife=[
    "FoodCanBakedBeans",
    "FoodCanSardines",
    "FoodCanFrankBeans",
    "FoodCanPasta",
    "FoodCanGriff",
    "FoodCanBadguy",
    "FoodCanBoneboy",
    "FoodCanCorn",
    "FoodCanCurgon",
    "FoodCanDemon",
    "FoodCanFraggleos",
    "FoodCanHerpy",
    "FoodCanOrlok",
    "FoodCanPowell",
    "FoodCanTylers",
    "FoodCanUnlabeled"
];

in compiles search for:

player_eat = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\player_eat.sqf";

change it to:

player_eat = compile preprocessFileLineNumbers "YOUR FOLDER\player_eat.sqf";

player_eat.sqf
Code:
private ["_onLadder","_itemorignal","_hasfooditem","_rawfood","_hasoutput","_config","_text","_regen","_dis","_sfx","_itemtodrop","_nearByPile","_item","_display","_rawexceptions","_badfood","_invehicle"];
disableserialization;
call gear_ui_init;
_onLadder =        (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
if (_onLadder) exitWith {cutText [(localize "str_player_21") , "PLAIN DOWN"]};

_itemorignal = _this;
_hasfooditem = _itemorignal in magazines player;

_rawfood = _itemorignal in meatraw;
_rawexceptions = _itemorignal in exceptionsraw;
_hasoutput = _itemorignal in food_with_output;
_badfood = _itemorignal in badfood;

_itemsPlayer = items player;
_needknife = _itemorignal in food_need_knife;
_hasknife =  "ItemKnife" in _itemsPlayer;
_chance = floor(random 100);

_config =   configFile >> "CfgMagazines" >> _itemorignal;
_text =     getText (_config >> "displayName");
_regen =     getNumber (_config >> "bloodRegen");

if (!_hasfooditem) exitWith {cutText [format[(localize "str_player_31"),_text,"consume"] , "PLAIN DOWN"]};

if (_needknife) then {
    if (_hasknife) then {
        player playActionNow "Medic";
        sleep 6;
        if (_chance < 41) then {
            player removeWeapon "ItemKnife";
            cutText [format["Fuck, I have broken my knife."], "PLAIN DOWN"];
        } else {
            player removeMagazine _itemorignal;
            _invehicle = false;
            if (vehicle player != player) then {
                _display = findDisplay 106;
                _display closeDisplay 0;
                _invehicle = true;
            };
            _dis=6;
            _sfx = "eat";
            [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
            [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
            if (_hasoutput and !_invehicle) then {
                _itemtodrop = food_output select (food_with_output find _itemorignal);
                sleep 3;
                _nearByPile= nearestObjects [(getposATL player), ["WeaponHolder","WeaponHolderBase"],2];
                if (count _nearByPile ==0) then {
                    _iPos = getPosATL player;
                    _radius = 0.0;
                    _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
                    _item setposATL _iPos;
                    } else {
                        _item = _nearByPile select 0;
                    };
                _item addMagazineCargoGlobal [_itemtodrop,1];
            };
            if (_badfood and (random 2 < 1)) then {
                r_player_infected = true;
                player setVariable["USEC_infected",true,true];
            };
            r_player_blood = r_player_blood + _regen;
            if (r_player_blood > r_player_bloodTotal) then {
                r_player_blood = r_player_bloodTotal;
            };
            player setVariable ["messing",[dayz_hunger,dayz_thirst],true];
            player setVariable["USEC_BloodQty",r_player_blood,true];
            player setVariable["medForceUpdate",true];
            PVDZE_plr_Save = [player,[],true,true];
            publicVariableServer "PVDZE_plr_Save";
            dayz_lastMeal =    time;
            dayz_hunger = 0;
            _display = uiNamespace getVariable 'DAYZ_GUI_display';
            (_display displayCtrl 1301) ctrlShow true;
            if (r_player_blood / r_player_bloodTotal >= 0.2) then {
                (_display displayCtrl 1300) ctrlShow true;
            };
            cutText [format[(localize  "str_player_consumed"),_text], "PLAIN DOWN"];
        };
    } else {
        cutText [format["Uff..i could not open the can. I need to find a knife."], "PLAIN DOWN"];
    };
} else {
    player playActionNow "PutDown";
    player removeMagazine _itemorignal;

    _invehicle = false;
    if (vehicle player != player) then {
        _display = findDisplay 106;
        _display closeDisplay 0;
        _invehicle = true;
    };

    sleep 1;

    _dis=6;
    _sfx = "eat";
    [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
    [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
   
    if (_rawfood and !_rawexceptions and (random 15 < 1)) then {
        r_player_infected = true;
        player setVariable["USEC_infected",true,true];
    };

    if (_badfood and (random 2 < 1)) then {
        r_player_infected = true;
        player setVariable["USEC_infected",true,true];
    };

    r_player_blood = r_player_blood + _regen;
    if (r_player_blood > r_player_bloodTotal) then {
        r_player_blood = r_player_bloodTotal;
    };

    player setVariable ["messing",[dayz_hunger,dayz_thirst],true];
    player setVariable["USEC_BloodQty",r_player_blood,true];
    player setVariable["medForceUpdate",true];

    PVDZE_plr_Save = [player,[],true,true];
    publicVariableServer "PVDZE_plr_Save";

    dayz_lastMeal =    time;
    dayz_hunger = 0;

    _display = uiNamespace getVariable 'DAYZ_GUI_display';
    (_display displayCtrl 1301) ctrlShow true;

    if (r_player_blood / r_player_bloodTotal >= 0.2) then {
        (_display displayCtrl 1300) ctrlShow true;
    };
   
    cutText [format[(localize  "str_player_consumed"),_text], "PLAIN DOWN"];
};

This is making the mod a lil bit more tricky. Opening a can should not be so easy..:)
 
Back
Top