Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. local carFuel = {};
  2.  
  3. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
  4. function()
  5. local xml = xmlLoadFile("carData.xml");
  6. local xmlNodes = xmlNodeGetChildren(xml);
  7. for i,node in ipairs(xmlNodes) do
  8. carFuel[tonumber(xmlNodeGetAttribute(node,'id'))] = tonumber(xmlNodeGetAttribute(node,'fuel'));
  9. end
  10. xmlUnloadFile(xml);
  11. end
  12. )
  13.  
  14. addEvent("onPedSyphonFuel",true);
  15. function startSyphon()
  16. if not isPedInVehicle(localPlayer) then
  17. if isPedOnGround(localPlayer) then
  18. local px, py, pz = getElementPosition(localPlayer);
  19. local rot = getPedRotation(localPlayer);
  20.  
  21. local a = math.rad(90 - rot);
  22.  
  23. local dx = math.cos(a) * 1.5;
  24. local dy = math.sin(a) * 1.5;
  25. local ppx = math.cos(a) * 0.2;
  26. local ppy = math.sin(a) * 0.2;
  27.  
  28. local ex = px-dx;
  29. local ey = py+dy;
  30. px = px-ppx;
  31. py = py+ppy;
  32. hit, x, y, z, elementHit = processLineOfSight(px, py, pz+1, ex, ey, pz);
  33. if elementHit then
  34. if getElementType(elementHit) == 'vehicle' then
  35. triggerServerEvent('pedSyphonVehicle',localPlayer,elementHit);
  36. end
  37. end
  38. end
  39. end
  40. end
  41. addEventHandler("onPedSyphonFuel",getRootElement(),startSyphon);
  42. addCommandHandler('syphon',startSyphon)
  43.  
  44. addEvent("onPedReFuel",true);
  45. function fillHerUp()
  46. local vehicle = getPedOccupiedVehicle(localPlayer);
  47. if not isPedInVehicle(localPlayer) then
  48. if isPedOnGround(localPlayer) then
  49. local px, py, pz = getElementPosition(localPlayer);
  50. local rot = getPedRotation(localPlayer);
  51.  
  52. local a = math.rad(90 - rot);
  53.  
  54. local dx = math.cos(a) * 1.5;
  55. local dy = math.sin(a) * 1.5;
  56. local ppx = math.cos(a) * 0.2;
  57. local ppy = math.sin(a) * 0.2;
  58.  
  59. local ex = px-dx;
  60. local ey = py+dy;
  61. px = px-ppx;
  62. py = py+ppy;
  63. hit, x, y, z, elementHit = processLineOfSight(px, py, pz+1, ex, ey, pz);
  64. if elementHit then
  65. if getElementType(elementHit) == 'vehicle' then
  66. triggerServerEvent('pedRefuelVehicle',localPlayer,elementHit);
  67. end
  68. end
  69. end
  70. end
  71. end
  72. addEventHandler("onPedReFuel",getRootElement(),fillHerUp);
  73. addCommandHandler('refuel',fillHerUp)
  74.  
  75. function drawGUI()
  76. local vehicle = getPedOccupiedVehicle(localPlayer);
  77. if vehicle then
  78. local x,y = guiGetScreenSize();
  79. if getVehicleType(vehicle) ~= 'Automobile' and getVehicleType(vehicle) ~= 'Bike' and getVehicleType(vehicle) ~= 'Monster Truck' and getVehicleType(vehicle) ~= 'Quad' then return end
  80. local driver = getVehicleController(vehicle);
  81. if driver ~= localPlayer then return end --###
  82. if getVehicleEngineState(vehicle) == false then return end --###
  83. dxDrawRectangle(x-53,(y/2)-75,40,142,0x66224466);
  84. local maxFuel = carFuel[0];
  85. local curFuel = getElementData(vehicle,'fuel');
  86. local carHealth = getElementHealth(vehicle)/10;
  87. if curFuel == false then return end
  88. if carFuel[getElementModel(vehicle)] then maxFuel = carFuel[getElementModel(vehicle)]; end
  89. local fuel = (curFuel/maxFuel)*100;
  90. local colour = nil;
  91. if fuel > 90 then
  92. colour = 0x9922CC33;
  93. dxDrawRectangle(x-30,(y/2)-71,16,21,colour);
  94. end
  95. if fuel > 75 then
  96. if colour == nil then
  97. colour = 0x99009900;
  98. end
  99. dxDrawRectangle(x-30,(y/2)-48,16,21,colour);
  100. end
  101. if fuel > 60 then
  102. if colour == nil then
  103. colour = 0x99339900;
  104. end
  105. dxDrawRectangle(x-30,(y/2)-25,16,21,colour);
  106. end
  107. if fuel > 45 then
  108. if colour == nil then
  109. colour = 0x99999900;
  110. end
  111. dxDrawRectangle(x-30,(y/2)-2,16,21,colour);
  112. end
  113. if fuel > 30 then
  114. if colour == nil then
  115. colour = 0x99996600;
  116. end
  117. dxDrawRectangle(x-30,(y/2)+21,16,21,colour);
  118. end
  119. if colour == nil then
  120. if fuel > 15 then
  121. colour = 0x99993300;
  122. else
  123. colour = 0x99990000;
  124. end
  125. end
  126. dxDrawRectangle(x-30,(y/2)+44,16,21,colour);
  127. local HealthHeight = ((136/100)*carHealth);
  128. local yOffset = HealthHeight-136
  129. dxDrawRectangle(x-50,(y/2)-71-yOffset,16,HealthHeight,0x99990000);
  130.  
  131. dxDrawText(tostring(carHealth)..'%',x-105,y-65);
  132. dxDrawText(tostring(fuel)..'%',x-105,y-50);
  133. end
  134. end
  135. addEventHandler("onClientRender",getRootElement(),drawGUI);
  136.  
  137.  
  138. addEventHandler("onClientElementStreamIn",getRootElement(),function ()
  139. if getElementType(source) ~= 'vehicle' then return end
  140. if getVehicleType(source) ~= 'Automobile' and getVehicleType(source) ~= 'Bike' and getVehicleType(source) ~= 'Monster Truck' and getVehicleType(source) ~= 'Quad' then return end
  141. triggerServerEvent('giveVehicleFuelOnSpawn',source);
  142. end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement