Guest User

Untitled

a guest
May 10th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.37 KB | None | 0 0
  1. ---------------------------
  2. --(c) by MazzMan/Maxim
  3. ---------------------------
  4. canDriverUseGun = true
  5.  
  6. ammo = {}
  7. ammo.small = false
  8. ammo.middle = false
  9. ammo.big = true
  10.  
  11. ammo.smallShots = 50
  12. ammo.middleShots = 6
  13.  
  14. ammo.smallCanShoot = true
  15. ammo.middleCanShoot = true
  16.  
  17. ammo.smallReloading = false
  18. ammo.middleReloading = false
  19. ammo.bigReloading = false
  20.  
  21. setElementData(getLocalPlayer(), "ac130KeysBound", false)
  22.  
  23. function onClientEnter(thePlayer, seat)
  24.     if(getLocalPlayer() == thePlayer and getElementModel(source) == 592 and getElementData(source, "ac130"))then
  25.         if(canDriverUseGun)then
  26.             bindKey("space", "down", setBinds)
  27.         elseif(seat == 1)then
  28.             bindKey("space", "down", setBinds)
  29.         end
  30.     end
  31. end
  32. addEventHandler("onClientVehicleEnter", getRootElement(), onClientEnter)
  33. addEvent ( "fromserver:enter", true )
  34. addEventHandler ( "fromserver:enter", root, onClientEnter )
  35.  
  36. function removeAllGunControls()
  37.     unbindKey("space", "down", setBinds)
  38.     setCameraGoggleEffect("normal")
  39.    
  40.     setElementData(getLocalPlayer(), "ac130KeysBound", false)
  41.     removeEventHandler("onClientRender", getRootElement(), keepCamAtAc130)
  42.     removeEventHandler("onClientCursorMove", getRootElement(), cammera)
  43.     unbindKey("mouse1", "down", shoot)
  44.     setCameraTarget(getLocalPlayer())
  45.     unbindKey("mouse_wheel_up", "down", changeAmmo)
  46.     unbindKey("mouse_wheel_down", "down", changeAmmo)
  47.     unbindKey("v", "down", setVisionMode)
  48. end
  49. addEventHandler("onClientVehicleExit", getRootElement(), removeAllGunControls)
  50. addEventHandler("onClientResourceStop", getRootElement(), removeAllGunControls)
  51.  
  52. addEventHandler("onClientPlayerWasted", getRootElement(), function()
  53.     if(source == getLocalPlayer())then
  54.         removeAllGunControls()
  55.     end
  56. end)
  57.  
  58. local windowX, windowY = guiGetScreenSize()
  59.  
  60.  
  61. local vvx, vvy, vvz = 0, 0, 0
  62. function keepCamAtAc130(screenX, screenY, absoluteX, absoluteY, vx,vy,vz)  
  63.     local x,y,z = getElementPosition(getPedOccupiedVehicle(getLocalPlayer()))
  64.        
  65.     local rx, ry, rz = getElementRotation(getPedOccupiedVehicle(getLocalPlayer()))
  66.    
  67.     rz = rz +180
  68.    
  69.     local cx = x + math.cos(math.rad(rz)) * 3
  70.     local cy = y + math.sin(math.rad(rz)) * 3
  71.    
  72.     if ( vx and vy and vz ) then
  73.         vvx, vvy, vvz = vx, vy, vz
  74.     end
  75.    
  76.     setCameraMatrix ( cx, cy, z, vvx, vvy, vvz );
  77.     drawHud ( )
  78. end
  79.  
  80. function setBinds()
  81.     if(getElementData(getLocalPlayer(), "ac130KeysBound") == false)then
  82.         setElementData(getLocalPlayer(), "ac130KeysBound", true)
  83.         addEventHandler ( "onClientRender", root, keepCamAtAc130 )
  84.         addEventHandler("onClientCursorMove", getRootElement(), keepCamAtAc130)
  85.         bindKey("mouse1", "down", shoot)
  86.         bindKey("mouse_wheel_up", "down", changeAmmo)
  87.         bindKey("mouse_wheel_down", "down", changeAmmo)
  88.         bindKey("v", "down", setVisionMode)
  89.     else
  90.         setElementData(getLocalPlayer(), "ac130KeysBound", false)
  91.         removeEventHandler("onClientCursorMove", getRootElement(), cammera)
  92.         removeEventHandler ( "onClientRender", root, keepCamAtAc130 )
  93.         unbindKey("mouse1", "down", shoot)
  94.         setCameraTarget(getLocalPlayer())
  95.         unbindKey("mouse_wheel_up", "down", changeAmmo)
  96.         unbindKey("mouse_wheel_down", "down", changeAmmo)
  97.         unbindKey("v", "down", setVisionMode)
  98.         setCameraGoggleEffect("normal")
  99.     end
  100. end
  101.  
  102. function shoot()
  103.     local cx, cy, cz = getCameraMatrix()
  104.     local wX,wY,wZ = getWorldFromScreenPosition(windowX/2, windowY/2, 2000)
  105.     local hit, x, y, z = processLineOfSight(cx, cy, cz, wX,wY,wZ)
  106.    
  107.     if(hit)then
  108.         local distance = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz)
  109.         local time = distance/0.5
  110.        
  111.         local ammoType
  112.         if(ammo.small)then
  113.             if(time >= 50)then
  114.                 if(ammo.smallCanShoot and ammo.smallReloading == false)then
  115.                     --im using a timer, becaus a while loop will cause to crash the game
  116.                     shootTimer = setTimer(function()
  117.                         if(getKeyState("mouse1"))then
  118.                             cx, cy, cz = getCameraMatrix()
  119.                             wX,wY,wZ = getWorldFromScreenPosition(windowX/2, windowY/2, 2000)  
  120.                             hit, x, y, z = processLineOfSight(cx, cy, cz, wX,wY,wZ)
  121.                             if(hit)then
  122.                                 playSound("sounds/shot_small.wav")
  123.                                 ammoType = "small"
  124.                                            
  125.                                 ammo.smallShots = ammo.smallShots - 1
  126.                                 if(ammo.smallShots == 0)then
  127.                                     setReloading("small")
  128.                                     killTimer(shootTimer)
  129.                                 end
  130.                                 ammo.smallCanShoot = false
  131.                                 setTimer(function()
  132.                                     ammo.smallCanShoot = true
  133.                                 end, 200, 1)
  134.                                 triggerServerEvent("onAc130Shoot", getRootElement(),cx, cy, cz, x, y, z, time, ammoType)
  135.                             end
  136.                         else
  137.                             killTimer(shootTimer)
  138.                         end
  139.                     end, 50, 0)
  140.                 else
  141.                     return false
  142.                 end
  143.             else
  144.                 return false
  145.             end
  146.         elseif(ammo.middle)then
  147.             if(time >= 50)then
  148.                 if(ammo.middleCanShoot and ammo.middleReloading == false)then
  149.                     ammoType = "middle"
  150.                     ammo.middleShots = ammo.middleShots - 1
  151.                     if(ammo.middleShots == 0)then
  152.                         setReloading("middle")
  153.                     end            
  154.                     ammo.middleCanShoot = false
  155.                     playSound("sounds/shot_middle.wav")
  156.                     setTimer(function()
  157.                         ammo.middleCanShoot = true
  158.                     end, 500, 1)
  159.                 else
  160.                     return false
  161.                 end
  162.             else
  163.                 return false
  164.             end
  165.         elseif(ammo.big)then
  166.             if(ammo.bigReloading == false)then
  167.                 if(time >= 50)then
  168.                     ammoType = "big"
  169.                     playSound("sounds/shot_middle.wav")
  170.                
  171.                     setReloading("big")
  172.                 else
  173.                     return false
  174.                 end
  175.             else
  176.                 return false
  177.             end
  178.         end
  179.         triggerServerEvent("onAc130Shoot", getRootElement(),cx, cy, cz, x, y, z, time, ammoType)
  180.     end
  181. end
  182.  
  183. function changeAmmo(key)
  184.     if(key == "mouse_wheel_up")then
  185.         if(ammo.small)then
  186.             ammo.small = false
  187.             ammo.big = true
  188.         elseif(ammo.middle)then
  189.             ammo.middle = false
  190.             ammo.small = true
  191.         elseif(ammo.big)then
  192.             ammo.big = false
  193.             ammo.middle = true
  194.         end
  195.     else
  196.         if(ammo.small)then
  197.             ammo.small = false
  198.             ammo.middle = true
  199.         elseif(ammo.middle)then
  200.             ammo.middle = false
  201.             ammo.big = true
  202.         elseif(ammo.big)then
  203.             ammo.big = false
  204.             ammo.small = true
  205.         end
  206.     end
  207. end
  208.  
  209. function setReloading(ammoType)
  210.     if(ammoType == "small")then
  211.         ammo.smallReloading = true
  212.         setTimer(function()
  213.             ammo.smallReloading = false    
  214.             ammo.smallShots = 50
  215.         end, 3000, 1)
  216.     elseif(ammoType == "middle")then
  217.         ammo.middleReloading = true
  218.         setTimer(function()
  219.             ammo.middleReloading = false       
  220.             ammo.middleShots = 6
  221.         end, 3000, 1)
  222.     elseif(ammoType == "big")then
  223.         ammo.bigReloading = true
  224.         setTimer(function()
  225.             ammo.bigReloading = false      
  226.         end, 3000, 1)
  227.     end
  228. end
  229.  
  230. function setVisionMode()
  231.     if(getCameraGoggleEffect() == "normal")then
  232.         setCameraGoggleEffect("nightvision")
  233.     elseif(getCameraGoggleEffect() == "nightvision")then
  234.         setCameraGoggleEffect("thermalvision")
  235.     elseif(getCameraGoggleEffect() == "thermalvision")then
  236.         setCameraGoggleEffect("normal")
  237.     end
  238. end
  239.  
  240. addEvent("onClientCreateEffect", true)
  241. addEventHandler("onClientCreateEffect", getRootElement(), function(x,y,z, lx, ly, lz, type, time)
  242.     if(type ~= "small")then
  243.         --playSound3D("sounds/shot_middle.wav", x,y,z)
  244.         --local num = math.random(1, 3)
  245.         --local projectileSound = playSound3D("sounds/projectile_"..num..".wav", lx, ly, lz)
  246.         --setSoundMaxDistance(projectileSound, 300)
  247.         setTimer(function()
  248.             local num = math.random(1, 6)
  249.             local explSound = playSound3D("sounds/explosion_"..num..".wav", lx, ly, lz)
  250.             if(type == "middle")then
  251.                 setSoundMaxDistance(explSound, 250)
  252.             else
  253.                 setSoundMaxDistance(explSound, 500)
  254.             end
  255.         end, time, 1)
  256.     end
  257.     fxAddTankFire(x,y,z, lx, ly, lz)
  258. end)
  259.  
  260. function drawHud()
  261.     if(ammo.small)then
  262.         if(ammo.smallReloading)then
  263.             color = tocolor(150, 150, 150, 255)
  264.         else
  265.             color = tocolor(255, 255, 255, 255)
  266.         end
  267.    
  268.         dxDrawLine(windowX/2-40, windowY/2, windowX/2+40, windowY/2,color, 2)
  269.         dxDrawLine(windowX/2, windowY/2-40, windowX/2, windowY/2+40,color, 2)
  270.     elseif(ammo.middle)then
  271.         if(ammo.middleReloading)then
  272.             color = tocolor(150, 150, 150, 255)
  273.         else
  274.             color = tocolor(255, 255, 255, 255)
  275.         end
  276.    
  277.         dxDrawLine(windowX/2-200, windowY/2, windowX/2-10, windowY/2,color, 2)
  278.         dxDrawLine(windowX/2+10, windowY/2, windowX/2+200, windowY/2,color, 2)
  279.        
  280.         dxDrawLine(windowX/2, windowY/2-200, windowX/2, windowY/2-10,color, 2)
  281.         dxDrawLine(windowX/2, windowY/2+10, windowX/2, windowY/2+200,color, 2)
  282.        
  283.         dxDrawLine(windowX/2-200, windowY/2-10, windowX/2-200, windowY/2+10,color, 2)
  284.         dxDrawLine(windowX/2-160, windowY/2-10, windowX/2-160, windowY/2+10,color, 2)
  285.         dxDrawLine(windowX/2-120, windowY/2-10, windowX/2-120, windowY/2+10,color, 2)
  286.         dxDrawLine(windowX/2-80, windowY/2-10, windowX/2-80, windowY/2+10,color, 2)
  287.         dxDrawLine(windowX/2-40, windowY/2-10, windowX/2-40, windowY/2+10,color, 2)
  288.         dxDrawLine(windowX/2+40, windowY/2-10, windowX/2+40, windowY/2+10,color, 2)
  289.         dxDrawLine(windowX/2+80, windowY/2-10, windowX/2+80, windowY/2+10,color, 2)
  290.         dxDrawLine(windowX/2+120, windowY/2-10, windowX/2+120, windowY/2+10,color, 2)
  291.         dxDrawLine(windowX/2+160, windowY/2-10, windowX/2+160, windowY/2+10,color, 2)      
  292.         dxDrawLine(windowX/2+200, windowY/2-10, windowX/2+200, windowY/2+10,color, 2)
  293.        
  294.         dxDrawLine(windowX/2-10, windowY/2-200, windowX/2+10, windowY/2-200,color, 2)
  295.         dxDrawLine(windowX/2-10, windowY/2-160, windowX/2+10, windowY/2-160,color, 2)
  296.         dxDrawLine(windowX/2-10, windowY/2-120, windowX/2+10, windowY/2-120,color, 2)
  297.         dxDrawLine(windowX/2-10, windowY/2-80, windowX/2+10, windowY/2-80,color, 2)
  298.         dxDrawLine(windowX/2-10, windowY/2-40, windowX/2+10, windowY/2-40,color, 2)
  299.         dxDrawLine(windowX/2-10, windowY/2+40, windowX/2+10, windowY/2+40,color, 2)
  300.         dxDrawLine(windowX/2-10, windowY/2+80, windowX/2+10, windowY/2+80,color, 2)
  301.         dxDrawLine(windowX/2-10, windowY/2+120, windowX/2+10, windowY/2+120,color, 2)
  302.         dxDrawLine(windowX/2-10, windowY/2+160, windowX/2+10, windowY/2+160,color, 2)      
  303.         dxDrawLine(windowX/2-10, windowY/2+200, windowX/2+10, windowY/2+200,color, 2)
  304.     else
  305.         if(ammo.bigReloading)then
  306.             color = tocolor(150, 150, 150, 255)
  307.         else
  308.             color = tocolor(255, 255, 255, 255)
  309.         end
  310.        
  311.         dxDrawLine(windowX/2-300, windowY/2, windowX/2-60, windowY/2,color, 2)
  312.         dxDrawLine(windowX/2+60, windowY/2, windowX/2+300, windowY/2,color, 2)
  313.        
  314.         dxDrawLine(windowX/2, windowY/2-200, windowX/2, windowY/2-40,color, 2)
  315.         dxDrawLine(windowX/2, windowY/2+40, windowX/2, windowY/2+200,color, 2)
  316.        
  317.         dxDrawLine(windowX/2-60, windowY/2-40, windowX/2+60, windowY/2-40,color, 2)
  318.         dxDrawLine(windowX/2-60, windowY/2+40, windowX/2+60, windowY/2+40,color, 2)
  319.        
  320.         dxDrawLine(windowX/2-60, windowY/2-40, windowX/2-60, windowY/2+40,color, 2)
  321.         dxDrawLine(windowX/2+60, windowY/2-40, windowX/2+60, windowY/2+40,color, 2)
  322.        
  323.     end
  324.    
  325.     if(ammo.small)then
  326.         colorSmall = tocolor(255, 255, 255, 255)
  327.     else
  328.         colorSmall = tocolor(150, 150, 150, 255)
  329.     end
  330.     if(ammo.middle)then
  331.         colorMiddle = tocolor(255, 255, 255, 255)
  332.     else
  333.         colorMiddle = tocolor(150, 150, 150, 255)
  334.     end
  335.     if(ammo.big)then
  336.         colorBig = tocolor(255, 255, 255, 255)
  337.     else
  338.         colorBig = tocolor(150, 150, 150, 255)
  339.     end
  340.     if(ammo.bigReloading)then
  341.         ammoBig = 0
  342.     else
  343.         ammoBig = 1
  344.     end
  345.    
  346.     dxDrawText("25mm: "..ammo.smallShots, 30, windowY/2+30, 100, 20, colorSmall, 2, "default")
  347.     dxDrawText("40mm: "..ammo.middleShots, 30, windowY/2+55, 100, 20, colorMiddle, 2, "default")
  348.     dxDrawText("105mm: "..ammoBig, 30, windowY/2+80, 100, 20, colorBig, 2, "default")
  349.    
  350.     players = getElementsByType("player")
  351.     peds = getElementsByType("ped")
  352.    
  353.     for k,v in ipairs(peds) do table.insert(players, v) end
  354.    
  355.     for _, thePlayer in ipairs(players)do
  356.         local x,y,z = getElementPosition(thePlayer)
  357.         local cx,cy,cz = getCameraMatrix()
  358.         if(getDistanceBetweenPoints3D(x,y,z, cx,cy,cz) <= 1000)then
  359.             sX, sY, sZ = getScreenFromWorldPosition(x,y,z)
  360.             if(sX and sY and sZ)then
  361.                 if(getElementType(thePlayer) == "ped")then
  362.                     color = tocolor(255, 217, 0, 255)
  363.                 else
  364.                     if(getPlayerTeam(thePlayer) == getPlayerTeam(getLocalPlayer()) and getPlayerTeam(getLocalPlayer()))then
  365.                         color = tocolor(0, 255, 0, 255)
  366.                     else
  367.                         color = tocolor(255, 0, 0, 255)
  368.                     end
  369.                 end
  370.                
  371.                 dxDrawLine(sX+20, sY+20, sX-20, sY+20,color, 2)
  372.                 dxDrawLine(sX+20, sY-20, sX-20, sY-20,color, 2)
  373.                 dxDrawLine(sX+20, sY-20, sX+20, sY+20,color, 2)
  374.                 dxDrawLine(sX-20, sY-20, sX-20, sY+20,color, 2)
  375.                
  376.                 if(getElementType(thePlayer) ~= "ped")then
  377.                     dxDrawText(getPlayerName(thePlayer), sX-20, sY+25, 25, 20, color, 0.9)
  378.                 end
  379.                
  380.                 if(getCameraGoggleEffect()=="thermalvision")then
  381.                     color = tocolor(255, 255, 255)
  382.                
  383.                     x,y,z = getPedBonePosition ( thePlayer, 8)
  384.                     x,y = getScreenFromWorldPosition( x, y, z)
  385.                    
  386.                     x2,y2,z2 = getPedBonePosition ( thePlayer, 2)
  387.                     x2,y2 = getScreenFromWorldPosition(x2, y2, z2)
  388.                    
  389.                     dxDrawLine(x,y,x2,y2, color, 1.5)
  390.                    
  391.                 -----------------SHOULDERS-----------------
  392.                     Hx,Hy,Hz = getPedBonePosition ( thePlayer, 4)
  393.                     Hx,Hy = getScreenFromWorldPosition( Hx, Hy, Hz)
  394.                    
  395.                     Sx2,Sy2,Sz2 = getPedBonePosition ( thePlayer, 22)
  396.                     Sx2,Sy2 = getScreenFromWorldPosition(Sx2, Sy2, Sz2)
  397.                    
  398.                     Sx3,Sy3,Sz3 = getPedBonePosition ( thePlayer, 32)
  399.                     Sx3,Sy3 = getScreenFromWorldPosition(Sx3, Sy3, Sz3)
  400.                    
  401.                     dxDrawLine(Hx,Hy,Sx2,Sy2, color, 1.5)
  402.                     dxDrawLine(Hx,Hy,Sx3,Sy3, color, 1.5)
  403.                    
  404.                 -----------------UPPER ARMS-----------------
  405.                     ERx,ERy,ERz = getPedBonePosition ( thePlayer, 23)
  406.                     ERx,ERy = getScreenFromWorldPosition( ERx,ERy,ERz)
  407.                    
  408.                     ELx,ELy,ELz = getPedBonePosition ( thePlayer, 33)
  409.                     ELx,ELy = getScreenFromWorldPosition(ELx,ELy,ELz)
  410.                    
  411.                     dxDrawLine(ERx,ERy,Sx2,Sy2, color, 1.5)
  412.                     dxDrawLine(ELx,ELy,Sx3,Sy3, color, 1.5)
  413.                    
  414.                 -----------------LOWER ARMS-----------------
  415.                     HRx,HRy,HRz = getPedBonePosition ( thePlayer, 24)
  416.                     HRx,HRy = getScreenFromWorldPosition( HRx,HRy,HRz)
  417.                    
  418.                     HLx,HLy,HLz = getPedBonePosition ( thePlayer, 34)
  419.                     HLx,HLy = getScreenFromWorldPosition(HLx,HLy,HLz)
  420.                    
  421.                     dxDrawLine(ERx,ERy,HRx,HRy, color, 1.5)
  422.                     dxDrawLine(ELx,ELy,HLx,HLy, color, 1.5)
  423.                    
  424.                 -----------------UPPER LEGS-----------------
  425.                     KRx,KRy,KRz = getPedBonePosition ( thePlayer, 52)
  426.                     KRx,KRy = getScreenFromWorldPosition( KRx,KRy,KRz)
  427.                    
  428.                     KLx,KLy,KLz = getPedBonePosition ( thePlayer, 42)
  429.                     KLx,KLy = getScreenFromWorldPosition(KLx,KLy,KLz)
  430.                    
  431.                     dxDrawLine(x2,y2,KRx,KRy, color, 1.5)
  432.                     dxDrawLine(x2,y2,KLx,KLy, color, 1.5)
  433.                    
  434.                 -----------------LOWER LEGS-----------------
  435.                     LRx,LRy,LRz = getPedBonePosition ( thePlayer, 53)
  436.                     LRx,LRy = getScreenFromWorldPosition( LRx,LRy,LRz )
  437.                    
  438.                     LLx,LLy,LLz = getPedBonePosition ( thePlayer, 43)
  439.                     LLx,LLy = getScreenFromWorldPosition(LLx,LLy,LLz)
  440.                    
  441.                     dxDrawLine(LRx,LRy,KRx,KRy, color, 1.5)
  442.                     dxDrawLine(LLx,LLy,KLx,KLy, color, 1.5)
  443.                 end
  444.             end
  445.         end
  446.     end
  447. end
  448. --addEventHandler("onClientRender", getRootElement(), drawHud)
  449.  
  450. function getPlayerSeat(player)
  451.     triggerServerEvent("getPlayerSeat", getRootElement(), player)
  452. end
  453.  
  454.  
  455. --to fix bugs
  456. addCommandHandler("fixAc130", function()
  457.     local veh = getPedOccupiedVehicle(getLocalPlayer())
  458.     if(veh and getElementModel(veh) == 592 and getElementData(veh, "ac130"))then       
  459.         if(canDriverUseGun)then
  460.             removeAllGunControls()
  461.             bindKey("space", "down", setBinds)
  462.         else
  463.             getPlayerSeat(getLocalPlayer())
  464.             setTimer(function()
  465.                 if(getElementData(getLocalPlayer(), "seat") ~= 0)then
  466.                     removeAllGunControls()
  467.                     bindKey("space", "down", setBinds)
  468.                 else
  469.                     removeAllGunControls()
  470.                 end
  471.             end, 100, 1)   
  472.         end
  473.     else
  474.         removeAllGunControls()
  475.     end
  476. end)
Advertisement
Add Comment
Please, Sign In to add comment