Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.82 KB | None | 0 0
  1.  
  2. -- this module define a generic system to transform (generate, process, convert) items and money to other items or money in a specific area
  3. -- each transformer can take things to generate other things, using a unit of work
  4. -- units are generated periodically at a specific rate
  5. -- reagents => products (reagents can be nothing, as for an harvest transformer)
  6.  
  7. local cfg = module("cfg/item_transformers")
  8. local lang = vRP.lang
  9.  
  10. -- api
  11.  
  12. local transformers = {}
  13. local cops_number = 0
  14. local busi_sell_sal = {}
  15.  
  16.  
  17. local function tr_remove_player(tr,player) -- remove player from transforming
  18. local recipe = tr.players[player] or ""
  19. tr.players[player] = nil -- dereference player
  20. if busi_sell_sal[player] then
  21. if busi_sell_sal[player] ~= 0 then
  22. vRP.addBookSell(player,busi_sell_sal[player])
  23. end
  24. end
  25. busi_sell_sal[player] = nil
  26. vRP.closeMenu(player)
  27.  
  28. if tr.itemtr.local_process == nil then
  29. vRPclient.removeProgressBar(player,{"vRP:tr:"..tr.name})
  30.  
  31. -- onstop
  32. if tr.itemtr.onstop then tr.itemtr.onstop(player,recipe) end
  33. else
  34. TriggerClientEvent("tr:stopTickClient",player)
  35. end
  36. end
  37.  
  38. local function tr_add_player(tr,player,recipe) -- add player to transforming
  39. tr.players[player] = recipe -- reference player as using transformer
  40. busi_sell_sal[player] = 0
  41. vRP.closeMenu(player)
  42.  
  43. if tr.itemtr.local_process == nil then
  44. vRPclient.setProgressBar(player,{"vRP:tr:"..tr.name,"center",recipe.."...",tr.itemtr.r,tr.itemtr.g,tr.itemtr.b,0})
  45. -- onstart
  46. if tr.itemtr.onstart then tr.itemtr.onstart(player,recipe) end
  47. else
  48. TriggerClientEvent("tr:startTickClient",player, tr)
  49. end
  50. end
  51.  
  52. -- enable to get a specific number of products whith a % of luck
  53. local function proba_recipes(max_recip_chance, product_identifier)
  54. local bloopis = math.random(0,1000)
  55.  
  56. if bloopis <= max_recip_chance then
  57. -- with this, if user have chance to drop product, he have a new chance to drop from 1 to X rare product !!
  58. return math.random(1,cfg.special_products[product_identifier])
  59. else
  60. return 0
  61. end
  62.  
  63. end
  64.  
  65. -- This method enable to apply a reduction % on dirty money depending on cops number
  66. -- This is to avoid "safe farming"
  67. local function apply_reduce_dirty(dirty, k)
  68. local percent = cfg.cops_reduce[cops_number]
  69. local new_dirty
  70.  
  71. if percent == nil then
  72. -- if percent is nil, we are in case nb cop > max value in array
  73. -- so we apply 100 % price
  74. percent = 100
  75. new_dirty = dirty
  76. else
  77. new_dirty = math.floor((dirty * percent)/100)
  78. end
  79.  
  80. if percent < 100 then
  81. -- send RP message to inform user that the price is reduced
  82. vRPclient.notify(k, {"Ouech GROS ! Moins d'Flics => Moins d'Risques. Moins d'Risques => Moins d'Thunes"})
  83. else
  84. vRPclient.notify(k, {"Money ! Money ! Money !"})
  85. end
  86.  
  87. return new_dirty
  88. end
  89.  
  90. RegisterServerEvent('tr:tickClient')
  91. AddEventHandler('tr:tickClient', function(tr)
  92. local _tr = tr
  93. local _source = source
  94. local serrat = _tr.players[_source]
  95. local user_id = vRP.getUserId(_source)
  96. if serrat and user_id ~= nil then -- for each player transforming
  97. local recipe = _tr.itemtr.recipes[serrat]
  98. if recipe then -- check units
  99.  
  100.  
  101. -- check reagents
  102. local reagents_ok = true
  103. for l,w in pairs(recipe.reagents) do
  104. reagents_ok = reagents_ok and (vRP.getInventoryItemAmount(user_id,l) >= w)
  105. end
  106.  
  107.  
  108. -- weight check
  109. local out_witems = {}
  110. local finalItems = {}
  111. for k,v in pairs(recipe.products) do
  112. -- we check by contains if the current product need a special treatment
  113. if cfg.special_products[k] then
  114. local value = proba_recipes(v, k)
  115.  
  116. if value > 0 then
  117. finalItems[k] = value
  118. out_witems[k] = {amount=value}
  119. end
  120.  
  121. else
  122. out_witems[k] = {amount=v}
  123. finalItems[k] = v
  124. end
  125. end
  126.  
  127.  
  128. local in_witems = {}
  129. for k,v in pairs(recipe.reagents) do
  130. in_witems[k] = {amount=v}
  131. end
  132. local new_weight = vRP.getInventoryWeight(user_id)+vRP.computeItemsWeight(out_witems)-vRP.computeItemsWeight(in_witems)
  133.  
  134. local inventory_ok = true
  135. if new_weight > vRP.getInventoryMaxWeight(user_id) then
  136. inventory_ok = false
  137. vRPclient.notify(tonumber(_source), {lang.inventory.full()})
  138. TriggerClientEvent("tr:stopTickClient",_source)
  139. end
  140.  
  141. if recipe.in_money > 0 then vRP.tryPayment(user_id,recipe.in_money) end
  142. for l,w in pairs(recipe.reagents) do
  143. vRP.tryGetInventoryItem(user_id,l,w,true)
  144. end
  145.  
  146. if reagents_ok and inventory_ok then -- do transformation
  147. -- produce products
  148. if recipe.out_money > 0 then
  149. vRP.getBussinessPlayer(user_id, function(busi)
  150. if busi and recipe.description ~= "Vente de gibier" or recipe.description ~= "Vente de peche" then
  151. -- user have business and recipe doesn't concern hunting "job"
  152. -- set productivity
  153. vRP.getProductivityPlayer(user_id, function(prod_val)
  154. prod_val = prod_val + recipe.out_money
  155. vRP.setProductivityPlayer(user_id,prod_val)
  156.  
  157. if busi_sell_sal[_source] then
  158. busi_sell_sal[_source] = busi_sell_sal[_source] + recipe.out_money
  159. -- print("ITEM TRANSFORMER : sauvegarde vente "..busi_sell_sal[_source].." pour ".._source)
  160. end
  161.  
  162. -- update business treasury
  163. vRP.addBusiTreasury(busi.busi_id,recipe.out_money)
  164. end)
  165. else
  166. vRP.giveMoney(user_id,recipe.out_money)
  167. end
  168. end)
  169. end
  170.  
  171. for l,w in pairs(recipe.products) do
  172. if finalItems[l] then
  173. if l == "dirty_money" then
  174. local final_dirty = apply_reduce_dirty(finalItems[l],k)
  175. vRP.giveInventoryItem(user_id,l,final_dirty,true)
  176. else
  177. vRP.giveInventoryItem(user_id,l,finalItems[l],true)
  178. end
  179. end
  180. end
  181.  
  182. -- give exp
  183. for l,w in pairs(recipe.aptitudes or {}) do
  184. local parts = splitString(l,".")
  185. if #parts == 2 then
  186. vRP.varyExp(user_id,parts[1],parts[2],w)
  187. end
  188. end
  189. else
  190. TriggerClientEvent("tr:stopTickClient",_source)
  191. end
  192.  
  193. end
  194. end
  195. end)
  196.  
  197. local function tr_tick(tr) -- do transformer tick
  198. for k,v in pairs(tr.players) do
  199. vRPclient.isPlayerInVehicle(tonumber(k), {}, function(in_veh)
  200.  
  201. if not in_veh then
  202. vRPclient.isInComa(tonumber(k),{}, function(in_coma)
  203. if not in_coma then
  204. local user_id = vRP.getUserId(tonumber(k))
  205. if v and user_id ~= nil then -- for each player transforming
  206. local recipe = tr.itemtr.recipes[v]
  207. if tr.units > 0 and recipe then -- check units
  208. -- check reagents
  209. local reagents_ok = true
  210. for l,w in pairs(recipe.reagents) do
  211. reagents_ok = reagents_ok and (vRP.getInventoryItemAmount(user_id,l) >= w)
  212. end
  213.  
  214. -- check money
  215. local money_ok = (vRP.getMoney(user_id) >= recipe.in_money)
  216.  
  217. -- weight check
  218. local out_witems = {}
  219. local finalItems = {}
  220. for k,v in pairs(recipe.products) do
  221. -- we check by contains if the current product need a special treatment
  222. if cfg.special_products[k] then
  223. local value = proba_recipes(v, k)
  224.  
  225. if value > 0 then
  226. finalItems[k] = value
  227. out_witems[k] = {amount=value}
  228. end
  229.  
  230. else
  231. out_witems[k] = {amount=v}
  232. finalItems[k] = v
  233. end
  234. end
  235. local in_witems = {}
  236. for k,v in pairs(recipe.reagents) do
  237. in_witems[k] = {amount=v}
  238. end
  239. local new_weight = vRP.getInventoryWeight(user_id)+vRP.computeItemsWeight(out_witems)-vRP.computeItemsWeight(in_witems)
  240.  
  241. local inventory_ok = true
  242. if new_weight > vRP.getInventoryMaxWeight(user_id) then
  243. inventory_ok = false
  244. vRPclient.notify(tonumber(k), {lang.inventory.full()})
  245. end
  246.  
  247. if money_ok and reagents_ok and inventory_ok then -- do transformation
  248. tr.units = tr.units-1 -- sub work unit
  249.  
  250. -- consume reagents
  251. if recipe.in_money > 0 then vRP.tryPayment(user_id,recipe.in_money) end
  252. for l,w in pairs(recipe.reagents) do
  253. vRP.tryGetInventoryItem(user_id,l,w,true)
  254. end
  255.  
  256. -- produce products
  257. if recipe.out_money > 0 then
  258. vRP.getBussinessPlayer(user_id, function(busi)
  259. if busi and recipe.business == nil then
  260. -- user have business and recipe doesn't concern hunting "job"
  261. -- set productivity
  262. vRP.getProductivityPlayer(user_id, function(prod_val)
  263. prod_val = prod_val + recipe.out_money
  264. vRP.setProductivityPlayer(user_id,prod_val)
  265.  
  266. if busi_sell_sal[tonumber(k)] then
  267. busi_sell_sal[tonumber(k)] = busi_sell_sal[tonumber(k)] + recipe.out_money
  268. -- print("ITEM TRANSFORMER : sauvegarde vente "..busi_sell_sal[tonumber(k)].." pour "..tonumber(k))
  269. end
  270.  
  271. -- update business treasury
  272. vRP.addBusiTreasury(busi.busi_id,recipe.out_money)
  273. end)
  274. else
  275. vRP.giveMoney(user_id,recipe.out_money)
  276. end
  277. end)
  278. end
  279.  
  280. for l,w in pairs(recipe.products) do
  281. if finalItems[l] then
  282. if l == "dirty_money" then
  283. local final_dirty = apply_reduce_dirty(finalItems[l],k)
  284. vRP.giveInventoryItem(user_id,l,final_dirty,true)
  285. else
  286. vRP.giveInventoryItem(user_id,l,finalItems[l],true)
  287. end
  288. end
  289. end
  290.  
  291. -- give exp
  292. for l,w in pairs(recipe.aptitudes or {}) do
  293. local parts = splitString(l,".")
  294. if #parts == 2 then
  295. vRP.varyExp(user_id,parts[1],parts[2],w)
  296. end
  297. end
  298.  
  299. -- onstep
  300. if tr.itemtr.onstep then tr.itemtr.onstep(tonumber(k),v) end
  301. end
  302. end
  303. end
  304. end
  305. end)
  306. else
  307. vRPclient.notify(tonumber(k), {lang.collect.not_allowed_vehicle()})
  308. end
  309.  
  310. end)
  311. end
  312.  
  313. -- display transformation state to all transforming players
  314. for k,v in pairs(tr.players) do
  315. if tr.itemtr.local_process == nil then
  316. vRPclient.setProgressBarValue(k,{"vRP:tr:"..tr.name,math.floor(tr.units/tr.itemtr.max_units*100.0)})
  317.  
  318. if tr.units > 0 then -- display units left
  319. vRPclient.setProgressBarText(k,{"vRP:tr:"..tr.name,v.."... "..tr.units.."/"..tr.itemtr.max_units})
  320. else
  321. vRPclient.setProgressBarText(k,{"vRP:tr:"..tr.name,"Vide, rechargement en cours"})
  322. end
  323. end
  324. end
  325. end
  326.  
  327. local function bind_tr_area(player,tr) -- add tr area to client
  328. vRP.setArea(player,"vRP:tr:"..tr.name,tr.itemtr.x,tr.itemtr.y,tr.itemtr.z,tr.itemtr.radius,tr.itemtr.height,tr.enter,tr.leave)
  329. end
  330.  
  331. local function unbind_tr_area(player,tr) -- remove tr area from client
  332. vRP.removeArea(player,"vRP:tr:"..tr.name)
  333. end
  334.  
  335. -- add an item transformer
  336. -- name: transformer id name
  337. -- itemtr: item transformer definition table
  338. --- name
  339. --- max_units
  340. --- units_per_minute
  341. --- x,y,z,radius,height (area properties)
  342. --- r,g,b (color)
  343. --- action
  344. --- description
  345. --- in_money
  346. --- out_money
  347. --- reagents: items as idname => amount
  348. --- products: items as idname => amount
  349. function vRP.setItemTransformer(name,itemtr)
  350. vRP.removeItemTransformer(name) -- remove pre-existing transformer
  351.  
  352. local tr = {itemtr=itemtr}
  353. tr.name = name
  354. transformers[name] = tr
  355.  
  356. -- init transformer
  357. tr.units = 0
  358. tr.players = {}
  359.  
  360. -- build menu
  361. tr.menu = {name=itemtr.name,css={top="75px",header_color="rgba("..itemtr.r..","..itemtr.g..","..itemtr.b..",0.75)"}}
  362.  
  363. -- build recipes
  364. for action,recipe in pairs(tr.itemtr.recipes) do
  365. local info = "<br /><br />"
  366. if recipe.in_money > 0 then info = info.."- "..recipe.in_money end
  367. for k,v in pairs(recipe.reagents) do
  368. local item = vRP.items[k]
  369. if item then
  370. info = info.."<br />"..v.." "..item.name
  371. end
  372. end
  373. info = info.."<br /><span style=\"color: rgb(0,255,125)\">=></span>"
  374. if recipe.out_money > 0 then info = info.."<br />+ "..recipe.out_money end
  375. for k,v in pairs(recipe.products) do
  376. if not cfg.special_products[k] then
  377. local item = vRP.items[k]
  378. if item then
  379. info = info.."<br />"..v.." "..item.name
  380. end
  381. end
  382. end
  383. for k,v in pairs(recipe.aptitudes or {}) do
  384. local parts = splitString(k,".")
  385. if #parts == 2 then
  386. local def = vRP.getAptitudeDefinition(parts[1],parts[2])
  387. if def then
  388. info = info.."<br />[EXP] "..v.." "..vRP.getAptitudeGroupTitle(parts[1]).."/"..def[1]
  389. end
  390. end
  391. end
  392.  
  393. tr.menu[action] = {function(player,choice) tr_add_player(tr,player,action) end, recipe.description..info}
  394. end
  395.  
  396. -- build area
  397. tr.enter = function(player,area)
  398. local user_id = vRP.getUserId(player)
  399. if user_id ~= nil and vRP.hasPermissions(user_id,itemtr.permissions or {}) then
  400. vRP.openMenu(player, tr.menu) -- open menu
  401. end
  402. end
  403.  
  404. tr.leave = function(player,area)
  405. tr_remove_player(tr, player)
  406. end
  407.  
  408. -- bind tr area to all already spawned players
  409. for k,v in pairs(vRP.rusers) do
  410. local source = vRP.getUserSource(k)
  411. if source ~= nil then
  412. bind_tr_area(source,tr)
  413. end
  414. end
  415. end
  416.  
  417. -- remove an item transformer
  418. function vRP.removeItemTransformer(name)
  419. local tr = transformers[name]
  420. if tr then
  421. -- copy players (to remove while iterating)
  422. local players = {}
  423. for k,v in pairs(tr.players) do
  424. players[k] = v
  425. end
  426.  
  427. for k,v in pairs(players) do -- remove players from transforming
  428. tr_remove_player(tr,k)
  429. end
  430.  
  431. -- remove tr area from all already spawned players
  432. for k,v in pairs(vRP.rusers) do
  433. local source = vRP.getUserSource(k)
  434. if source ~= nil then
  435. unbind_tr_area(source,tr)
  436. end
  437. end
  438.  
  439. transformers[name] = nil
  440. end
  441. end
  442.  
  443. -- task: transformers ticks (every 3 seconds)
  444. local function transformers_tick()
  445. SetTimeout(0,function() -- error death protection for transformers_tick()
  446. for k,tr in pairs(transformers) do
  447. tr_tick(tr)
  448. end
  449. end)
  450.  
  451. SetTimeout(3000,transformers_tick)
  452. end
  453. transformers_tick()
  454.  
  455. -- task: transformers unit regeneration
  456. local function transformers_regen()
  457. for k,tr in pairs(transformers) do
  458. if tr.itemtr.local_process == nil then
  459. tr.units = tr.units+tr.itemtr.units_per_minute
  460. if tr.units >= tr.itemtr.max_units then tr.units = tr.itemtr.max_units end
  461. end
  462. end
  463.  
  464. SetTimeout(60000,transformers_regen)
  465. end
  466. transformers_regen()
  467.  
  468. -- add transformers areas on player first spawn
  469. AddEventHandler("vRP:playerSpawn",function(user_id, source, first_spawn)
  470. if first_spawn then
  471. for k,tr in pairs(transformers) do
  472. bind_tr_area(source,tr)
  473. end
  474. end
  475. end)
  476.  
  477. -- STATIC TRANSFORMERS
  478.  
  479. SetTimeout(5000,function()
  480. -- delayed to wait items loading
  481. -- load item transformers from config file
  482. for k,v in pairs(cfg.item_transformers) do
  483. vRP.setItemTransformer("cfg:"..k,v)
  484. end
  485. end)
  486.  
  487. -- HIDDEN TRANSFORMERS
  488.  
  489. -- generate a random position for the hidden transformer
  490. local function gen_random_position(positions)
  491. local n = #positions
  492. if n > 0 then
  493. return positions[math.random(1,n)]
  494. else
  495. return {0,0,0}
  496. end
  497. end
  498.  
  499. local function hidden_placement_tick()
  500. vRP.getSData("vRP:hidden_trs", function(data)
  501. local hidden_trs = json.decode(data) or {}
  502.  
  503. for k,v in pairs(cfg.hidden_transformers) do
  504. -- init entry
  505. local htr = hidden_trs[k]
  506. if htr == nil then
  507. hidden_trs[k] = {timestamp=parseInt(os.time()), position=gen_random_position(v.positions)}
  508. htr = hidden_trs[k]
  509. end
  510.  
  511. -- remove hidden transformer if needs respawn
  512. if tonumber(os.time())-htr.timestamp >= cfg.hidden_transformer_duration*60 then
  513. htr.timestamp = parseInt(os.time())
  514. vRP.removeItemTransformer("cfg:"..k)
  515. -- generate new position
  516. htr.position = gen_random_position(v.positions)
  517. end
  518.  
  519. -- spawn if unspawned
  520. if transformers["cfg:"..k] == nil then
  521. v.def.x = htr.position[1]
  522. v.def.y = htr.position[2]
  523. v.def.z = htr.position[3]
  524.  
  525. vRP.setItemTransformer("cfg:"..k, v.def)
  526. end
  527. end
  528.  
  529. vRP.setSData("vRP:hidden_trs",json.encode(hidden_trs)) -- save hidden transformers
  530. end)
  531.  
  532. SetTimeout(300000, hidden_placement_tick)
  533. end
  534. SetTimeout(5000, hidden_placement_tick) -- delayed to wait items loading
  535. --[[
  536. -- special tick for dealer
  537. local dealer_trs = {}
  538. local function dealer_placement_tick()
  539. for k,v in pairs(cfg.dealer_transformers) do
  540. -- init entry
  541. local htr = dealer_trs[k]
  542. if htr == nil then
  543. dealer_trs[k] = {timestamp=parseInt(os.time()), position=gen_random_position(v.positions)}
  544. htr = dealer_trs[k]
  545. end
  546.  
  547. -- remove dealer transformer
  548. if transformers["cfg:"..k] then
  549.  
  550. local timer = tonumber(os.time())-htr.timestamp
  551. -- remove only when transformers exist and max duration is reached
  552. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_duration then
  553. htr.timestamp = parseInt(os.time())
  554. vRP.removeItemTransformer("cfg:"..k)
  555. -- generate new position
  556. htr.position = gen_random_position(v.positions)
  557.  
  558. -- delete marker if unspawned
  559. for k,v in pairs(vRP.rusers) do
  560. local player = vRP.getUserSource(tonumber(k))
  561. vRPclient.removeNamedBlip(player,{"vRP:Dealer"})
  562. vRPclient.removeNamedMarker(player,{"VRP:Dealer"})
  563.  
  564. end
  565. end
  566. end
  567.  
  568. -- spawn if unspawned and wait respawn time is over
  569. if transformers["cfg:"..k] == nil then
  570. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_spawn_time then
  571. htr.position = gen_random_position(v.positions)
  572. v.def.x = htr.position[1]
  573. v.def.y = htr.position[2]
  574. v.def.z = htr.position[3]
  575.  
  576. for users,values in pairs(vRP.rusers) do
  577. local player = vRP.getUserSource(tonumber(users))
  578. data = vRP.getUserDataTable(users)
  579.  
  580. if data.groups["Police"] and data.groups["cop"] then
  581. vRPclient.removeNamedBlip(player,{"vRP:Dealer"})
  582. vRPclient.removeNamedMarker(player,{"VRP:Dealer"})
  583. else
  584. -- add dealer blip/marker
  585. vRPclient.setNamedBlip(player,{"vRP:Dealer",v.def.x,v.def.y,v.def.z,496,1,lang.drugssdeal.deal.title()})
  586. vRPclient.setNamedMarker(player,{"vRP:Dealer",v.def.x,v.def.y,v.def.z-1,0.7,0.7,0.5,0,255,125,125,150})
  587. --vRPclient.notify(player,{"L'acheteur de drogue vient d'apparaitre sur la carte"})
  588. end
  589. end
  590. vRP.setItemTransformer("cfg:"..k, v.def)
  591. end
  592. end
  593. end
  594.  
  595. SetTimeout(600000, dealer_placement_tick)
  596. end
  597. SetTimeout(6000, dealer_placement_tick) -- delayed to wait items loading
  598. --]]
  599. --black market
  600. local bmarket_trs = {}
  601. local function bmarket_placement_tick()
  602. for k,v in pairs(cfg.blackmarket_transformers) do
  603. -- init entry
  604. local htr = bmarket_trs[k]
  605. if htr == nil then
  606. bmarket_trs[k] = {timestamp=parseInt(os.time()), position=gen_random_position(v.positions)}
  607. htr = bmarket_trs[k]
  608. end
  609.  
  610. -- remove dealer transformer
  611. if transformers["cfg:"..k] then
  612.  
  613. local timer = tonumber(os.time())-htr.timestamp
  614. -- remove only when transformers exist and max duration is reached
  615. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_duration then
  616. htr.timestamp = parseInt(os.time())
  617. vRP.removeItemTransformer("cfg:"..k)
  618. -- generate new position
  619. htr.position = gen_random_position(v.positions)
  620.  
  621. -- delete marker if unspawned
  622. for k,v in pairs(vRP.rusers) do
  623. local player = vRP.getUserSource(tonumber(k))
  624. vRPclient.removeNamedBlip(player,{"vRP:bmarket"})
  625. vRPclient.removeNamedMarker(player,{"VRP:bmarket"})
  626.  
  627. end
  628. end
  629. end
  630.  
  631. -- spawn if unspawned and wait respawn time is over
  632. if transformers["cfg:"..k] == nil then
  633. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_spawn_time then
  634. htr.position = gen_random_position(v.positions)
  635. v.def.x = htr.position[1]
  636. v.def.y = htr.position[2]
  637. v.def.z = htr.position[3]
  638.  
  639. for users,values in pairs(vRP.rusers) do
  640. local player = vRP.getUserSource(tonumber(users))
  641. data = vRP.getUserDataTable(users)
  642.  
  643. if data.groups["Police"] and data.groups["cop"] then
  644. vRPclient.removeNamedBlip(player,{"vRP:bmarket"})
  645. vRPclient.removeNamedMarker(player,{"VRP:bmarket"})
  646. else
  647. -- add dealer blip/marker
  648. vRPclient.setNamedBlip(player,{"vRP:bmarket",v.def.x,v.def.y,v.def.z,207,1,lang.bmarketmain.bmarket.title()})
  649. vRPclient.setNamedMarker(player,{"vRP:bmarket",v.def.x,v.def.y,v.def.z-1,0.7,0.7,0.5,0,255,125,125,150})
  650. --vRPclient.notify(player,{"L'acheteur d'alcool vient d'apparaitre sur la carte"})
  651. end
  652. end
  653. vRP.setItemTransformer("cfg:"..k, v.def)
  654. end
  655. end
  656. end
  657.  
  658. SetTimeout(700000, bmarket_placement_tick)
  659. end
  660. --SetTimeout(6000, bmarket_placement_tick) -- delayed to wait items loading
  661. SetTimeout(300000, bmarket_placement_tick) -- delayed to wait items loading
  662. -- special tick for dealer
  663.  
  664. local dealerbis_trs = {}
  665. local function dealerbis_placement_tick()
  666. for k,v in pairs(cfg.dealerbis_transformers) do
  667. -- init entry
  668. local htr = dealerbis_trs[k]
  669. if htr == nil then
  670. dealerbis_trs[k] = {timestamp=parseInt(os.time()), position=gen_random_position(v.positions)}
  671. htr = dealerbis_trs[k]
  672. end
  673.  
  674. -- remove dealer transformer
  675. if transformers["cfg:"..k] then
  676.  
  677. local timer = tonumber(os.time())-htr.timestamp
  678. -- remove only when transformers exist and max duration is reached
  679. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_duration then
  680. htr.timestamp = parseInt(os.time())
  681. vRP.removeItemTransformer("cfg:"..k)
  682. -- generate new position
  683. htr.position = gen_random_position(v.positions)
  684.  
  685. -- delete marker if unspawned
  686. for k,v in pairs(vRP.rusers) do
  687. local player = vRP.getUserSource(tonumber(k))
  688. vRPclient.removeNamedBlip(player,{"vRP:Dealerbis"})
  689. vRPclient.removeNamedMarker(player,{"VRP:Dealerbis"})
  690.  
  691. end
  692. end
  693. end
  694.  
  695. -- spawn if unspawned and wait respawn time is over
  696. if transformers["cfg:"..k] == nil then
  697. if tonumber(os.time())-htr.timestamp >= cfg.dealer_transformer_spawn_time then
  698. htr.position = gen_random_position(v.positions)
  699. v.def.x = htr.position[1]
  700. v.def.y = htr.position[2]
  701. v.def.z = htr.position[3]
  702.  
  703. for users,values in pairs(vRP.rusers) do
  704. local player = vRP.getUserSource(tonumber(users))
  705. data = vRP.getUserDataTable(users)
  706.  
  707. if data.groups["Police"] and data.groups["cop"] then
  708. vRPclient.removeNamedBlip(player,{"vRP:Dealerbis"})
  709. vRPclient.removeNamedMarker(player,{"VRP:Dealerbis"})
  710. else
  711. -- add dealer blip/marker
  712. vRPclient.setNamedBlip(player,{"vRP:Dealerbis",v.def.x,v.def.y,v.def.z,93,1,lang.drugssdealbis.dealbis.title()})
  713. vRPclient.setNamedMarker(player,{"vRP:Dealerbis",v.def.x,v.def.y,v.def.z-1,0.7,0.7,0.5,0,255,125,125,150})
  714. --vRPclient.notify(player,{"L'acheteur d'alcool vient d'apparaitre sur la carte"})
  715. end
  716. end
  717. vRP.setItemTransformer("cfg:"..k, v.def)
  718. end
  719. end
  720. end
  721.  
  722. SetTimeout(700000, dealerbis_placement_tick)
  723. end
  724. SetTimeout(6000, dealerbis_placement_tick) -- delayed to wait items loading
  725.  
  726.  
  727. -- INFORMER
  728.  
  729. -- build informer menu
  730. local informer_menu = {name=lang.itemtr.informer.title(), css={top="75px",header_color="rgba(0,255,125,0.75)"}}
  731. local function get_choice_index(choice)
  732. local result = 0
  733. for i=1,#cfg.informerbis do
  734. if choice == cfg.informerbis[i][1] then
  735. -- save index
  736. result = i
  737. break
  738. end
  739. end
  740.  
  741. return result
  742. end
  743.  
  744. local function ch_informer_buy(player,choice)
  745.  
  746. local user_id = vRP.getUserId(player)
  747. local choice_index = get_choice_index(choice)
  748. local tr = transformers["cfg:"..choice]
  749. local price = cfg.informerbis[choice_index][2]
  750.  
  751. if user_id ~= nil and tr ~= nil then
  752. if vRP.tryPayment(user_id, price) then
  753. vRPclient.setGPS(player, {tr.itemtr.x,tr.itemtr.y}) -- set gps marker
  754. vRPclient.notify(player, {lang.money.paid({price})})
  755. vRPclient.notify(player, {lang.itemtr.informer.bought()})
  756. else
  757. vRPclient.notify(player, {lang.money.not_enough()})
  758. end
  759. end
  760. end
  761.  
  762. --for k,v in pairs(cfg.informer.infos) do
  763. -- informer_menu[k] = {ch_informer_buy, lang.itemtr.informer.description({v})}
  764. --end
  765.  
  766. local function informer_enter()
  767. local user_id = vRP.getUserId(source)
  768. if user_id ~= nil then
  769. vRP.openMenu(source,informer_menu)
  770. end
  771. end
  772.  
  773. local function informer_leave()
  774. vRP.closeMenu(source)
  775. end
  776.  
  777. local function informer_placement_tick()
  778. local pos = gen_random_position(cfg.informer.positions)
  779. local x,y,z = table.unpack(pos)
  780. local bloozizi = math.random(1,#cfg.informerbis)
  781. for k,v in pairs(vRP.rusers) do
  782. local player = vRP.getUserSource(tonumber(k))
  783.  
  784. -- add informer blip/marker/area
  785. vRPclient.setNamedBlip(player,{"vRP:informer",x,y,z,cfg.informer.blipid,cfg.informer.blipcolor,lang.itemtr.informer.title()})
  786. vRPclient.setNamedMarker(player,{"vRP:informer",x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
  787. informer_menu = {name=lang.itemtr.informer.title(), css={top="75px",header_color="rgba(0,255,125,0.75)"}}
  788. informer_menu[cfg.informerbis[bloozizi][1]] = {ch_informer_buy, lang.itemtr.informer.description({cfg.informerbis[bloozizi][2]})}
  789. vRP.setArea(player,"vRP:informer",x,y,z,1,1.5,informer_enter,informer_leave)
  790. end
  791.  
  792. -- remove informer blip/marker/area after after a while
  793. SetTimeout(cfg.informer.duration*60000, function()
  794. for k,v in pairs(vRP.rusers) do
  795. local player = vRP.getUserSource(tonumber(k))
  796. vRPclient.removeNamedBlip(player,{"vRP:informer"})
  797. vRPclient.removeNamedMarker(player,{"vRP:informer"})
  798. vRP.removeArea(player,"vRP:informer")
  799. end
  800. end)
  801.  
  802. SetTimeout(cfg.informer.interval*60000, informer_placement_tick)
  803. end
  804. SetTimeout(cfg.informer.interval*60000,informer_placement_tick)
  805.  
  806. -- check cops number every 10 minutes
  807. local function check_cops_number()
  808. local cop = 0
  809. local data
  810.  
  811. for k,v in pairs(vRP.rusers) do
  812. data = vRP.getUserDataTable(k)
  813. if data then
  814. if data.groups then
  815.  
  816. if not vRP.getModState(k) then
  817. if data.not_working == nil then
  818. -- only if cop work
  819. if (data.groups["Police"]) or data.groups["Fbi"] or data.groups["sheriff"] then
  820. -- cop
  821. cop = cop+1
  822. end
  823. end
  824. end
  825. end
  826. end
  827. end
  828.  
  829. -- save cops number
  830. cops_number = cop
  831. SetTimeout(cfg.cops_check_time, check_cops_number)
  832. end
  833. SetTimeout(cfg.cops_check_time,check_cops_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement