Advertisement
Eihrenjar

Untitled

Jan 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. local function isValidMoney(value)
  2.     if(value == nil) then
  3.         return false
  4.     end
  5.     return (value > 0 and value <= 99999999999999)
  6. end
  7.  
  8. function onSay(cid, words, param)
  9.  
  10.     local player = Player(cid)
  11.     local guild = player:getGuild():getId()
  12.     if(guild == nil) then
  13.         return true
  14.     end
  15.  
  16.     local t = string.explode(param, ' ', 1)
  17.    
  18.     if(player:getGuildLevel() == GUILDLEVEL_LEADER and isInArray({'pick'}, t[1])) then
  19.         if(t[1] == 'pick') then
  20.             local money = {tonumber(t[2])}
  21.             if(not isValidMoney(money[1])) then
  22.                 player:sendChannelMessage('', 'Invalid amount of money specified.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  23.                 return false
  24.             end
  25.  
  26.             local resultId = db.storeQuery("SELECT `balance` FROM `guilds` WHERE `id` = " .. guild)
  27.             if resultId == false then
  28.                 return false
  29.             end
  30.            
  31.             money[2] = result.getDataInt(resultId, "balance")
  32.             result.free(resultId)
  33.  
  34.             if(money[1] > money[2]) then
  35.                 player:sendChannelMessage('', 'The balance is too low for such amount.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  36.                 return false
  37.             end
  38.  
  39.             if(not db.query('UPDATE `guilds` SET `balance` = `balance` - ' .. money[1] .. ' WHERE `id` = ' .. guild .. ' LIMIT 1;')) then
  40.                 return false
  41.             end
  42.  
  43.             doPlayerAddMoney(cid, money[1])
  44.             player:sendChannelMessage('', 'You have just picked ' .. money[1] .. ' money from your guild balance.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  45.         else
  46.             player:sendChannelMessage('', 'Invalid sub-command.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  47.         end
  48.     elseif(t[1] == 'donate') then
  49.         local money = tonumber(t[2])
  50.         if(not isValidMoney(money)) then
  51.             player:sendChannelMessage('', 'Invalid amount of money specified.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  52.             return true
  53.         end
  54.  
  55.         if(getPlayerMoney(cid) < money) then
  56.             player:sendChannelMessage('', 'You don\'t have enough money.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  57.             return true
  58.         end
  59.  
  60.         if(not doPlayerRemoveMoney(cid, money)) then
  61.             return false
  62.         end
  63.  
  64.         db.query('UPDATE `guilds` SET `balance` = `balance` + ' .. money .. ' WHERE `id` = ' .. guild .. ' LIMIT 1;')
  65.         player:sendChannelMessage('', 'You have transfered ' .. money .. ' money to your guild balance.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  66.     else
  67.         local resultId = db.storeQuery('SELECT `name`, `balance` FROM `guilds` WHERE `id` = ' .. guild)
  68.         if resultId == false then
  69.             return false
  70.         end
  71.         player:sendChannelMessage('', 'Current balance of guild ' .. result.getDataString(resultId, "name") .. ' is: ' .. result.getDataInt(resultId, "balance") .. ' bronze coins.', TALKTYPE_CHANNEL_R1, CHANNEL_GUILD)
  72.         result.free(resultId)
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement