local SHOOT_COOLDOWN = 700 local LOCKON_TIME = 2000 local LOCK_RANGE = 530 local LOCK_ANGLE = 1.0472 local VALID_TARGET_FUNCTION = function (vehicle) if not vehicle then return end if vehicle.vehicleType ~= "Plane" and vehicle.vehicleType ~= "Helicopter" then return false end if not isLineOfSightClear(localPlayer.position, vehicle.position, true, false) then return false end return true end local next, pairs, ipairs, localPlayer, addEvent, createProjectile, addEventHandler, triggerEvent, math, table, resourceRoot, isElement, getTickCount, getElementType, getElementsByType, tostring, dxDrawLine, removeEventHandler, bindKey, unbindKey, toggleControl, root, tocolor, getScreenFromWorldPosition, isControlEnabled = next, pairs, ipairs, localPlayer, addEvent, createProjectile, addEventHandler, triggerEvent, math, table, resourceRoot, isElement, getTickCount, getElementType, getElementsByType, tostring, dxDrawLine, removeEventHandler, bindKey, unbindKey, toggleControl, root, tocolor, getScreenFromWorldPosition, isControlEnabled; local validTarget = VALID_TARGET_FUNCTION or function() return true end LOCK_ANGLE = math.cos(LOCK_ANGLE) local inHydra = false local firestate = nil local visibleVehicles = {} local lockedVehicles = {} local nearbyVehicles = {} getNearbyVehicles = function() return nearbyVehicles end local getTarget, stopHydra, currentHydra local function checkForLockout(vehicle) if visibleVehicles[vehicle] then triggerEvent("onClientHydraMissilesSystemLockout", localPlayer, vehicle) visibleVehicles[vehicle] = nil lockedVehicles[vehicle] = nil getTarget() end end local function prev(t, index) local cur, val = next(t, index) while index ~= next(t, cur) do cur, val = next(t, cur) end return cur, val end local target local function switchTarget(key, keystate, dir) if not inHydra then return end local it = next if dir == "back" then it = prev end local prev = target if target and not lockedVehicles[target] then target = nil end target = (it(lockedVehicles, target)) if target == nil then --i.e. was last item target = (it(lockedVehicles, target)) end if target~=prev then triggerEvent("onClientHydraMissilesSystemTargetChange", localPlayer, target) end end getTarget = function() if not inHydra then return end if not target or not lockedVehicles[target] then switchTarget() end return target end local lastShot = SHOOT_COOLDOWN*-2 local function shootMissile() if localPlayer:getData("player:dmprotected") then return end if localPlayer:getData("greenzone") then return end if not inHydra then return end local target = getTarget() if not target or getTickCount() < lastShot + SHOOT_COOLDOWN then return end lastShot = getTickCount() local hydra = localPlayer.vehicle if triggerEvent("onClientHydraMissilesSystemShootHoming", localPlayer, target)==true then createProjectile( hydra, 20, hydra.position, 1, target) end end local function update() local curtime = getTickCount() if not localPlayer.vehicle then stopHydra() return end local target = getTarget() for _, vehicle in ipairs(nearbyVehicles) do local visibleNow = false local locked = lockedVehicles[vehicle] if vehicle and vehicle~=localPlayer.vehicle and not vehicle.blown and validTarget(vehicle) then local targPos = vehicle.position local myPos = localPlayer.position local displacement = targPos-myPos local dist = displacement.length local cosAngle = localPlayer.vehicle.matrix.forward:dot(displacement)/dist if dist < LOCK_RANGE and cosAngle>LOCK_ANGLE then local aX, aY = getScreenFromWorldPosition(targPos) if (aY) then local R = 1000/math.min(math.max(dist, 20), 100) local color visibleNow = true local tween if locked then tween = 0 else tween = 1 - (curtime - (visibleVehicles[vehicle] or curtime))/LOCKON_TIME tween=tween^4 end if vehicle == target then color = tocolor(255, 99, 71, 220) elseif locked then color = tocolor(255,165,0, 160) else color = tocolor(255,215,0, (1-tween)*80) end do dxDrawLine( aX+R+(8+tween*300), aY+R+(8+tween*300), aX+R*0.8, aY+R+(8+tween*300),color, 2 ) dxDrawLine( aX+R+(8+tween*300), aY-R-(8+tween*300), aX+R*0.8, aY-R-(8+tween*300),color, 2 ) dxDrawLine( aX+R+(8+tween*300), aY+R+(8+tween*300), aX+R+(8+tween*300), aY+R*0.8,color, 2 ) dxDrawLine( aX-R-(8+tween*300), aY+R+(8+tween*300), aX-R-(8+tween*300), aY+R*0.8,color, 2 ) dxDrawLine( aX-R-(8+tween*300), aY+R+(8+tween*300), aX-R*0.8, aY+R+(8+tween*300),color, 2 ) dxDrawLine( aX-R-(8+tween*300), aY-R-(8+tween*300), aX-R*0.8, aY-R-(8+tween*300),color, 2 ) dxDrawLine( aX+R+(8+tween*300), aY-R-(8+tween*300), aX+R+(8+tween*300), aY-R*0.8,color, 2 ) dxDrawLine( aX-R-(8+tween*300), aY-R-(8+tween*300), aX-R-(8+tween*300), aY-R*0.8,color, 2 ) end end end end if not visibleNow then checkForLockout(vehicle) elseif visibleVehicles[vehicle] then if not locked and curtime - visibleVehicles[vehicle] > LOCKON_TIME then lockedVehicles[vehicle] = true triggerEvent("onClientHydraMissilesSystemLockonEnd", localPlayer, vehicle) end else triggerEvent("onClientHydraMissilesSystemLockonStart", localPlayer, vehicle) visibleVehicles[vehicle] = curtime end end end local function homingState(key,state) if not inHydra then return end if state == "down" then firestate = isControlEnabled("vehicle_secondary_fire") toggleControl("vehicle_secondary_fire",false) bindKey("vehicle_secondary_fire","down",shootMissile) triggerEvent("onClientHydraMissilesSystemHomingStateOn", localPlayer, currentHydra) else toggleControl("vehicle_secondary_fire",firestate) firestate = nil unbindKey("vehicle_secondary_fire","down",shootMissile) triggerEvent("onClientHydraMissilesSystemHomingStateOff", localPlayer, currentHydra) end end local function vehicleGoneHandler() removeEventHandler("onClientElementDestroy", source, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", source, vehicleGoneHandler) if getElementType( source ) == "vehicle" then for i, v in ipairs(nearbyVehicles) do if v == source then checkForLockout(source) table.remove(nearbyVehicles, i) return end end end end local function prepAfterStreamIn(vehicle) addEventHandler("onClientElementStreamOut", vehicle, vehicleGoneHandler) addEventHandler("onClientElementDestroy", vehicle, vehicleGoneHandler) end local function streamInHandler() if getElementType( source ) == "vehicle" then table.insert(nearbyVehicles, source) prepAfterStreamIn(source) end end local function startHydra(vehicle) if not inHydra and vehicle and isElement(vehicle) and vehicle.model == 520 then nearbyVehicles = getElementsByType("vehicle", root, true) for i, v in ipairs(nearbyVehicles) do prepAfterStreamIn(v) end addEventHandler("onClientElementStreamIn", root, streamInHandler) addEventHandler("onClientVehicleExplode", vehicle, stopHydra) addEventHandler("onClientElementDestroy", vehicle, stopHydra) addEventHandler("onClientElementStreamOut", vehicle, stopHydra) inHydra = tostring(isControlEnabled("handbrake")) currentHydra = vehicle toggleControl("handbrake", false) bindKey("handbrake","down",homingState) bindKey("handbrake","up",homingState) bindKey("lshift","down",switchTarget, "back") bindKey("rshift","down",switchTarget) bindKey("horn","down",switchTarget) addEventHandler( "onClientRender", root, update) triggerEvent("onClientHydraMissilesSystemStart", localPlayer, vehicle) end end stopHydra = function() if inHydra then local target = getTarget() for i, v in ipairs(nearbyVehicles) do if v ~= target then removeEventHandler("onClientElementDestroy", v, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", v, vehicleGoneHandler) checkForLockout(v) end end checkForLockout(target) if target then removeEventHandler("onClientElementDestroy", target, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", target, vehicleGoneHandler) end removeEventHandler("onClientRender", root, update) unbindKey("handbrake","down",homingState) unbindKey("handbrake","up",homingState) if firestate ~= nil then homingState("handbrake","up") end local vehicle = currentHydra currentHydra = nil unbindKey("lshift","down",switchTarget) unbindKey("rshift","down",switchTarget) unbindKey("horn","down",switchTarget) toggleControl("handbrake", inHydra=="true") inHydra = false removeEventHandler("onClientElementStreamIn", root, streamInHandler) if isElement(vehicle) then removeEventHandler("onClientVehicleExplode", vehicle, stopHydra) removeEventHandler("onClientElementDestroy", vehicle, stopHydra) removeEventHandler("onClientElementStreamOut", vehicle, stopHydra) else outputDebugString("There was an annoying problem on this line, write a bug report please.") end triggerEvent("onClientHydraMissilesSystemStop", localPlayer, vehicle) end end local function initScript() if localPlayer.vehicle and localPlayer.vehicle.model == 520 then startHydra(localPlayer.vehicle) end addEventHandler("onClientResourceStop", resourceRoot, stopHydra) addEventHandler("onClientPlayerVehicleExit",localPlayer,stopHydra) addEventHandler("onClientPlayerWasted",localPlayer,stopHydra) addEventHandler("onClientPlayerVehicleEnter",localPlayer,startHydra) end addEvent("onClientHydraMissilesSystemStart") addEvent("onClientHydraMissilesSystemStop") addEvent("onClientHydraMissilesSystemLockonStart") addEvent("onClientHydraMissilesSystemLockonEnd") addEvent("onClientHydraMissilesSystemLockout") addEvent("onClientHydraMissilesSystemTargetChange") addEvent("onClientHydraMissilesSystemShootHoming") addEvent("onClientHydraMissilesSystemHomingStateOn") addEvent("onClientHydraMissilesSystemHomingStateOff") addEventHandler("onClientResourceStart",resourceRoot,initScript)
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more