Advertisement
Guest User

Untitled

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