Advertisement
Guest User

Delete item offline or online

a guest
Aug 11th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. function doPlayerDeleteInventoryItem(name, slot)
  2.     local resultId = db.storeQuery('SELECT `id` FROM `players` WHERE `name` = ' .. db.escapeString(name))
  3.     if not resultId then
  4.         return result.free(resultId)
  5.     end
  6.     local guid = result.getNumber(resultId, "id")
  7.     result.free(resultId)
  8.     resultId = db.query(('DELETE FROM `player_items` WHERE `player_id` = %u AND `pid` = %u'):format(guid, slot))
  9.     return resultId
  10. end
  11.  
  12. function onSay(player, words, param)
  13.     local split = param:split(",")
  14.     local target = Player(split[1])
  15.     local slot = tonumber(split[2])
  16.     if not slot or slot < 1 or slot > 11 then
  17.         return not player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The second parameter is wrong or has a bad slot index.")
  18.     end
  19.     if target then
  20.         local slotItem = target:getSlotItem(slot)
  21.         if slotItem then
  22.             slotItem:remove()
  23.             return not player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The item was deleted successfully.")
  24.         end
  25.         return not player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "There is no item to delete.")
  26.     elseif not doPlayerDeleteInventoryItem(split[1], slot) then
  27.         return not player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "No items could be deleted.")
  28.     end
  29.     return not player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The item was deleted successfully.")
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement