Advertisement
Surgetin

image on vehicle's top

Mar 17th, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. local image
  2. local timer
  3. local duration = 5000
  4. local activeImage = false
  5. local imagesEnabled = true
  6.  
  7. local images = {
  8.     angry =     "images/angry.png",
  9.     bored =     "images/bored.png",
  10.     ...
  11. }
  12.  
  13. function drawImageOnVehicleTop(imageFile)
  14.     if activeImage then
  15.         return
  16.     end
  17.    
  18.     local vehicle = getPedOccupiedVehicle(localPlayer)
  19.     if vehicle then
  20.         image = dxCreateTexture(imageFile)
  21.         if image then
  22.             activeImage = true
  23.             addEventHandler("onClientRender", root, renderImageOnVehicleTop)
  24.             timer = setTimer(destroyImageAndHandlers, duration, 1)
  25.         end
  26.     end
  27. end
  28.  
  29. function renderImageOnVehicleTop()
  30.     local vehicle = getPedOccupiedVehicle(localPlayer)
  31.     if not isElement(vehicle) or isPedDead(localPlayer) then
  32.         destroyImageAndHandlers()
  33.         return
  34.     end
  35.     local x, y, z = getElementPosition(vehicle)
  36.     dxDrawMaterialLine3D(x, y, z + 2, x, y, z + 1, image, 1)
  37. end
  38.  
  39. function destroyImageAndHandlers()
  40.     if image then
  41.         destroyElement(image)
  42.         image = nil
  43.         activeImage = false
  44.     end
  45.     if isTimer(timer) then
  46.         killTimer(timer)
  47.     end
  48.     removeEventHandler("onClientRender", root, renderImageOnVehicleTop)
  49. end
  50.  
  51. local buttons = {
  52.     {key = "1", image = images.angry},
  53.     {key = "2", image = images.bored},
  54.     ...
  55. }
  56.  
  57. function toggleImages()
  58.     imagesEnabled = not imagesEnabled
  59.     outputChatBox(imagesEnabled and "*" ..greycolor.. " Emoji images has been" ..col_g.. " enabled" or "*" ..greycolor.. " Emoji images has been" ..col_r.. " disabled", 255, 255, 255, true)
  60. end
  61. bindKey( "F6", "down", toggleImages )
  62.  
  63. function handleKey(button, press)
  64.     if imagesEnabled and press and getKeyState("mouse2") then
  65.         local image = nil
  66.        
  67.         for i, btn in ipairs(buttons) do
  68.             if button == btn.key then
  69.                 image = btn.image
  70.                 break
  71.             end
  72.         end
  73.        
  74.         if image then
  75.             drawImageOnVehicleTop(image)
  76.         end    
  77.     end    
  78. end
  79. addEventHandler("onClientKey", root, handleKey)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement