Français Traitement d'objet virtuel vers un objet physique

  • Auteur de la discussion Auteur de la discussion MaKKo
  • Date de début Date de début

MaKKo

User
29/12/19
194
15
12
1 300
Bienvenue sur ce tutoriel qui vous permettra de transformer un objet virtuel en un objet physique via un traitement.
Ce tutoriel fait suite à la demande d'aide de A Aiden .

C'est parti !

Dans votre mission/config, créer un fichier Config_ProcessVirtToPhysical.hpp avec:

Code:
/*
    Maxence
*/
class VirtualToPhysical_Processing {
    class ExampleProcess {
        object_required = "toolkit";
        object_given = "TheProgrammer_cailloux";
        text = "Traitement d'un truc";
        time = 45;
        required_licenses[] = {"license_civ_driver"};
    };
};

A la fin de votre Config_Master.hpp (du dossier config), ajoutez :
Code:
#include "Config_ProcessVirtToPhysical.hpp"

Dans votre mission/core/actions, créez un fichier fn_processVirtToPhysical.sqf avec :
Code:
#include "..\..\script_macros.hpp"
/*
    Maxence
*/
params ["_target", "_caller", "_actionId", "_type"];

_config = missionConfigFile >> "VirtualToPhysical_Processing";

if (life_action_inUse || (life_is_processing) || (_type isEqualTo "")) exitWith {};
if !(isClass (_config >> _type)) exitWith {};
if (_caller distance _target > 10) exitWith {hint localize "STR_ISTR_Lock_TooFar"};

_exit = false;
_config = _config >> _type;

_materialsRequired = getText (_config >> "object_required");
_materialsGiven = getText (_config >> "object_given");

_upp = getText (_config >> "text");
_time = getNumber (_config >> "time");
_license = getArray (_config >> "required_licenses");

if ((count _license) >= 1) then {
    {
        if (_x != "") then {
            if !(missionNamespace getVariable [_x,false]) exitWith {_exit = true};
        };
    } forEach _license;
};

if (_exit) exitWith {hint localize "STR_Shop_Veh_NoLicense"};

_amount = ITEM_VALUE(_materialsRequired);
if (_amount isEqualTo 0) exitWith {hint localize "STR_NOTF_NotEnoughItemProcess"};
 
disableSerialization;
"progressBar" cutRsc ["life_progress","PLAIN"];
_ui = uiNamespace getVariable "life_progress";
_progress = _ui displayCtrl 38201;
_pgText = _ui displayCtrl 38202;
_pgText ctrlSetText format ["%2 (1%1)...","%",_upp];
_progress progressSetPosition 0.01;
_cP = 0.01;

life_is_processing = true;
life_action_inUse = true;

for "_i" from 0 to 1 step 0 do {
    uiSleep (_time / 100);
    _cP = _cP + 0.01;
    _progress progressSetPosition _cP;
    _pgText ctrlSetText format ["%3 (%1%2)...",round(_cP * 100),"%",_upp];
    if (_cP >= 1) exitWith {};
    if (_caller distance _target > 10) exitWith {
        hint localize "STR_Process_Stay";
        life_is_processing = false;
    };
};

"progressBar" cutText ["","PLAIN"];

if (life_is_processing) then {
    _itemSpace = getNumber (configFile >> "cfgWeapons" >> _materialsGiven >> "ItemInfo" >> "mass");
    _maxWeightPlayer = 0;
 
    _maxUniform = getContainerMaxLoad uniform player;
    _maxVest = getContainerMaxLoad vest player;
    _maxBackpack = getContainerMaxLoad backpack player;

    if (_maxUniform > 0) then {
        _maxWeightPlayer = _maxWeightPlayer + _maxUniform;
    };

    if (_maxVest > 0) then {
        _maxWeightPlayer = _maxWeightPlayer + _maxVest;
    };

    if (_maxBackpack > 0) then {
        _maxWeightPlayer = _maxWeightPlayer + _maxBackpack;
    };

    _curentMass = (loadVest player * _maxUniform) + (loadBackpack player * _maxBackpack) + (loadUniform player * _maxUniform);

    _objectToAdd = _amount;
    if (_itemSpace > 0) then {
        _objectToAdd = (floor ((_maxWeightPlayer - _curentMass) / _itemSpace)) min _amount;
    };

    if (_maxWeightPlayer isEqualTo 0) exitWith {hint "Unable to retrieve the player's inventory"};
    if (_objectToAdd isEqualTo 0) exitWith {hint localize "STR_NOTF_InvFull"};

    [false,_materialsRequired,_objectToAdd] call life_fnc_handleInv;

    for "_i" from 1 to _objectToAdd do {
        player addItem _materialsGiven;
    };

    titleText [localize "STR_NOTF_ItemProcess","PLAIN"];
    [0] call SOCK_fnc_updatePartial;
};

life_action_inUse = false;
life_is_processing = false;

Et dans ton Functions.hpp sous file = "core\actions"; ajoutez cette ligne :
Code:
class processVirtToPhysical {};

Pour votre mapping, il faudra mettre cet init :
Code:
this addAction["Traitement d'un truc",life_fnc_processVirtToPhysical,"ExampleProcess"];

Il ne vous reste plus qu'a configurer ton traitement avec des objets virtuels en entrée et des objets physiques en sortie

Merci à Maxence Maxence pour le tutoriel.


Et voilà !
 
  • Like
  • Muscle
Les réactions: Demon et ToMA3