Crazy Mike

Consuming Can of Food returns 1 empty can

15 posts in this topic

ExileClient_object_item_consume

Spoiler

/**
 * ExileClient_object_item_consume
 *
 * Exile Mod
 * www.exilemod.com
 * © 2015 Exile Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 */
 
private["_itemClassName","_consumingConfig","_configEffects","_feedbackString","_effectAttributeId","_effectValue","_effectDuration","_effectUnit","_effect","_addPlusCharacter","_bloodAlcohol","_bloodAlcoholComment","_animations","_animationIndex","_stopBleeding","_configSounds","_numberOfConfigSounds","_returnItemClass"];
_itemClassName = _this select 0;
if !(_itemClassName in (magazines player)) exitWith {false};
if( isClass(configFile >> "CfgMagazines" >> _itemClassName >> "Interactions" >> "Consuming") ) then
{
    _consumingConfig = configFile >> "CfgMagazines" >> _itemClassName >> "Interactions" >> "Consuming";
    _configEffects = getArray (_consumingConfig >> "effects");
    _feedbackString = "";
    {
        _effectAttributeId = _x select 0;
        _effectValue = _x select 1;
        _effectDuration = _x select 2;
        _effectUnit = if (_effectAttributeId isEqualTo 4) then {"‰"} else {"%"};
        _effect = 
        [
            _effectAttributeId,
            _effectValue, 
            _effectDuration, 
            time, 
            _effectValue 
        ];
        _addPlusCharacter = if (_effectValue > 0) then { "+" } else { "" };
        if( _effectDuration == 0 ) then 
        {
            _feedbackString = _feedbackString + format["%1: %2%3%4<br/>", (ExileClientPlayerEffectNames select _effectAttributeId), _addPlusCharacter, _effectValue, _effectUnit];
        }
        else 
        {
            _feedbackString = _feedbackString + format["%1: %2%3%4/%5s<br/>", (ExileClientPlayerEffectNames select _effectAttributeId), _addPlusCharacter, _effectValue, _effectUnit, _effectDuration];
        };
        if (_effectAttributeId isEqualTo 4) then
        {
            _bloodAlcohol = (ExileClientPlayerAttributes select 4);
            _bloodAlcohol = (_bloodAlcohol + _effectValue) max 0;
            ExileClientPlayerAttributes set [4, _bloodAlcohol];
            if (_bloodAlcohol > 0) then 
            {
                _bloodAlcoholComment = "You feel tipsy.";
                if (_bloodAlcohol >= 3) then
                {
                    _bloodAlcoholComment = "You are drunk as a skunk.";
                }
                else 
                {
                    if (_bloodAlcohol >= 2) then
                    {
                        _bloodAlcoholComment = "You are boozed-up.";
                    }
                    else 
                    {
                        if (_bloodAlcohol >= 1) then
                        {
                            _bloodAlcoholComment = "You are drunk.";
                        };
                    };
                };
                systemChat format["Your blood alcohol level is now %1%2. %3", _bloodAlcohol, "‰", _bloodAlcoholComment];
            };
            if (ExileClientDeliriumThread isEqualTo -1) then
            {
                call ExileClient_object_player_thread_delirium;
                ExileClientDeliriumThread = [20, ExileClient_object_player_thread_delirium, [], true] call ExileClient_system_thread_addtask;
            };
        }
        else 
        {
            ExileClientPlayerEffects pushBack _effect;
        };    
    } 
    foreach _configEffects;
    _animations = getArray (_consumingConfig >> "animations");
    if !(_animations isEqualTo []) then
    {
        if ((vehicle player) isEqualTo player) then 
        {
            _animationIndex = call ExileClient_util_animation_getMatrixIndex;
            player playMove (_animations select _animationIndex);
        };
    };
    _stopBleeding = getNumber (_consumingConfig >> "stopBleeding");
    if (_stopBleeding isEqualTo 1) then
    {
        player setBleedingRemaining 0;
    };
    _configSounds = getArray (_consumingConfig >> "sounds");
    _numberOfConfigSounds = count _configSounds;
    if( _numberOfConfigSounds > 0 ) then
    {
        playSound (_configSounds select (floor (random _numberOfConfigSounds)));
    };
    player removeItem _itemClassName;
    _returnItemClass = getText (_consumingConfig >> "returnedItem");
    if( _returnItemClass != "" ) then
    {
        player addItem _returnItemClass;
    };
    if( _feedbackString != "") then
    {
        ["SuccessTitleAndText", ["Consumed item!", _feedbackString]] call ExileClient_gui_toaster_addTemplateToast;
    };
};
true

I see at the bottom returnitem, can someone give me any insight on how I could utilize this to give players an empty can after they have eaten a can of food?

Share this post


Link to post
Share on other sites

I wouldn't use the default code in there because it's expecting to find "returnedItems" in the config, and it looks like Exile hasn't implemented that yet.

class Interactions
{
	class Consuming: Exile_AbstractItem_Interaction_Eating_Can
	{
		effects[] =
		{
			{ATTRIBUTE_HUNGER, 40, 60}
		};
	};
};

 I wouldn't be surprised that this will be added sometime in the future. 

 

In the meantime, you could put checks in there to see if the classname is in an array of items that are cans, then add a empty can to the player's inventory. I highly suggest putting a check in there because you will end up giving someone an empty can no matter what they consume. 

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement
16 minutes ago, WolfkillArcadia said:

I wouldn't use the default code in there because it's expecting to find "returnedItems" in the config, and it looks like Exile hasn't implemented that yet.


class Interactions
{
	class Consuming: Exile_AbstractItem_Interaction_Eating_Can
	{
		effects[] =
		{
			{ATTRIBUTE_HUNGER, 40, 60}
		};
	};
};

 I wouldn't be surprised that this will be added sometime in the future. 

 

In the meantime, you could put checks in there to see if the classname is in an array of items that are cans, then add a empty can to the player's inventory. I highly suggest putting a check in there because you will end up giving someone an empty can no matter what they consume. 

I just have to figure out how to edit in to check for a list of items consumed to return another item aka empty cans, trust me when i say i know near nothing and have to learn, most of my edits so far have been monkey see monkey do, either a point to another file that i can look to see a similar function or a straight example would be really appreciated

Edited by Crazy Mike

Share this post


Link to post
Share on other sites
43 minutes ago, Crazy Mike said:

I just have to figure out how to edit in to check for a list of items consumed to return another item aka empty cans, trust me when i say i know near nothing and have to learn, most of my edits so far have been monkey see monkey do, either a point to another file that i can look to see a similar function or a straight example would be really appreciated

A couple of commands you can use to do this is:
https://community.bistudio.com/wiki/in
https://community.bistudio.com/wiki/find

Example using "in":

Spoiler

// Using "in"
_classname = "ITEM2";
_array = ["ITEM1","ITEM2","ITEM3"];

if (_classname in _array) then 
{
	systemChat "Classname is inside array";
};

// This will return Classname is inside array. 

 

Example using "find":

Spoiler

// Using "find"

_classname = "ITEM3";
_array = ["ITEM1,"ITEM2","ITEM3"];

_index = _array find _classname;

if (_index > -1) then 
{
	systemChat format["Classname found, located at index: %1",_index];
};

// This will return "Classname found, located at index: 2"

 

Find is more useful if you need the index so you can modify the array, but it will work in this context. 

I suggest using "in" as that it's a bit easier to use and will give you what you need, I just wanted to give you a couple of options. 

1 person likes this

Share this post


Link to post
Share on other sites
4 minutes ago, WolfkillArcadia said:

A couple of commands you can use to do this is:
https://community.bistudio.com/wiki/in
https://community.bistudio.com/wiki/find

Example using "in":

  Hide contents


// Using "in"
_classname = "ITEM2";
_array = ["ITEM1","ITEM2","ITEM3"];

if (_classname in _array) then 
{
	systemChat "Classname is inside array";
};

// This will return Classname is inside array. 

 

Example using "find":

  Hide contents


// Using "find"

_classname = "ITEM3";
_array = ["ITEM1,"ITEM2","ITEM3"];

_index = _array find _classname;

if (_index > -1) then 
{
	systemChat format["Classname found, located at index: %1",_index];
};

// This will return "Classname found, located at index: 2"

 

Find is more useful if you need the index so you can modify the array, but it will work in this context. 

I suggest using "in" as that it's a bit easier to use and will give you what you need, I just wanted to give you a couple of options. 

i can definatly work with this, thanks for the pointer

Share this post


Link to post
Share on other sites

this is currently what ive turned your example into

Spoiler

_classname = "Exile_Item_Catfood";
    _array = ["Exile_Item_Can_Empty"];
    if (_classname in _array) then 
    {
        _weaponHolderA = createVehicle ["GroundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; 
        _weaponHolderA addItemCargoGlobal ["Exile_Item_Can_Empty", 1];
    };

it doesnt work but i can probably see a few reasons why, i think that _classname and _array both need names to start?

 

edit: thought a bit and changed to this

Spoiler

_classname = "Exile_Item_Catfood";
    _test2 = ["Exile_Item_Catfood"];
    if (_classname in getArray (_test2)) then 
    {
        _weaponHolderA = createVehicle ["GroundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; 
        _weaponHolderA addItemCargoGlobal ["Exile_Item_Can_Empty", 1];
    };

2nd doesnt have any effect, unless the ground holder is what i messed up

Edited by Crazy Mike

Share this post


Link to post
Share on other sites
Just now, BetterDeadThanZed said:

I thought eating food from a can already returned an empty can.

tried eating all cans cooked and raw this morning and it didnt spawn one on the ground or inventory

Share this post


Link to post
Share on other sites
17 minutes ago, Crazy Mike said:

this is currently what ive turned your example into

  Reveal hidden contents

_classname = "Exile_Item_Catfood";
    _array = ["Exile_Item_Can_Empty"];
    if (_classname in _array) then 
    {
        _weaponHolderA = createVehicle ["GroundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; 
        _weaponHolderA addItemCargoGlobal ["Exile_Item_Can_Empty", 1];
    };

it doesnt work but i can probably see a few reasons why, i think that _classname and _array both need names to start?

 

edit: thought a bit and changed to this

  Hide contents

_classname = "Exile_Item_Catfood";
    _test2 = ["Exile_Item_Catfood"];
    if (_classname in getArray (_test2)) then 
    {
        _weaponHolderA = createVehicle ["GroundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"]; 
        _weaponHolderA addItemCargoGlobal ["Exile_Item_Can_Empty", 1];
    };

2nd doesnt have any effect, unless the ground holder is what i messed up

First example: It is running, your classnames are different so that if then is getting a false returned, IE it will ignore whatever is in it. Also _pos hasn't been defined. 

Second example, you don't have _pos defined anywhere. It's not going to know what that is. Also, getArray is reserved for configFile accessing. _test2 is already an array, I've corrected your code below. I tested this out in game and it works. 

_classname = "Exile_Item_Catfood";
_array = ["Exile_Item_Catfood"];
_pos = getPosATL player;
if (_classname in _array) then 
{
	_lootHolder = createVehicle ["GroundWeaponHolder",_pos,[],3,"CAN_COLLIDE"];
    _lootHolder setPosATL _pos;
    _lootHolder addMagazineCargoGlobal ["Exile_Item_Can_Empty",1];
};

 

1 person likes this

Share this post


Link to post
Share on other sites
2 minutes ago, WolfkillArcadia said:

First example: It is running, your classnames are different so that if then is getting a false returned, IE it will ignore whatever is in it. Also _pos hasn't been defined. 

Second example, you don't have _pos defined anywhere. It's not going to know what that is. Also, getArray is reserved for configFile accessing. _test2 is already an array, I've corrected your code below. I tested this out in game and it works. 


_classname = "Exile_Item_Catfood";
_array = ["Exile_Item_Catfood"];
_pos = getPosATL player;
if (_classname in _array) then 
{
	_lootHolder = createVehicle ["GroundWeaponHolder",_pos,[],3,"CAN_COLLIDE"];
    _lootHolder setPosATL _pos;
    _lootHolder addMagazineCargoGlobal ["Exile_Item_Can_Empty",1];
};

 

alright that looks much better then what i did, if i have any more questions ill be sure to come bug the shit out of you, thanks again :P

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.