Advertisement
Guest User

Untitled

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