LH_Lawliet

Untitled

Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. cash = 0 -- Container for loop.
  2.  
  3.  
  4. RegisterNetEvent('ReceiveUserMoney')
  5. AddEventHandler('ReceiveUserMoney', function(value)
  6.     cash = value
  7. end)
  8.  
  9.  
  10. Citizen.CreateThread(function()
  11.   while true do
  12.    Citizen.Wait(0)
  13.     if (IsNear() == true) then
  14.       TriggerServerEvent("GetUserMoney")
  15.       Citizen.Wait(math.random(100,500))  
  16.     end
  17.   end
  18. end)
  19.  
  20.  
  21.  
  22. Citizen.CreateThread(function()
  23.   if NetworkIsSessionStarted() then
  24.     for k, pos in pairs (config.pos) do
  25.       blip = AddBlipForCoord(pos[1],pos[2],pos[3])
  26.       SetBlipSprite(blip, 52)
  27.       SetBlipAsShortRange(blip, true)
  28.       BeginTextCommandSetBlipName("STRING")
  29.       AddTextComponentString("Magasin")
  30.       SetBlipScale  (blip, 0.7)
  31.       EndTextCommandSetBlipName(blip)
  32.     end
  33.   end
  34. end)
  35.  
  36.  
  37. Citizen.CreateThread(function()
  38.   while true do
  39.    Citizen.Wait(0)
  40.     if (IsNear() == true) then
  41.       drawTxt('Appuyer sur ~g~E~s~ pour accĂ©der au magasin',0,1,0.5,0.8,0.6,255,255,255,255)
  42.         if (IsControlJustPressed(1, 38) and IsNear() == true) then
  43.            
  44.               exports.ft_menuBuilder:Open("shopmenu")
  45.  
  46.         end
  47.     end
  48.   end
  49. end)
  50.  
  51.  
  52.  
  53.  
  54.  
  55. function IsNear()
  56.   local ply = GetPlayerPed(-1)
  57.   local plyCoords = GetEntityCoords(ply, 0)
  58.   for k, pos in pairs (config.pos) do
  59.     local distance = GetDistanceBetweenCoords(pos[1],pos[2],pos[3],  plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
  60.     if(distance <= 5) then
  61.       return true
  62.     end
  63.   end
  64. end
  65.  
  66.  
  67.  
  68. function drawTxt(text,font,centre,x,y,scale,r,g,b,a)
  69.   SetTextFont(font)
  70.   SetTextProportional(0)
  71.   SetTextScale(scale, scale)
  72.   SetTextColour(r, g, b, a)
  73.   SetTextDropShadow(0, 0, 0, 0,255)
  74.   SetTextEdge(1, 0, 0, 0, 255)
  75.   SetTextDropShadow()
  76.   SetTextOutline()
  77.   SetTextCentre(centre)
  78.   SetTextEntry("STRING")
  79.   AddTextComponentString(text)
  80.   DrawText(x , y)
  81. end
  82.  
  83.  
  84.  
  85.  
  86.  
  87. RegisterNetEvent('shop:buy')
  88. AddEventHandler('shop:buy', function(data)
  89. print(cash)
  90. print(data.price)
  91. print(data.object)
  92.     if data.price < cash then
  93.         TriggerServerEvent('UpdateUserMoney', -data.price)
  94.         TriggerClientEvent("player:receiveItem", data.object, 1)
  95.         exports.ft_base:Notification("Tu a acheter "..data.object..".")
  96.     else
  97.        exports.ft_base:Notification("Tu n'a pas assez d'argent sur toi.")
  98.     end
  99.  
  100. end)
Advertisement
Add Comment
Please, Sign In to add comment