Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 KB | None | 0 0
  1. local ESX = nil
  2.  
  3. local SmelteryTimer = {}
  4. local ExchangeTimer = {}
  5. local GoldJobTimer = {}
  6.  
  7. local NPC = 0
  8.  
  9. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  10.  
  11. Citizen.CreateThread(function()
  12. Citizen.Wait(1000)
  13. while true do
  14. NPC = math.random(1,#Config.MissionNPC)
  15. TriggerClientEvent("esx_goldCurrency:spawnNPC",-1,Config.MissionNPC[NPC])
  16. Citizen.Wait(7200000*2)
  17. end
  18. end)
  19.  
  20. AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
  21. TriggerClientEvent("esx_goldCurrency:spawnNPC",playerId,Config.MissionNPC[NPC])
  22. end)
  23.  
  24. -- server side for cooldown timer
  25. RegisterServerEvent("esx_goldCurrency:MeltingCooldown")
  26. AddEventHandler("esx_goldCurrency:MeltingCooldown",function(source)
  27. table.insert(SmelteryTimer,{MeltingTimer = GetPlayerIdentifier(source), time = ((Config.SmelteryTime * 1000))})
  28. end)
  29.  
  30. -- server side for cooldown timer
  31. RegisterServerEvent("esx_goldCurrency:ExhangeCooldown")
  32. AddEventHandler("esx_goldCurrency:ExhangeCooldown",function(source)
  33. table.insert(ExchangeTimer,{ExchangeTimer = GetPlayerIdentifier(source), timeExchange = ((Config.ExchangeCooldown * 60000))})
  34. end)
  35.  
  36. -- server side for cooldown timer
  37. RegisterServerEvent("esx_goldCurrency:GoldJobCooldown")
  38. AddEventHandler("esx_goldCurrency:GoldJobCooldown",function(source)
  39. table.insert(GoldJobTimer,{GoldJobTimer = GetPlayerIdentifier(source), timeGoldJob = (2 * 60000)}) -- cooldown timer for doing missions
  40. end)
  41.  
  42. -- thread for syncing the cooldown timer
  43. Citizen.CreateThread(function() -- do not touch this thread function!
  44. while true do
  45. Citizen.Wait(1000)
  46. for k,v in pairs(SmelteryTimer) do
  47. if v.time <= 0 then
  48. RemoveSmelteryTimer(v.MeltingTimer)
  49. else
  50. v.time = v.time - 1000
  51. end
  52. end
  53. for k,v in pairs(ExchangeTimer) do
  54. if v.timeExchange <= 0 then
  55. RemoveExchangeTimer(v.ExchangeTimer)
  56. else
  57. v.timeExchange = v.timeExchange - 1000
  58. end
  59. end
  60. for k,v in pairs(GoldJobTimer) do
  61. if v.timeGoldJob <= 0 then
  62. RemoveGoldJobTimer(v.GoldJobTimer)
  63. else
  64. v.timeGoldJob = v.timeGoldJob - 1000
  65. end
  66. end
  67. end
  68. end)
  69.  
  70. -- server side function to get cooldown timer
  71. ESX.RegisterServerCallback("esx_goldCurrency:getGoldJobCoolDown",function(source,cb)
  72. local _source = source
  73. local xPlayer = ESX.GetPlayerFromId(_source)
  74. if not CheckGoldJobTimer(GetPlayerIdentifier(source)) then
  75. cb(false)
  76. else
  77. TriggerClientEvent("esx:showNotification",source,string.format("Kolejna ~y~praca~s~ będzie ~g~dostępna~s~ dla Ciebie w ciągu: ~b~%s~s~ minutes",GetGoldJobTimer(GetPlayerIdentifier(source))))
  78. cb(true)
  79. end
  80. end)
  81.  
  82. -- server side function to get payment
  83. RegisterServerEvent('esx_goldCurrency:missionAccepted')
  84. AddEventHandler('esx_goldCurrency:missionAccepted', function()
  85. TriggerClientEvent("esx_goldCurrency:startMission",source,0)
  86. end)
  87.  
  88. ESX.RegisterServerCallback("esx_goldCurrency:getPayment",function(source,cb)
  89. local _source = source
  90. local xPlayer = ESX.GetPlayerFromId(_source)
  91. local Players = ESX.GetPlayers()
  92. local blackMoney = 0
  93. blackMoney = xPlayer.getAccount('black_money').money
  94. local moneyCash = 0
  95. moneyCash = xPlayer.getMoney()
  96. if Config.UseBlackMoneyAsMissionCost == true then
  97. if blackMoney <= Config.MissionCost then
  98. TriggerClientEvent('esx:showNotification', source, "Nie masz ~b~wystarczająco~s~ ~r~ brudnej forsy~s~ aby zapłacić za ~y~robotę~s~")
  99. cb(false)
  100. else
  101. xPlayer.removeAccountMoney('black_money', Config.MissionCost)
  102. TriggerEvent("esx_goldCurrency:GoldJobCooldown",source)
  103. cb(true)
  104. end
  105. else
  106. if moneyCash <= Config.MissionCost then
  107. TriggerClientEvent('esx:showNotification', source, "Nie masz ~b~wystarczająco~s~ ~r~forsy~s~ aby zapłacić za ~y~robotę~s~")
  108. cb(false)
  109. else
  110. xPlayer.removeMoney(Config.MissionCost)
  111. TriggerEvent("esx_goldCurrency:GoldJobCooldown",source)
  112. cb(true)
  113. end
  114. end
  115. end)
  116.  
  117. -- server side function to accept the mission
  118. ESX.RegisterServerCallback("esx_goldCurrency:getMissionavailability",function(source,cb)
  119. local _source = source
  120. local xPlayer = ESX.GetPlayerFromId(_source)
  121. local Players = ESX.GetPlayers()
  122. local policeOnline = 0
  123. for i = 1, #Players do
  124. local xPlayer = ESX.GetPlayerFromId(Players[i])
  125. if xPlayer["job"]["name"] == Config.PoliceDatabaseName then
  126. policeOnline = policeOnline + 1
  127. end
  128. end
  129. if policeOnline >= Config.RequiredPoliceOnline then
  130. cb(true)
  131. else
  132. cb(false)
  133. TriggerClientEvent('esx:showNotification', source, "Nie ma wystarczająco ~b~policji~s~ w ~y~mieście~s~")
  134. end
  135. end)
  136.  
  137. -- mission reward
  138. RegisterServerEvent('esx_goldCurrency:reward')
  139. AddEventHandler('esx_goldCurrency:reward', function()
  140. local _source = source
  141. local xPlayer = ESX.GetPlayerFromId(_source)
  142. local SecondItem = false
  143.  
  144. -- item 1
  145. local itemAmount1 = ((math.random(Config.ItemMinAmount1,Config.ItemMaxAmount1)) * 100)
  146. local item1 = ESX.GetItemLabel(Config.ItemName1)
  147.  
  148. -- item 2
  149. local itemAmount2 = math.random(Config.ItemMinAmount2,Config.ItemMaxAmount2)
  150. local item2 = ESX.GetItemLabel(Config.ItemName2)
  151.  
  152. local chance = math.random(1,Config.RandomChance)
  153. if chance == 1 then
  154. SecondItem = true
  155. end
  156.  
  157. if Config.EnableSecondItemReward == true and SecondItem == true then
  158. xPlayer.addInventoryItem(Config.ItemName1,itemAmount1)
  159. xPlayer.addInventoryItem(Config.ItemName2,itemAmount2)
  160. if Config.EnableCustomNotification == true then
  161. TriggerClientEvent("esx_goldCurrency:missionComplete", source,itemAmount1,item1,itemAmount2,item2)
  162. else
  163. TriggerClientEvent('esx:showNotification', source, "~g~Misja zakończona:~s~ Otrzymałeś ~b~"..itemAmount1.."x~s~ ~y~"..item1.."~s~ i "..itemAmount2.."x~s~ ~y~"..item2.."~s~")
  164. end
  165. else
  166. xPlayer.addInventoryItem(Config.ItemName1,itemAmount1)
  167. if Config.EnableCustomNotification == true then
  168. TriggerClientEvent("esx_goldCurrency:missionComplete", source,itemAmount1,item1)
  169. else
  170. TriggerClientEvent('esx:showNotification', source, "~g~Misja zakończona:~s~ Otrzymałeś ~b~"..itemAmount1.."x~s~ ~y~"..item1.."~s~")
  171. end
  172. end
  173.  
  174. end)
  175.  
  176. RegisterServerEvent('esx_goldCurrency:GoldJobInProgress')
  177. AddEventHandler('esx_goldCurrency:GoldJobInProgress', function(targetCoords, streetName)
  178. TriggerClientEvent('esx_goldCurrency:outlawNotify', -1,string.format("^3 Strzaly ^0 na ^5%s^0 ",streetName))
  179. TriggerClientEvent('esx_goldCurrency:GoldJobInProgress', -1, targetCoords)
  180. end)
  181.  
  182. -- sync mission data
  183. RegisterServerEvent("esx_goldCurrency:syncMissionData")
  184. AddEventHandler("esx_goldCurrency:syncMissionData",function(data)
  185. TriggerClientEvent("esx_goldCurrency:syncMissionData",-1,data)
  186. end)
  187.  
  188. -- server side function for converting part
  189. RegisterServerEvent('esx_goldCurrency:goldMelting')
  190. AddEventHandler('esx_goldCurrency:goldMelting', function()
  191. local xPlayer = ESX.GetPlayerFromId(source)
  192.  
  193. if xPlayer.getInventoryItem("goldwatch").count >= 100 then
  194. if xPlayer.getInventoryItem("goldbar").count <= 99 then
  195. if not CheckIfMelting(GetPlayerIdentifier(source)) then
  196. TriggerEvent("esx_goldCurrency:MeltingCooldown",source)
  197.  
  198. xPlayer.removeInventoryItem("goldwatch",100)
  199.  
  200. TriggerClientEvent("goldwatchTogoldbar",source)
  201. Citizen.Wait((Config.SmelteryTime * 1000))
  202.  
  203. xPlayer.addInventoryItem("goldbar",1)
  204. else
  205. TriggerClientEvent("esx:showNotification",source,string.format("Jestes juz ~b~zaangazowany~s~ w ten ~y~proces~s~!",GetTimeForMelting(GetPlayerIdentifier(source))))
  206. end
  207. else
  208. TriggerClientEvent("esx:showNotification",source,"Nie ~r~masz ~s~ wystarczajaco ~b~wolnego miejsca~s~ dla ~y~Zlotych Sztabek~s~")
  209. end
  210. else
  211. TriggerClientEvent("esx:showNotification",source,"Potrzebujesz ~r~minimum~s~ 100x ~y~Zlotych Zegarkow~s~")
  212. end
  213. end)
  214.  
  215. -- server side function for exchange part
  216. RegisterServerEvent('esx_goldCurrency:goldExchange')
  217. AddEventHandler('esx_goldCurrency:goldExchange', function()
  218. local xPlayer = ESX.GetPlayerFromId(source)
  219. local _source = source
  220.  
  221. if not CheckIfExchanging(GetPlayerIdentifier(source)) then
  222. if xPlayer.getInventoryItem("goldbar").count >= 1 then
  223. TriggerEvent("esx_goldCurrency:ExhangeCooldown",source)
  224.  
  225. xPlayer.removeInventoryItem("goldbar",1)
  226.  
  227. TriggerClientEvent("goldbarToCash",source)
  228. Citizen.Wait((Config.ExchangeTime * 1000))
  229.  
  230. xPlayer.addAccountMoney('black_money', 35000)
  231. else
  232. TriggerClientEvent("esx:showNotification",source,"Potrzebujesz ~r~minimum~s~ jedna ~y~Zlota Sztabke~s~")
  233. end
  234. else
  235. TriggerClientEvent("esx:showNotification",source,string.format("Mozesz ~y~wymienic zloto~s~ ponownie w ciagu: ~b~%s minutes~s~",GetTimeForExchange(GetPlayerIdentifier(source))))
  236. end
  237. end)
  238.  
  239. -- ## DO NOT TOUCH BELOW THIS!! ## --
  240.  
  241. -- Functions for Smeltery Timer
  242. function RemoveSmelteryTimer(source)
  243. for k,v in pairs(SmelteryTimer) do
  244. if v.MeltingTimer == source then
  245. table.remove(SmelteryTimer,k)
  246. end
  247. end
  248. end
  249. function GetTimeForMelting(source)
  250. for k,v in pairs(SmelteryTimer) do
  251. if v.MeltingTimer == source then
  252. return math.ceil(v.time/1000)
  253. end
  254. end
  255. end
  256. function CheckIfMelting(source)
  257. for k,v in pairs(SmelteryTimer) do
  258. if v.MeltingTimer == source then
  259. return true
  260. end
  261. end
  262. return false
  263. end
  264. -- Functions for Exchange Timer:
  265. function RemoveExchangeTimer(source)
  266. for k,v in pairs(ExchangeTimer) do
  267. if v.ExchangeTimer == source then
  268. table.remove(ExchangeTimer,k)
  269. end
  270. end
  271. end
  272. function GetTimeForExchange(source)
  273. for k,v in pairs(ExchangeTimer) do
  274. if v.ExchangeTimer == source then
  275. return math.ceil(v.timeExchange/60000)
  276. end
  277. end
  278. end
  279. function CheckIfExchanging(source)
  280. for k,v in pairs(ExchangeTimer) do
  281. if v.ExchangeTimer == source then
  282. return true
  283. end
  284. end
  285. return false
  286. end
  287. -- Functions for Mission Timer:
  288. function RemoveGoldJobTimer(source)
  289. for k,v in pairs(GoldJobTimer) do
  290. if v.GoldJobTimer == source then
  291. table.remove(GoldJobTimer,k)
  292. end
  293. end
  294. end
  295. function GetGoldJobTimer(source)
  296. for k,v in pairs(GoldJobTimer) do
  297. if v.GoldJobTimer == source then
  298. return math.ceil(v.timeGoldJob/60000)
  299. end
  300. end
  301. end
  302. function CheckGoldJobTimer(source)
  303. for k,v in pairs(GoldJobTimer) do
  304. if v.GoldJobTimer == source then
  305. return true
  306. end
  307. end
  308. return false
  309. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement