Guest User

Untitled

a guest
Dec 16th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. bountyStorage = 99981
  2.  
  3. function onSay(player, words, param)
  4.     if param == '' then
  5.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Usage: '.. words ..' playername, money')
  6.         return false
  7.     end
  8.  
  9.     local sp = string.split(param, ',')
  10.     local name, money = sp[1], tonumber(sp[2])
  11.     local guid = getPlayerGUIDByName(name)
  12.     local target = (guid ~= 0) and (Player(name) or guid)
  13.  
  14.     -- Has the player entered the correct parameters?
  15.     if not (name and money) then
  16.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Usage: '.. words ..' playername, money')
  17.         return false
  18.     end
  19.  
  20.     -- Does the target player exist?
  21.     if not target then
  22.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'Player '.. name .. ' does not exist.')
  23.         return false
  24.     end
  25.  
  26.     if money == 0 then
  27.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must add a value greater than 0.')
  28.         return false
  29.     end
  30.  
  31.     -- Does the player have enough money to set a bounty to the specified target?
  32.     if not (player:getMoney() >= money) then
  33.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You do not have enough money.')
  34.         return false
  35.     end
  36.  
  37.     local online = type(target) == 'userdata'
  38.  
  39.     local query = "SELECT `value` FROM `player_storage` WHERE `key` = ".. bountyStorage .." AND `player_id` = ".. guid
  40.     local getResult = db.storeQuery(query)
  41.  
  42.     if not online and not getResult then
  43.         db.query("INSERT INTO `player_storage` (`player_id`, `key`, `value`) VALUES (".. guid ..", ".. bountyStorage ..", 0)")
  44.         getResult = db.storeQuery(query)
  45.     end
  46.  
  47.     local dbValue = result.getDataInt(getResult, 'value')
  48.     local newValue = money + (online and target:getStorageValue(bountyStorage) or tonumber(dbValue))
  49.     result.free(getResult)
  50.  
  51.     -- Is the target online?
  52.     if online then
  53.         target:setStorageValue(bountyStorage, newValue)
  54.     else
  55.         db.query("UPDATE `player_storage` SET `value` = " .. newValue .. " WHERE `key` = " .. bountyStorage .. " AND `player_id` = " .. guid)
  56.     end
  57.  
  58.     Game.broadcastMessage(string.format('[BOUNTY]: %s has added a bounty of %d gold to %s. Current bounty: %d', player:getName(), money, name, newValue), MESSAGE_STATUS_CONSOLE_ORANGE)
  59.     player:removeMoney(money)
  60.     return false
  61. end
Add Comment
Please, Sign In to add comment