Advertisement
lowheartrate

fixed progressbar with nativeUI

May 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.70 KB | None | 0 0
  1. 5:08 AM] lowheartrate: Anyone have any experience using NativeUILua-Reloaded? I am having an issue trying to use the progress bar: https://github.com/iTexZoz/NativeUILua_Reloaded/issues/54
  2. [5:16 AM] JohnAA12: Did you include the progress bar files?
  3. [5:17 AM] JohnAA12: ex: client_scripts {
  4. "@NativeUILua-Reloaded/UIProgressBar/UIProgressBarPool.lua",
  5. "@NativeUILua-Reloaded/UIProgressBar/items/UIProgressBarItem.lua"
  6. }
  7. [5:18 AM] lowheartrate: @JohnAA12 This is my __resource.lua: https://pastebin.com/BBg82VLg
  8. [5:21 AM] JohnAA12:
  9. RegisterNetEvent('NativeUI:progress')
  10. AddEventHandler('NativeUI:progress', function()
  11. local _progressBarPool = NativeUI.ProgressBarPool()
  12. Citizen.CreateThread(function()
  13. while true do
  14. Citizen.Wait(1)
  15. _ProgressBarPool:Draw()
  16. end
  17. end)
  18.  
  19. local Item = NativeUI.CreateProgressBarItem("Récolte en cours...")
  20. _ProgressBarPool:Add(Item)
  21.  
  22. Citizen.CreateThread(function()
  23. while true do
  24. Citizen.Wait(1)
  25. if (progress >= 100) then
  26. progress = 0
  27. else
  28. progress = progress + 0.1
  29. end
  30. Item:SetPercentage(progress)
  31. end
  32. end)
  33. end)
  34. [5:22 AM] JohnAA12: when you make the progress bar pool you use _progressBarPool
  35. [5:22 AM] JohnAA12: but you're calling _ProgressBarPool
  36. [5:23 AM] JohnAA12: also you need to define progress
  37. [5:28 AM] lowheartrate: progess is define in the if / else statements.
  38. [5:28 AM] JohnAA12: You need to define it first
  39. [5:28 AM] JohnAA12: progress is nil by default
  40. [5:28 AM] JohnAA12: if (nil >= 100) will error
  41. [5:29 AM] lowheartrate: I am trying to make the progress bar run until the player is done washing their money (delay of 3.5 minutes).
  42. [5:29 AM] JohnAA12: You have to call local progress = 0 outside of the while true loop for the progress
  43. [5:30 AM] JohnAA12: or it won't move at all
  44. [5:30 AM] lowheartrate: gotcha, something like this look better?
  45. RegisterNetEvent('NativeUI:progress')
  46. AddEventHandler('NativeUI:progress', function()
  47. local _progressBarPool = NativeUI.ProgressBarPool()
  48. local progress = 0
  49. Citizen.CreateThread(function()
  50. while true do
  51. Citizen.Wait(1)
  52. _progressBarPool:Draw()
  53. end
  54. end)
  55.  
  56. local Item = NativeUI.CreateProgressBarItem("RĂ©colte en cours...")
  57. _progressBarPool:Add(Item)
  58.  
  59. Citizen.CreateThread(function()
  60. while true do
  61. Citizen.Wait(1)
  62. if (progress >= 100) then
  63. progress = 0
  64. else
  65. progress = progress + 0.1
  66. end
  67. Item:SetPercentage(progress)
  68. end
  69. end)
  70. end)
  71. [5:30 AM] JohnAA12: you still have _ProgressBarPool instead of _progressBarPool
  72. [5:31 AM] lowheartrate: edited
  73. [5:31 AM] JohnAA12: Okay? That should work
  74. [5:31 AM] lowheartrate: I'll go try it out.
  75. [5:31 AM] JohnAA12: But that progress is not in any way 3.5 minutes
  76. [5:31 AM] JohnAA12: you'll have to adjust the math for it
  77. [5:31 AM] lowheartrate: Gotcha
  78. [5:35 AM] lowheartrate: I'm getting this error now: https://i.imgur.com/MKxWCJm.png
  79. [5:36 AM] JohnAA12: you need to add manifest version to __resource.lua
  80. [5:37 AM] JohnAA12: resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
  81. [5:37 AM] lowheartrate: That one specifically or the latest?
  82. resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
  83. [5:38 AM] JohnAA12: Any works
  84. [5:38 AM] JohnAA12: From what i've tested
  85. [5:39 AM] JohnAA12: "Technically" the latest one is05cfa83c-a124-4cfa-a768-c24a5811d8f9
  86. [5:39 AM] lowheartrate: Awesome works! Just got to get it so the bar takes 3.5 minutes to load, currently it takes just a few seconds and restarts.
  87. [5:41 AM] lowheartrate: How would I go about changing the amount of time it takes to load? Would I replace
  88. Citizen.CreateThread(function()
  89. while true do
  90. Citizen.Wait(1)
  91. if (progress >= 100) then
  92. progress = 0
  93. else
  94. progress = progress + 0.1
  95. end
  96. Item:SetPercentage(progress)
  97. end
  98. end)
  99.  
  100. with something like:
  101. Citizen.CreateThread(function()
  102. while true do
  103. Citizen.Wait(< 3.5 MINUTES >)
  104. if (progress >= 100) then
  105. progress = 0
  106. else
  107. progress = progress + 0.1
  108. end
  109. Item:SetPercentage(progress)
  110. end
  111. end)
  112. [5:41 AM] JohnAA12: no
  113. [5:41 AM] JohnAA12: you would have it way say 1 sec (1000) each time
  114. [5:42 AM] JohnAA12: and add like 0.28 to the progress
  115. [5:42 AM] JohnAA12: so after 3.5 minutes it's full
  116. [5:42 AM] JohnAA12: Because 0.28 * 3.5 = 0.98
  117. [5:43 AM] JohnAA12: and you times that by 100 which is 98 (the bar is out of 100)
  118. [5:43 AM] JohnAA12: and pretty much the closest you can get without trailing decimal numbers
  119. [5:43 AM] lowheartrate: and then
  120. if (progress >= 100) then
  121. -- kill progress bar
  122. else
  123. [5:44 AM] JohnAA12: If you want to kill it you would have to do something like _progressBarPool.ProgressBar = {}
  124. [5:44 AM] JohnAA12: So it removes the progress bars
  125. [5:45 AM] lowheartrate: gotcha, how come it loads so fast as of right now if its only loading progress = progress + 0.1
  126. [5:45 AM] JohnAA12: Because the wait is only 1/1000 of a second
  127. [5:45 AM] lowheartrate: Gotcha
  128. [5:46 AM] JohnAA12: Odd numbers are weird for the progress, as you can't really get exactly 100
  129. [5:47 AM] JohnAA12: That's not exactly
  130. [5:47 AM] JohnAA12: as 3.5 * 28.5714285714 is 99.9999999999
  131. [5:48 AM] lowheartrate: and that would take 3.5 seconds to load wouldn't it lol looking for the amount of seconds it takes.
  132. [5:48 AM] lowheartrate: Thats why I delete.
  133. [5:48 AM] JohnAA12: you would have the Citizen.Wait(1000)
  134. [5:49 AM] JohnAA12: and the progress add 0.285714285714
  135. [5:49 AM] lowheartrate: 100/210 (seconds) = 0.4761904761904762
  136. [5:49 AM] lowheartrate: https://i.imgur.com/aCzQicV.png
  137. [5:50 AM] JohnAA12: Yeah you can try that
  138. [5:53 AM] lowheartrate: Doesn't seem to show me the progress bar at all anymore:
  139. RegisterNetEvent('NativeUI:progress')
  140. AddEventHandler('NativeUI:progress', function()
  141. local _progressBarPool = NativeUI.ProgressBarPool()
  142. local progress = 0
  143. Citizen.CreateThread(function()
  144. while true do
  145. Citizen.Wait(1)
  146. _progressBarPool:Draw()
  147. end
  148. end)
  149.  
  150. local Item = NativeUI.CreateProgressBarItem("Washing $" .. accountMoney .. "!")
  151. _progressBarPool:Add(Item)
  152.  
  153. Citizen.CreateThread(function()
  154. while true do
  155. Citizen.Wait(1000)
  156. if (progress >= 100) then
  157. progress = 0
  158. else
  159. -- each second add 0.4761904761904762 to the progress bar - will be at >= 100 in 3.5 minutes
  160. progress = progress + 0.4761904761904762
  161. end
  162. Item:SetPercentage(progress)
  163. end
  164. end)
  165. end)
  166. [5:54 AM] JohnAA12: probably because the float is so small
  167. [5:56 AM] JohnAA12: wait
  168. [5:56 AM] lowheartrate: local Item = NativeUI.CreateProgressBarItem("Washing $" .. accountMoney .. "!")
  169. [5:56 AM] JohnAA12: where do you define accountMoney
  170. [5:57 AM] lowheartrate: I define that is in the server event:
  171. RegisterServerEvent('esx_moneywash:withdraw')
  172. AddEventHandler('esx_moneywash:withdraw', function(amount)
  173. local _source = source
  174. local xPlayer = ESX.GetPlayerFromId(_source)
  175. local accountMoney = 0
  176. accountMoney = xPlayer.getAccount('black_money').money
  177. amount = accountMoney
  178. if amount == nil or amount <= 0 or amount > accountMoney then
  179. TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
  180. else
  181. TriggerClientEvent('NativeUI:progress', -1)
  182. xPlayer.removeAccountMoney('black_money', amount)
  183.  
  184. -- delay time (1 second = 1000ms) before user gets their clean money
  185. Citizen.Wait(Config.NotificationLockTime * 1000) -- 3.5 minutes (210000)
  186. xPlayer.addMoney(amount)
  187. TriggerClientEvent('esx:showNotification', _source, _U('wash_money') .. amount .. '~s~.')
  188. TriggerClientEvent('esx_moneywash:closeWASH', _source)
  189. end
  190. end)
  191. [5:57 AM] JohnAA12: You have to send the value to the client
  192. [5:57 AM] JohnAA12: also why do you have the wash show for all players
  193. [5:57 AM] JohnAA12: TriggerClientEvent('NativeUI:progress', -1)
  194. [5:58 AM] lowheartrate: I only want to show the progress bar for the client that has started it but need it to only happen if the amount is not 0/nil
  195. [5:59 AM] JohnAA12: You need to make the -1 _source for only the client that started it
  196. [5:59 AM] JohnAA12: and pass the amount in for the triggerclientevent
  197. [5:59 AM] JohnAA12: then add the value on the client part to show that amount
  198. [6:00 AM] lowheartrate: so this should go into the client event:
  199. local _source = source
  200. local xPlayer = ESX.GetPlayerFromId(_source)
  201. local accountMoney = 0
  202. accountMoney = xPlayer.getAccount('black_money').money
  203. [6:00 AM] JohnAA12: no
  204. [6:00 AM] JohnAA12: You just send the amount
  205. [6:00 AM] JohnAA12: theres no xplayer on the client
  206. [6:02 AM] JohnAA12:
  207. RegisterServerEvent('esx_moneywash:withdraw')
  208.  
  209. AddEventHandler('esx_moneywash:withdraw', function(amount)
  210. Citizen.CreateThread(function()
  211. local _source = source
  212. local xPlayer = ESX.GetPlayerFromId(_source)
  213. local accountMoney = 0
  214. accountMoney = xPlayer.getAccount('black_money').money
  215. amount = accountMoney
  216.  
  217. if amount == nil or amount <= 0 or amount > accountMoney then
  218. TriggerClientEvent('esx:showNotification', _source, _U('invalid_amount'))
  219. else
  220. TriggerClientEvent('NativeUI:progress', _source, amount)
  221. xPlayer.removeAccountMoney('black_money', amount)
  222. local savedPlayer = xPlayer
  223. -- delay time (1 second = 1000ms) before user gets their clean money
  224. Citizen.Wait(Config.NotificationLockTime * 1000) -- 3.5 minutes (210000)
  225. savedPlayer.addMoney(amount)
  226. TriggerClientEvent('esx:showNotification', _source, _U('wash_money') .. amount .. '~s~.')
  227. TriggerClientEvent('esx_moneywash:closeWASH', _source)
  228. end
  229. end)
  230. end)
  231. [6:03 AM] JohnAA12: You need to have the Citizen.Wait() in a thread for it to work properly i think
  232. [6:03 AM] JohnAA12: and then on the client part
  233. [6:03 AM] JohnAA12:
  234. RegisterNetEvent('NativeUI:progress')
  235. AddEventHandler('NativeUI:progress', function(accountMoney)
  236. local _progressBarPool = NativeUI.ProgressBarPool()
  237. local progress = 0
  238. Citizen.CreateThread(function()
  239. while true do
  240. Citizen.Wait(1)
  241. _progressBarPool:Draw()
  242. end
  243. end)
  244.  
  245. local Item = NativeUI.CreateProgressBarItem("Washing $" .. accountMoney .. "!")
  246. _progressBarPool:Add(Item)
  247.  
  248. Citizen.CreateThread(function()
  249. while true do
  250. Citizen.Wait(1000)
  251. if (progress >= 100) then
  252. progress = 0
  253. else
  254. -- each second add 0.4761904761904762 to the progress bar - will be at >= 100 in 3.5 minutes
  255. progress = progress + 0.4761904761904762
  256. end
  257. Item:SetPercentage(progress)
  258. end
  259. end)
  260. end)
  261. [6:05 AM] lowheartrate: Sorry, but how would I go about getting the client's accountMoney from there if I can't use the xPlayer.
  262. [6:06 AM] JohnAA12: You send the number on the TriggerClientEvent
  263. [6:06 AM] JohnAA12: you wouldn't use xPlayer on the client
  264. [6:06 AM] JohnAA12: I put it there for you it should work
  265. [6:06 AM] lowheartrate: oh, i don't have to somehow define the accountMoney in the client event then?
  266. [6:07 AM] JohnAA12: It is defined
  267. [6:07 AM] JohnAA12: AddEventHandler('NativeUI:progress', function(accountMoney)
  268. [6:10 AM] lowheartrate: PERFECT!
  269. [6:10 AM] lowheartrate: thanks so much for all your help :smiley:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement