Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------
- --(c) by MazzMan/Maxim
- ---------------------------
- canDriverUseGun = true
- ammo = {}
- ammo.small = false
- ammo.middle = false
- ammo.big = true
- ammo.smallShots = 50
- ammo.middleShots = 6
- ammo.smallCanShoot = true
- ammo.middleCanShoot = true
- ammo.smallReloading = false
- ammo.middleReloading = false
- ammo.bigReloading = false
- setElementData(getLocalPlayer(), "ac130KeysBound", false)
- addEventHandler("onClientVehicleEnter", getRootElement(), function(thePlayer, seat)
- if(getLocalPlayer() == thePlayer and getElementModel(source) == 592 and getElementData(source, "ac130"))then
- if(canDriverUseGun)then
- bindKey("space", "down", setBinds)
- elseif(seat == 1)then
- bindKey("space", "down", setBinds)
- end
- end
- end)
- function removeAllGunControls()
- unbindKey("space", "down", setBinds)
- setCameraGoggleEffect("normal")
- setElementData(getLocalPlayer(), "ac130KeysBound", false)
- removeEventHandler("onClientRender", getRootElement(), keepCamAtAc130)
- removeEventHandler("onClientCursorMove", getRootElement(), cammera)
- unbindKey("mouse1", "down", shoot)
- setCameraTarget(getLocalPlayer())
- unbindKey("mouse_wheel_up", "down", changeAmmo)
- unbindKey("mouse_wheel_down", "down", changeAmmo)
- unbindKey("v", "down", setVisionMode)
- end
- addEventHandler("onClientVehicleExit", getRootElement(), removeAllGunControls)
- addEventHandler("onClientResourceStop", getRootElement(), removeAllGunControls)
- addEventHandler("onClientPlayerWasted", getRootElement(), function()
- if(source == getLocalPlayer())then
- removeAllGunControls()
- end
- end)
- local windowX, windowY = guiGetScreenSize()
- local vtable = { }
- function cammera(screenX, screenY, absoluteX, absoluteY, vx,vy,vz)
- vtable = { vx, vy, vz }
- end
- function keepCamAtAc130()
- local x,y,z = getElementPosition(getPedOccupiedVehicle(getLocalPlayer()))
- local rx, ry, rz = getElementRotation(getPedOccupiedVehicle(getLocalPlayer()))
- rz = rz +180
- local cx = x + math.cos(math.rad(rz)) * 3
- local cy = y + math.sin(math.rad(rz)) * 3
- setCameraMatrix ( cx, cy, z, vtable[1], vtable[2], vtable[3] )
- drawHud ( )
- end
- function setBinds()
- if(getElementData(getLocalPlayer(), "ac130KeysBound") == false)then
- setElementData(getLocalPlayer(), "ac130KeysBound", true)
- addEventHandler("onClientCursorMove", getRootElement(), cammera)
- addEventHandler ( "onClientRender", root, keepCamAtAc130 )
- bindKey("mouse1", "down", shoot)
- bindKey("mouse_wheel_up", "down", changeAmmo)
- bindKey("mouse_wheel_down", "down", changeAmmo)
- bindKey("v", "down", setVisionMode)
- else
- setElementData(getLocalPlayer(), "ac130KeysBound", false)
- removeEventHandler("onClientCursorMove", getRootElement(), cammera)
- removeEventHandler ( "onClientRender", root, keepCamAtAc130 )
- unbindKey("mouse1", "down", shoot)
- setCameraTarget(getLocalPlayer())
- unbindKey("mouse_wheel_up", "down", changeAmmo)
- unbindKey("mouse_wheel_down", "down", changeAmmo)
- unbindKey("v", "down", setVisionMode)
- setCameraGoggleEffect("normal")
- end
- end
- function shoot()
- local cx, cy, cz = getCameraMatrix()
- local wX,wY,wZ = getWorldFromScreenPosition(windowX/2, windowY/2, 2000)
- local hit, x, y, z = processLineOfSight(cx, cy, cz, wX,wY,wZ)
- if(hit)then
- local distance = getDistanceBetweenPoints3D(x, y, z, cx, cy, cz)
- local time = distance/0.5
- local ammoType
- if(ammo.small)then
- if(time >= 50)then
- if(ammo.smallCanShoot and ammo.smallReloading == false)then
- --im using a timer, becaus a while loop will cause to crash the game
- shootTimer = setTimer(function()
- if(getKeyState("mouse1"))then
- cx, cy, cz = getCameraMatrix()
- wX,wY,wZ = getWorldFromScreenPosition(windowX/2, windowY/2, 2000)
- hit, x, y, z = processLineOfSight(cx, cy, cz, wX,wY,wZ)
- if(hit)then
- playSound("sounds/shot_small.wav")
- ammoType = "small"
- ammo.smallShots = ammo.smallShots - 1
- if(ammo.smallShots == 0)then
- setReloading("small")
- killTimer(shootTimer)
- end
- ammo.smallCanShoot = false
- setTimer(function()
- ammo.smallCanShoot = true
- end, 200, 1)
- triggerServerEvent("onAc130Shoot", getRootElement(),cx, cy, cz, x, y, z, time, ammoType)
- end
- else
- killTimer(shootTimer)
- end
- end, 50, 0)
- else
- return false
- end
- else
- return false
- end
- elseif(ammo.middle)then
- if(time >= 50)then
- if(ammo.middleCanShoot and ammo.middleReloading == false)then
- ammoType = "middle"
- ammo.middleShots = ammo.middleShots - 1
- if(ammo.middleShots == 0)then
- setReloading("middle")
- end
- ammo.middleCanShoot = false
- playSound("sounds/shot_middle.wav")
- setTimer(function()
- ammo.middleCanShoot = true
- end, 500, 1)
- else
- return false
- end
- else
- return false
- end
- elseif(ammo.big)then
- if(ammo.bigReloading == false)then
- if(time >= 50)then
- ammoType = "big"
- playSound("sounds/shot_middle.wav")
- setReloading("big")
- else
- return false
- end
- else
- return false
- end
- end
- triggerServerEvent("onAc130Shoot", getRootElement(),cx, cy, cz, x, y, z, time, ammoType)
- end
- end
- function changeAmmo(key)
- if(key == "mouse_wheel_up")then
- if(ammo.small)then
- ammo.small = false
- ammo.big = true
- elseif(ammo.middle)then
- ammo.middle = false
- ammo.small = true
- elseif(ammo.big)then
- ammo.big = false
- ammo.middle = true
- end
- else
- if(ammo.small)then
- ammo.small = false
- ammo.middle = true
- elseif(ammo.middle)then
- ammo.middle = false
- ammo.big = true
- elseif(ammo.big)then
- ammo.big = false
- ammo.small = true
- end
- end
- end
- function setReloading(ammoType)
- if(ammoType == "small")then
- ammo.smallReloading = true
- setTimer(function()
- ammo.smallReloading = false
- ammo.smallShots = 50
- end, 3000, 1)
- elseif(ammoType == "middle")then
- ammo.middleReloading = true
- setTimer(function()
- ammo.middleReloading = false
- ammo.middleShots = 6
- end, 3000, 1)
- elseif(ammoType == "big")then
- ammo.bigReloading = true
- setTimer(function()
- ammo.bigReloading = false
- end, 3000, 1)
- end
- end
- function setVisionMode()
- if(getCameraGoggleEffect() == "normal")then
- setCameraGoggleEffect("nightvision")
- elseif(getCameraGoggleEffect() == "nightvision")then
- setCameraGoggleEffect("thermalvision")
- elseif(getCameraGoggleEffect() == "thermalvision")then
- setCameraGoggleEffect("normal")
- end
- end
- addEvent("onClientCreateEffect", true)
- addEventHandler("onClientCreateEffect", getRootElement(), function(x,y,z, lx, ly, lz, type, time)
- if(type ~= "small")then
- --playSound3D("sounds/shot_middle.wav", x,y,z)
- --local num = math.random(1, 3)
- --local projectileSound = playSound3D("sounds/projectile_"..num..".wav", lx, ly, lz)
- --setSoundMaxDistance(projectileSound, 300)
- setTimer(function()
- local num = math.random(1, 6)
- local explSound = playSound3D("sounds/explosion_"..num..".wav", lx, ly, lz)
- if(type == "middle")then
- setSoundMaxDistance(explSound, 250)
- else
- setSoundMaxDistance(explSound, 500)
- end
- end, time, 1)
- end
- fxAddTankFire(x,y,z, lx, ly, lz)
- end)
- function drawHud()
- if(ammo.small)then
- if(ammo.smallReloading)then
- color = tocolor(150, 150, 150, 255)
- else
- color = tocolor(255, 255, 255, 255)
- end
- dxDrawLine(windowX/2-40, windowY/2, windowX/2+40, windowY/2,color, 2)
- dxDrawLine(windowX/2, windowY/2-40, windowX/2, windowY/2+40,color, 2)
- elseif(ammo.middle)then
- if(ammo.middleReloading)then
- color = tocolor(150, 150, 150, 255)
- else
- color = tocolor(255, 255, 255, 255)
- end
- dxDrawLine(windowX/2-200, windowY/2, windowX/2-10, windowY/2,color, 2)
- dxDrawLine(windowX/2+10, windowY/2, windowX/2+200, windowY/2,color, 2)
- dxDrawLine(windowX/2, windowY/2-200, windowX/2, windowY/2-10,color, 2)
- dxDrawLine(windowX/2, windowY/2+10, windowX/2, windowY/2+200,color, 2)
- dxDrawLine(windowX/2-200, windowY/2-10, windowX/2-200, windowY/2+10,color, 2)
- dxDrawLine(windowX/2-160, windowY/2-10, windowX/2-160, windowY/2+10,color, 2)
- dxDrawLine(windowX/2-120, windowY/2-10, windowX/2-120, windowY/2+10,color, 2)
- dxDrawLine(windowX/2-80, windowY/2-10, windowX/2-80, windowY/2+10,color, 2)
- dxDrawLine(windowX/2-40, windowY/2-10, windowX/2-40, windowY/2+10,color, 2)
- dxDrawLine(windowX/2+40, windowY/2-10, windowX/2+40, windowY/2+10,color, 2)
- dxDrawLine(windowX/2+80, windowY/2-10, windowX/2+80, windowY/2+10,color, 2)
- dxDrawLine(windowX/2+120, windowY/2-10, windowX/2+120, windowY/2+10,color, 2)
- dxDrawLine(windowX/2+160, windowY/2-10, windowX/2+160, windowY/2+10,color, 2)
- dxDrawLine(windowX/2+200, windowY/2-10, windowX/2+200, windowY/2+10,color, 2)
- dxDrawLine(windowX/2-10, windowY/2-200, windowX/2+10, windowY/2-200,color, 2)
- dxDrawLine(windowX/2-10, windowY/2-160, windowX/2+10, windowY/2-160,color, 2)
- dxDrawLine(windowX/2-10, windowY/2-120, windowX/2+10, windowY/2-120,color, 2)
- dxDrawLine(windowX/2-10, windowY/2-80, windowX/2+10, windowY/2-80,color, 2)
- dxDrawLine(windowX/2-10, windowY/2-40, windowX/2+10, windowY/2-40,color, 2)
- dxDrawLine(windowX/2-10, windowY/2+40, windowX/2+10, windowY/2+40,color, 2)
- dxDrawLine(windowX/2-10, windowY/2+80, windowX/2+10, windowY/2+80,color, 2)
- dxDrawLine(windowX/2-10, windowY/2+120, windowX/2+10, windowY/2+120,color, 2)
- dxDrawLine(windowX/2-10, windowY/2+160, windowX/2+10, windowY/2+160,color, 2)
- dxDrawLine(windowX/2-10, windowY/2+200, windowX/2+10, windowY/2+200,color, 2)
- else
- if(ammo.bigReloading)then
- color = tocolor(150, 150, 150, 255)
- else
- color = tocolor(255, 255, 255, 255)
- end
- dxDrawLine(windowX/2-300, windowY/2, windowX/2-60, windowY/2,color, 2)
- dxDrawLine(windowX/2+60, windowY/2, windowX/2+300, windowY/2,color, 2)
- dxDrawLine(windowX/2, windowY/2-200, windowX/2, windowY/2-40,color, 2)
- dxDrawLine(windowX/2, windowY/2+40, windowX/2, windowY/2+200,color, 2)
- dxDrawLine(windowX/2-60, windowY/2-40, windowX/2+60, windowY/2-40,color, 2)
- dxDrawLine(windowX/2-60, windowY/2+40, windowX/2+60, windowY/2+40,color, 2)
- dxDrawLine(windowX/2-60, windowY/2-40, windowX/2-60, windowY/2+40,color, 2)
- dxDrawLine(windowX/2+60, windowY/2-40, windowX/2+60, windowY/2+40,color, 2)
- end
- if(ammo.small)then
- colorSmall = tocolor(255, 255, 255, 255)
- else
- colorSmall = tocolor(150, 150, 150, 255)
- end
- if(ammo.middle)then
- colorMiddle = tocolor(255, 255, 255, 255)
- else
- colorMiddle = tocolor(150, 150, 150, 255)
- end
- if(ammo.big)then
- colorBig = tocolor(255, 255, 255, 255)
- else
- colorBig = tocolor(150, 150, 150, 255)
- end
- if(ammo.bigReloading)then
- ammoBig = 0
- else
- ammoBig = 1
- end
- dxDrawText("25mm: "..ammo.smallShots, 30, windowY/2+30, 100, 20, colorSmall, 2, "default")
- dxDrawText("40mm: "..ammo.middleShots, 30, windowY/2+55, 100, 20, colorMiddle, 2, "default")
- dxDrawText("105mm: "..ammoBig, 30, windowY/2+80, 100, 20, colorBig, 2, "default")
- players = getElementsByType("player")
- peds = getElementsByType("ped")
- for k,v in ipairs(peds) do table.insert(players, v) end
- for _, thePlayer in ipairs(players)do
- local x,y,z = getElementPosition(thePlayer)
- local cx,cy,cz = getCameraMatrix()
- if(getDistanceBetweenPoints3D(x,y,z, cx,cy,cz) <= 1000)then
- sX, sY, sZ = getScreenFromWorldPosition(x,y,z)
- if(sX and sY and sZ)then
- if(getElementType(thePlayer) == "ped")then
- color = tocolor(255, 217, 0, 255)
- else
- if(getPlayerTeam(thePlayer) == getPlayerTeam(getLocalPlayer()) and getPlayerTeam(getLocalPlayer()))then
- color = tocolor(0, 255, 0, 255)
- else
- color = tocolor(255, 0, 0, 255)
- end
- end
- dxDrawLine(sX+20, sY+20, sX-20, sY+20,color, 2)
- dxDrawLine(sX+20, sY-20, sX-20, sY-20,color, 2)
- dxDrawLine(sX+20, sY-20, sX+20, sY+20,color, 2)
- dxDrawLine(sX-20, sY-20, sX-20, sY+20,color, 2)
- if(getElementType(thePlayer) ~= "ped")then
- dxDrawText(getPlayerName(thePlayer), sX-20, sY+25, 25, 20, color, 0.9)
- end
- if(getCameraGoggleEffect()=="thermalvision")then
- color = tocolor(255, 255, 255)
- x,y,z = getPedBonePosition ( thePlayer, 8)
- x,y = getScreenFromWorldPosition( x, y, z)
- x2,y2,z2 = getPedBonePosition ( thePlayer, 2)
- x2,y2 = getScreenFromWorldPosition(x2, y2, z2)
- dxDrawLine(x,y,x2,y2, color, 1.5)
- -----------------SHOULDERS-----------------
- Hx,Hy,Hz = getPedBonePosition ( thePlayer, 4)
- Hx,Hy = getScreenFromWorldPosition( Hx, Hy, Hz)
- Sx2,Sy2,Sz2 = getPedBonePosition ( thePlayer, 22)
- Sx2,Sy2 = getScreenFromWorldPosition(Sx2, Sy2, Sz2)
- Sx3,Sy3,Sz3 = getPedBonePosition ( thePlayer, 32)
- Sx3,Sy3 = getScreenFromWorldPosition(Sx3, Sy3, Sz3)
- dxDrawLine(Hx,Hy,Sx2,Sy2, color, 1.5)
- dxDrawLine(Hx,Hy,Sx3,Sy3, color, 1.5)
- -----------------UPPER ARMS-----------------
- ERx,ERy,ERz = getPedBonePosition ( thePlayer, 23)
- ERx,ERy = getScreenFromWorldPosition( ERx,ERy,ERz)
- ELx,ELy,ELz = getPedBonePosition ( thePlayer, 33)
- ELx,ELy = getScreenFromWorldPosition(ELx,ELy,ELz)
- dxDrawLine(ERx,ERy,Sx2,Sy2, color, 1.5)
- dxDrawLine(ELx,ELy,Sx3,Sy3, color, 1.5)
- -----------------LOWER ARMS-----------------
- HRx,HRy,HRz = getPedBonePosition ( thePlayer, 24)
- HRx,HRy = getScreenFromWorldPosition( HRx,HRy,HRz)
- HLx,HLy,HLz = getPedBonePosition ( thePlayer, 34)
- HLx,HLy = getScreenFromWorldPosition(HLx,HLy,HLz)
- dxDrawLine(ERx,ERy,HRx,HRy, color, 1.5)
- dxDrawLine(ELx,ELy,HLx,HLy, color, 1.5)
- -----------------UPPER LEGS-----------------
- KRx,KRy,KRz = getPedBonePosition ( thePlayer, 52)
- KRx,KRy = getScreenFromWorldPosition( KRx,KRy,KRz)
- KLx,KLy,KLz = getPedBonePosition ( thePlayer, 42)
- KLx,KLy = getScreenFromWorldPosition(KLx,KLy,KLz)
- dxDrawLine(x2,y2,KRx,KRy, color, 1.5)
- dxDrawLine(x2,y2,KLx,KLy, color, 1.5)
- -----------------LOWER LEGS-----------------
- LRx,LRy,LRz = getPedBonePosition ( thePlayer, 53)
- LRx,LRy = getScreenFromWorldPosition( LRx,LRy,LRz )
- LLx,LLy,LLz = getPedBonePosition ( thePlayer, 43)
- LLx,LLy = getScreenFromWorldPosition(LLx,LLy,LLz)
- dxDrawLine(LRx,LRy,KRx,KRy, color, 1.5)
- dxDrawLine(LLx,LLy,KLx,KLy, color, 1.5)
- end
- end
- end
- end
- end
- --addEventHandler("onClientRender", getRootElement(), drawHud)
- function getPlayerSeat(player)
- triggerServerEvent("getPlayerSeat", getRootElement(), player)
- end
- --to fix bugs
- addCommandHandler("fixAc130", function()
- local veh = getPedOccupiedVehicle(getLocalPlayer())
- if(veh and getElementModel(veh) == 592 and getElementData(veh, "ac130"))then
- if(canDriverUseGun)then
- removeAllGunControls()
- bindKey("space", "down", setBinds)
- else
- getPlayerSeat(getLocalPlayer())
- setTimer(function()
- if(getElementData(getLocalPlayer(), "seat") ~= 0)then
- removeAllGunControls()
- bindKey("space", "down", setBinds)
- else
- removeAllGunControls()
- end
- end, 100, 1)
- end
- else
- removeAllGunControls()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement