SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function addItem (source, name, amount ,meta) |
| 1 | + | function addItem (_source, _name, _amount, _meta) |
| 2 | - | local _source = source |
| 2 | + | _meta = meta or {}
|
| 3 | - | local _name = name |
| 3 | + | |
| 4 | - | local _amount = amount |
| 4 | + | |
| 5 | - | local _meta = meta or {}
|
| 5 | + | |
| 6 | if _amount > 0 then | |
| 7 | local user = exports.redemrp:getPlayerFromId(_source) | |
| 8 | - | TriggerEvent('redemrp:getPlayerFromId', _source, function(user)
|
| 8 | + | |
| 9 | - | local identifier = user.getIdentifier() |
| 9 | + | local identifier = user.getIdentifier() |
| 10 | - | local charid = user.getSessionVar("charid")
|
| 10 | + | local charid = user.getSessionVar("charid")
|
| 11 | - | local player_inventory = inventory_with_data[identifier .. "_" .. charid] |
| 11 | + | local player_inventory = inventory_with_data[identifier .. "_" .. charid] |
| 12 | - | local player_db_inventory = inventory_without_data[identifier .. "_" .. charid] |
| 12 | + | local player_db_inventory = inventory_without_data[identifier .. "_" .. charid] |
| 13 | - | if item_info.type == "item_standard" then |
| 13 | + | |
| 14 | - | if inventory_weight[identifier .. "_" .. charid] + (item_info.weight * _amount) <= 24.0 then |
| 14 | + | if item_info.type == "item_standard" then |
| 15 | - | if player_inventory[_name] then |
| 15 | + | if inventory_weight[identifier .. "_" .. charid] + (item_info.weight * _amount) <= 24.0 then |
| 16 | - | player_inventory[_name].amount = player_inventory[_name].amount + _amount |
| 16 | + | if player_inventory[_name] then |
| 17 | - | player_db_inventory[_name].amount = player_db_inventory[_name].amount + _amount |
| 17 | + | player_inventory[_name].amount = player_inventory[_name].amount + _amount |
| 18 | - | else |
| 18 | + | player_db_inventory[_name].amount = player_db_inventory[_name].amount + _amount |
| 19 | - | inventory[identifier .. "_" .. charid][_name] = {name = _name, amount = _amount, meta = _meta, label = item_info.label, description = item_info.description, imgsrc = item_info.imgsrc , weight = item_info.weight, staticData = item_info.staticData}
|
| 19 | + | else |
| 20 | - | player_db_inventory[_name].amount = _amount |
| 20 | + | inventory[identifier .. "_" .. charid][_name] = {name = _name, amount = _amount, meta = _meta, label = item_info.label, description = item_info.description, imgsrc = item_info.imgsrc , weight = item_info.weight, staticData = item_info.staticData}
|
| 21 | - | end |
| 21 | + | player_db_inventory[_name].amount = _amount |
| 22 | - | inventory_weight[identifier .. "_" .. charid] = inventory_weight[identifier .. "_" .. charid] + (item_info.weight * _amount) |
| 22 | + | |
| 23 | inventory_weight[identifier .. "_" .. charid] = inventory_weight[identifier .. "_" .. charid] + (item_info.weight * _amount) | |
| 24 | - | elseif item_info.type == "item_weapon" then |
| 24 | + | |
| 25 | - | if inventory_weight[identifier .. "_" .. charid] + item_info.weight <= 24.0 then |
| 25 | + | elseif item_info.type == "item_weapon" then |
| 26 | - | local numBase0 = math.random(100,999) |
| 26 | + | if inventory_weight[identifier .. "_" .. charid] + item_info.weight <= 24.0 then |
| 27 | - | local numBase1 = math.random(0,9999) |
| 27 | + | local weaponid = string.format("%03d%04d", math.random(100,999), math.random(0,9999))
|
| 28 | - | local weaponid = string.format("%03d%04d", numBase0, numBase1)
|
| 28 | + | inventory[identifier .. "_" .. charid][_name..weaponid] = {name = _name..weaponid, amount = _amount, meta = _meta, label = item_info.label, description = item_info.description, imgsrc = item_info.imgsrc , weight = item_info.weight, staticData = item_info.staticData}
|
| 29 | - | inventory[identifier .. "_" .. charid][_name..weaponid] = {name = _name..weaponid, amount = _amount, meta = _meta, label = item_info.label, description = item_info.description, imgsrc = item_info.imgsrc , weight = item_info.weight, staticData = item_info.staticData}
|
| 29 | + | player_db_inventory[_name..weaponid].amount = {amount = _amount , meta = _meta}
|
| 30 | - | player_db_inventory[_name..weaponid].amount = {amount = _amount , meta = _meta}
|
| 30 | + | |
| 31 | inventory_weight[identifier .. "_" .. charid] = inventory_weight[identifier .. "_" .. charid] + item_info.weight | |
| 32 | - | inventory_weight[identifier .. "_" .. charid] = inventory_weight[identifier .. "_" .. charid] + item_info.weight |
| 32 | + | end |
| 33 | end | |
| 34 | - | end) |
| 34 | + | |
| 35 |