Advertisement
Tricky_Fat_Cat

GM2_LootSystem_GetObjectToSpawn

Nov 1st, 2019
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @param lootTable
  2.  
  3. var _lootTable = argument0;
  4.  
  5. var _result;
  6. var _objectData;
  7. var _maxWeight = 0;
  8.  
  9. var _arrayLength = array_length_1d(_lootTable);
  10. var _lootWeight = SetLootWeight(_lootTable);
  11.  
  12. var _diceRoll = irandom_range(1, _lootWeight);
  13.  
  14. for (var i = 0; i < _arrayLength; i++)
  15. {
  16.     _objectData = _lootTable[i];
  17.    
  18.     var _object = _objectData [? "object"];
  19.     var _weight = _objectData [? "weight"];
  20.    
  21.     _maxWeight += _weight;
  22.    
  23.     if (_diceRoll <= _maxWeight)
  24.     {
  25.         if (is_array(_object))
  26.         {
  27.             return _object;
  28.         }
  29.         else
  30.         {
  31.             break;
  32.         }
  33.     }
  34. }
  35.  
  36. _result = ds_map_create();
  37. ds_map_copy(_result, _objectData);
  38.  
  39. return _result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement