Tocuto

50 Shades of Lua: Blanky Coins command: !work

Apr 23rd, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. local job, job_title
  2.  
  3. if not parameters then
  4.     local jobs = {}
  5.     for i, v in next, data.jobs do
  6.         if v.available and data.money[v.boss] > 9 and data.money[v.boss] >= v.money_range[2] then
  7.             jobs[#jobs + 1] = {i, v}
  8.         end
  9.     end
  10.  
  11.     job_title, job = table.unpack(jobs[math.random(#jobs)])
  12. else
  13.     if parameters:match("(%S+) (.+)") then
  14.         local search_type, search = parameters:match("(%S+) (.+)")
  15.  
  16.         if search_type:lower() == "at" then
  17.             job = data.jobs[search:lower()]
  18.             if (not job) or (not job.available) then
  19.                 print("Job not found or not available: `" .. search:lower() .. "`")
  20.                 return
  21.             end
  22.             job_title = search:lower()
  23.         elseif search_type:lower() == "for" then
  24.             local match = search:match("<@!?(%d+)>")
  25.             if match then
  26.                 work_on = match
  27.             else
  28.                 work_on = discord.getMemberId(search)
  29.             end
  30.             if (not work_on) or not discord.isMember(work_on) then
  31.                 print("The given user was not found in the server.")
  32.                 return
  33.             end
  34.             local jobs = {}
  35.             for i, v in next, data.jobs do
  36.                 if v.boss == work_on and v.available and data.money[v.boss] > 10 and data.money[v.boss] >= v.money_range[2] then
  37.                     jobs[#jobs + 1] = {i, v}
  38.                 end
  39.             end
  40.             if #jobs == 0 then
  41.                 print("<@" .. work_on .. "> is currently not hiring anyone or can't hire anyone.")
  42.                 return
  43.             end
  44.             job_title, job = table.unpack(jobs[math.random(#jobs)])
  45.         else
  46.             print("Invalid syntax. Valid ones:")
  47.             print("!work at job name")
  48.             print("!work for Bolo")
  49.             print("!work for Lautenschlager#2555")
  50.             print("!work for <@285878295759814656>")
  51.             print("!work")
  52.             return
  53.         end
  54.     else
  55.         print("Invalid syntax. Valid ones:")
  56.         print("!work at job name")
  57.         print("!work for Bolo")
  58.         print("!work for Lautenschlager#2555")
  59.         print("!work for <@285878295759814656>")
  60.         print("!work")
  61.         return
  62.     end
  63. end
  64.  
  65. if data.money[job.boss] < 10 or data.money[job.boss] < job.money_range[2] then
  66.     print("The job boss can't pay you. Search another job.")
  67.     return
  68. end
  69.  
  70. if not cooldown(1) then return end
  71. print("Job: `" .. job_title .. "`")
  72. print("Boss: <@" .. job.boss .. ">")
  73. print("")
  74. local state = math.random(3)
  75. if state == 1 then -- hired
  76.     local earned = math.random(job.money_range[1], job.money_range[2])
  77.  
  78.     if not data.money[discord.authorId] then
  79.         data.money[discord.authorId] = 500
  80.     end
  81.     data.money[discord.authorId] = data.money[discord.authorId] + 70 * earned / 100
  82.     data.money[job.boss] = data.money[job.boss] + 20 * earned / 100
  83.     data.money["436703225140346881"] = data.money["436703225140346881"] + 5 * earned / 100
  84.     data.money["212634414021214209"] = data.money["212634414021214209"] + 5 * earned / 100
  85.  
  86.     print("You've been hired!")
  87.     print(job.hired_phrases[math.random(#job.hired_phrases)])
  88.     print("Your wage is $" .. earned)
  89.     print("You've earned $" .. 70 * earned / 100 .. ". (70%)")
  90.     print("Your boss earned $" .. 20 * earned / 100 .. ". (20%)")
  91.     print("You give $" .. 10 * earned / 100 .. " as tax. (10%)")
  92. elseif state == 2 then -- fired
  93.     print("You've been fired!")
  94.     print(job.fired_phrases[math.random(#job.fired_phrases)])
  95.     print("But see the good point: you stole $10 from your boss!")
  96.  
  97.     if not data.money[discord.authorId] then
  98.         data.money[discord.authorId] = 500
  99.     end
  100.     data.money[discord.authorId] = data.money[discord.authorId] + 10
  101.     data.money[job.boss] = data.money[job.boss] - 10
  102. else -- rejected
  103.     print("You've been rejected!")
  104.     print(job.rejected_phrases[math.random(#job.rejected_phrases)])
  105. end
Add Comment
Please, Sign In to add comment