OneTallor

Untitled

Jun 7th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.50 KB | None | 0 0
  1. kocsi = { [420]=true }
  2. local isDragging = false
  3. local windowOffsetX, windowOffsetY = 0, 0
  4. local myFont = dxCreateFont("taximeter/roboto.ttf",14)
  5. local sx, sy = guiGetScreenSize()
  6. windowWidth, windowsHeight = 552, 202
  7. posX = sx-400
  8. posY = sy-350
  9. local clockFont = dxCreateFont("taximeter/font.ttf",20)
  10. local megtettMeterek = 0
  11. local convertMeterToKm
  12. local showtaximeter = false
  13. local started = false
  14.  
  15. addEvent('nullazas', true)
  16. addEventHandler('nullazas', root, function()
  17.     local veh = getPedOccupiedVehicle(localPlayer)
  18.     setElementData(veh,"taxi.megtettmeter",0)
  19.     setElementData(veh,"taxi.ar",0)
  20.     setElementData(veh,"taxi.megtettkm",0)
  21.     megtettMeterek = 0
  22. end)
  23.  
  24. function taxi (thePlayer)
  25.     if showtaximeter then
  26.         if getPedOccupiedVehicleSeat(localPlayer) == 0 then
  27.             local vehicle = getPedOccupiedVehicle(getLocalPlayer())
  28.  
  29.             if getElementData(vehicle, "taxi.megtettmeter") == 0 or getElementData(vehicle, "taxi.megtettmeter") == nil or getElementData(vehicle, "taxi.megtettmeter") == false then
  30.                 setElementData(vehicle,"taxi.megtettmeter",0)
  31.             end
  32.  
  33.             if isCursorShowing() then
  34.                 cursorX, cursorY = getCursorPosition()
  35.                 cursorX, cursorY = cursorX * sx, cursorY * sy
  36.             end
  37.  
  38.             if isDragging then
  39.                 posX, posY = cursorX + windowOffsetX, cursorY + windowOffsetY
  40.             end
  41.  
  42.             if started == false then
  43.                 color = tocolor(108, 172, 111, 160)
  44.             elseif started == true then
  45.                 color = tocolor(207, 0, 15, 160)
  46.             end
  47.  
  48.             if started == false then
  49.                 if isCursorInRectangle(posX+13, posY + 90, 274, 45) then
  50.                     color = tocolor(108, 172, 111, 200)
  51.                 end
  52.             elseif started == true then
  53.                 if isCursorInRectangle(posX+13, posY + 90, 274, 45) then
  54.                     color = tocolor(207, 0, 15, 200)
  55.                 end
  56.             end
  57.  
  58.             dxDrawRectangle(posX, posY, 300, 150, tocolor(0, 0, 0, 160))
  59.             dxDrawRectangle(posX+13, posY + 35, 274, 35, tocolor(0, 0, 0, 180))
  60.             dxDrawRectangle(posX+13, posY + 90, 274, 45, color)
  61.             dxDrawText('#F7CA18SosaCity Taxi #ffffff- Viteldíj (Ft):', posX+26, posY+5, sx, sy, tocolor(255, 255, 255, 255), 1, myFont, 'left', 'top', false, false, true, true)
  62.  
  63.             if started then
  64.                 dxDrawText('Leállítás', posX+300, posY+225, posX, posY, tocolor(255, 255, 255, 255), 1, myFont, 'center', 'center')
  65.             else
  66.                 dxDrawText('Elindítás', posX+300, posY+225, posX, posY, tocolor(255, 255, 255, 255), 1, myFont, 'center', 'center')
  67.             end
  68.             convertMeterToKm = math.ceil((getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettmeter")/1000))
  69.             local maxNulla = 14
  70.             local actualCharAmount = maxNulla - string.len(tostring(getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettmeter")))
  71.             local finalString = ""
  72.                  
  73.             for i = 0, actualCharAmount, 1 do
  74.                 finalString = finalString .. "0"
  75.             end
  76.             dxDrawText(finalString .. "#7CC576" .. getElementData(vehicle,"taxi.megtettmeter"), posX+13+9, posY + 35, sx, sy, tocolor (255,255,255, 255), 1, clockFont, "left","top",true,true,true,true,true)
  77.         else
  78.             local vehicle = getPedOccupiedVehicle(getLocalPlayer())
  79.  
  80.             if getElementData(vehicle, "taxi.megtettmeter") == 0 or getElementData(vehicle, "taxi.megtettmeter") == nil or getElementData(vehicle, "taxi.megtettmeter") == false then
  81.                 setElementData(vehicle,"taxi.megtettmeter",0)
  82.             end
  83.  
  84.             if isCursorShowing() then
  85.                 cursorX, cursorY = getCursorPosition()
  86.                 cursorX, cursorY = cursorX * sx, cursorY * sy
  87.             end
  88.  
  89.             if isDragging then
  90.                 posX, posY = cursorX + windowOffsetX, cursorY + windowOffsetY
  91.             end
  92.  
  93.             dxDrawRectangle(posX, posY, 300, 150, tocolor(0, 0, 0, 160))
  94.             dxDrawRectangle(posX+13, posY + 35, 274, 35, tocolor(0, 0, 0, 180))
  95.             dxDrawText('#F7CA18SosaCity Taxi #ffffff- Viteldíj (Ft):', posX+26, posY+5, sx, sy, tocolor(255, 255, 255, 255), 1, myFont, 'left', 'top', false, false, true, true)
  96.             convertMeterToKm = math.ceil((getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettmeter")/1000))
  97.             local maxNulla = 14
  98.             local actualCharAmount = maxNulla - string.len(tostring(getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettmeter")))
  99.             local finalString = ""
  100.                  
  101.             for i = 0, actualCharAmount, 1 do
  102.                 finalString = finalString .. "0"
  103.             end
  104.             dxDrawText(finalString .. "#7CC576" .. getElementData(vehicle,"taxi.megtettmeter"), posX+13+9, posY + 35, sx, sy, tocolor (255,255,255, 255), 1, clockFont, "left","top",true,true,true,true,true)
  105.         end
  106.     end
  107. end
  108. addEventHandler("onClientRender", getRootElement(), taxi)
  109.  
  110. function isCursorInRectangle(x,y,w,h)
  111.     if isCursorShowing() then
  112.     local mx,my = getCursorPosition()
  113.     local cursorx,cursory = mx*sx,my*sy
  114.         if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
  115.             return true
  116.         else
  117.             return false
  118.         end
  119.     end
  120. end
  121.  
  122. function calculateMeters(vehicle)
  123.     local x, y, z = getElementPosition(vehicle)
  124.     if (math.ceil(getDistanceBetweenPoints2D(oldX, oldY, x, y))-1 >= 1) then
  125.         megtettMeterek = megtettMeterek+math.ceil(getDistanceBetweenPoints2D(oldX, oldY, x, y))-1
  126.         oldX, oldY = x, y
  127.         -- Adatok Beállítása
  128.         triggerServerEvent("setTaxiDataToValue",localPlayer,localPlayer,getPedOccupiedVehicle(localPlayer),megtettMeterek,convertMeterToKm,convertMeterToKm * 10)
  129.     end
  130. end
  131.  
  132. function initializeCounter(s)
  133.     if s then
  134.     local vehicle = getPedOccupiedVehicle(localPlayer)
  135.    
  136.     if (not vehicle) then return end
  137.     local x, y, z = getElementPosition(vehicle)
  138.    
  139.     oldX, oldY, oldZ = x, y, z
  140.     meterCounter = setTimer(calculateMeters, 1000, 0, vehicle)
  141.     else
  142.         if isTimer(meterCounter) then
  143.             killTimer(meterCounter)
  144.         end
  145.         megtettMeterek = getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettmeter")
  146.         convertMeterToKm = getElementData(getPedOccupiedVehicle(localPlayer),"taxi.megtettkm")
  147.     end
  148. end
  149.  
  150.  
  151.  
  152.  
  153. function menuClick(gomb,stat,x,y)
  154.     if gomb == "left" and stat == "down" then
  155.         if showtaximeter then
  156.             if getPedOccupiedVehicleSeat(localPlayer) == 0 then
  157.             if dobozbaVan(posX+13, posY + 90, 274, 45,x,y) then
  158.                 local vehicle = getPedOccupiedVehicle(localPlayer)
  159.                 if started == false then
  160.                     started = true
  161.                     setElementData(vehicle, "started", false)
  162.                     initializeCounter(true)
  163.                     local alap = playSound('taximeter/taxibutton.mp3')
  164.                     setSoundVolume(alap, 0.2)
  165.                 elseif started == true then
  166.                     started = false
  167.                     setElementData(vehicle, "started", true)
  168.                     initializeCounter(false)
  169.                     local alap2 = playSound('taximeter/taxibutton.mp3')
  170.                     setSoundVolume(alap2, 0.2)
  171.                     if getElementData(vehicle,"taxi.megtettmeter") > 0 then
  172.                         local alap3 = playSound('taximeter/taxiprint.mp3')
  173.                         setSoundVolume(alap3, 0.2)
  174.                         local x, y, z = getElementPosition(vehicle)
  175.                         oldX, oldY, oldZ = x, y, z
  176.                         initializeCounter(false)
  177.                     end
  178.                 end
  179.             end
  180.             end
  181.             if x >= posX and x < posX + 300 and y >= posY and y < posY + 35 then
  182.                 windowOffsetX, windowOffsetY = (posX) - x, (posY) - y
  183.                 isDragging = true
  184.             end
  185.         end
  186.        
  187.     end
  188.     if gomb == "left" and stat == "up" and isDragging then
  189.         if showtaximeter then
  190.             isDragging = false
  191.         end
  192.     end
  193. end
  194. addEventHandler("onClientClick", getRootElement(), menuClick)
  195.  
  196. function dobozbaVan(dX, dY, dSZ, dM, eX, eY)
  197.     if(eX >= dX and eX <= dX+dSZ and eY >= dY and eY <= dY+dM) then
  198.         return true
  199.     else
  200.         return false
  201.     end
  202. end
  203.  
  204. function isInSlot(xS,yS,wS,hS)
  205.     if(isCursorShowing()) then
  206.         XY = {guiGetScreenSize()}
  207.         local cursorX, cursorY = getCursorPosition()
  208.         cursorX, cursorY = cursorX*XY[1], cursorY*XY[2]
  209.         if(dobozbaVan(xS,yS,wS,hS, cursorX, cursorY)) then
  210.             return true
  211.         else
  212.             return false
  213.         end
  214.     end
  215. end
  216.  
  217. function EnterVehicle(thePlayer,seat)
  218.     if thePlayer ~= getLocalPlayer() then return end
  219.     if getElementModel(source) == 420 or getElementModel(source) == 438 then
  220.         showtaximeter = true
  221.         outputChatBox("#ffffff[#6cac6fSosa #ffffff- #FFA700Taxi#ffffff] A Taxiórát a '#53bfdc/togtaximeter#ffffff' parancsal tudod eltüntetni.",255,0,0,true)
  222.         outputChatBox("#ffffff[#6cac6fSosa #ffffff- #FFA700Taxi#ffffff] Kifizetni az utat a '#53bfdc/paytaxi#ffffff' parancsal tudod elvégezni.",255,0,0,true)
  223.     end
  224. end
  225. addEventHandler("onClientVehicleEnter",getRootElement(),EnterVehicle)
  226.  
  227. function ExitVehicle(thePlayer,seat)
  228.     if thePlayer ~= getLocalPlayer() then return end
  229.     if getElementModel(source) == 420 or getElementModel(source) == 438 then
  230.         showtaximeter = false
  231.     end
  232. end
  233. addEventHandler("onClientVehicleExit",getRootElement(),ExitVehicle)
  234.  
  235.  
  236. function togtax()
  237.     if not showtaximeter then
  238.         showtaximeter = true
  239.     elseif showtaximeter then
  240.         showtaximeter = false
  241.     end
  242. end
  243. addCommandHandler("togtaximeter",togtax)
Add Comment
Please, Sign In to add comment