Advertisement
Guest User

Untitled

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