[*FIX] Bad spawn item script

Discussion in 'Report a bug' started by Solib, Mar 22, 2018.

  1. Solib

    Solib New Member

    Joined:
    Aug 27, 2017
    Messages:
    8
    Likes Received:
    2
    Relevant for version 0.2.1
    My small thanks to the community
    ------------------------------------------
    1) Open file: @DesolationServer\Addons\Desolation\Server\Loot\fn_spawnLoot.sqf
    2) Search this code:
    Code:
    // TODO: fix this shit code
                    if(isClass (configFile >> "CfgWeapons" >> _item)) then {
                        if((toLower(_item) find "tacs_" == 0) || (toLower(_item) find "item" == 0) || (toLower(_item) find "h_" == 0) || (toLower(_item) find "u_" == 0) || (toLower(_item) find "v_" == 0) || (toLower(_item) find "minedetector" == 0) || (toLower(_item) find "binocular" == 0) || (toLower(_item) find "rangefinder" == 0) || (toLower(_item) find "NVGoggles" == 0) || (toLower(_item) find "laserdesignator" == 0) || (toLower(_item) find "firstaidkit" == 0) || (toLower(_item) find "medkit" == 0) || (toLower(_item) find "toolkit" == 0) || (toLower(_item) find "muzzle_" == 0) || (toLower(_item) find "optic_" == 0) || (toLower(_item) find "acc_" == 0) || (toLower(_item) find "bipod_" == 0)) then {
                            _object addItemCargoGlobal [_item,1];
                        } else {
                            if(toLower(_type) in ["handgun","weapon"]) then {
                                _chance = ["ChanceToSpawnWithMag"] call DS_fnc_getCfgValue;
                                if(random(100) < _chance) then {
                                    _mags = getArray(configFile >> "CfgWeapons" >> _item >> "Magazines");
                                    _mag = _mags select floor(random(count(_mags)));
                                    _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _mag >> "count");
                                    _object addMagazineAmmoCargo [_mag,1,ceil(random(_maxAmmo))];
                                    _i = _i + 1;
                                };
                            };
                            _object addWeaponCargoGlobal [_item,1];
                        };
                    };
            
                    if(isClass (configFile >> "CfgVehicles" >> _item)) then {
                        _object addBackpackCargoGlobal [_item,1];
                    };
            
                    if(isClass (configFile >> "cfgGlasses" >> _item)) then {
                        _object addItemCargoGlobal [_item,1];
                    };
            
                    if(isClass (configFile >> "CfgMagazines" >> _item)) then {
                        _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _item >> "count");
                        _object addMagazineAmmoCargo [_item,1,ceil(random(_maxAmmo))];
                    };
    
    3) Replace with:
    Code:
    _typeItem = _item call DS_fnc_itemType;
                    switch (_typeItem) do
                    {
                        case "Weapon":  {
                            if(toLower(_type) in ["handgun","weapon"]) then {
                                _chance = ["ChanceToSpawnWithMag"] call DS_fnc_getCfgValue;
                                if(random(100) < _chance) then {
                                    _mags = getArray(configFile >> "CfgWeapons" >> _item >> "Magazines");
                                    _mag = _mags select floor(random(count(_mags)));
                                    _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _mag >> "count");
                                    _object addMagazineAmmoCargo [_mag,1,ceil(random(_maxAmmo))];
                                    diag_log format ["<ActionSystem>: (Debug) spawnLoot addMagazineAmmoCargo CfgWeapons = %1", _item];
                                    _i = _i + 1;
                                };
                            };
    _object addWeaponCargoGlobal [_item,1];
                        };
                
                        case "Backpack":     {
                            _object addBackpackCargoGlobal [_item, 1];
                        };
                
                        case "Magazine":     {
                            _maxAmmo = getNumber(configFile >> "CfgMagazines" >> _item >> "count");
                            _object addMagazineAmmoCargo [_item,1,ceil(random(_maxAmmo))];
                        };
                
                        default             {
                            _object addItemCargoGlobal [_item, 1];
                        };
                    };
    4) Save file and close
    5) Create new file (@DesolationServer\Addons\Desolation\Server\Loot\fn_typeItem.sqf)
    Code:
    /*
    fn_typeItem.sqf
    */
    private["_itemClassName","_cargoType","_itemType"];
    _itemClassName = _this;
    _cargoType = "Item";
    _itemType = [_itemClassName] call BIS_fnc_itemType;
    switch( _itemType select 0) do
    {
        case "Equipment":     { _cargoType = _itemType select 1; };
        default                { _cargoType = _itemType select 0 };
    };
    _cargoType
    6) Open (@DesolationServer\Addons\Desolation\config.cpp)
    7) Search code
    Code:
    class Server_Loot {
                file = "Desolation\Server\Loot";
                isserver = 1;
                class lootManager {};
                class spawnLoot {};
                class setLoot {};
                class getLoot {};
                class despawnLoot {};
            };
    8) Replace with:
    Code:
    class Server_Loot {
                file = "Desolation\Server\Loot";
                isserver = 1;
                class lootManager {};
                class spawnLoot {};
                class setLoot {};
                class getLoot {};
                class despawnLoot {};
                class typeItem {};
            };
    9) Pack new pbo Desolation.pbo

    10) PROFIT - All items spawning and no errors
     
    Last edited: Apr 14, 2018
    Legodev likes this.
  2. Legodev

    Legodev Developer Staff Member

    Joined:
    Jul 18, 2016
    Messages:
    349
    Likes Received:
    114
    Thank you very much for this bugfix! :)
     
  3. Solib

    Solib New Member

    Joined:
    Aug 27, 2017
    Messages:
    8
    Likes Received:
    2
    Who has already applied the correction, I apologize. I made a mistake. You need to copy the new code from step 3
     
  4. YourDaddy

    YourDaddy Member

    Joined:
    Jul 25, 2017
    Messages:
    59
    Likes Received:
    4
    Hello, in Step 1 is no filename im path....
     
  5. Solib

    Solib New Member

    Joined:
    Aug 27, 2017
    Messages:
    8
    Likes Received:
    2
    filename fn_spawnLoot.sqf
     

Share This Page