Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2025-12-30, 23:31


noose

JESTĘ SKRYPTERĘ






Wiek: 35
Na forum: 3897 dni
Posty: 219

Piwa: 2295

Respekt: 155,8
Respekt: 155,8Respekt: 155,8

Kod:

armedVehicles = {[425]=true, [520]=true, [476]=true, [447]=true, [430]=true, [432]=true, [464]=true, [407]=true, [601]=true}
function vehicleWeaponFire(key, keyState, vehicleFireType)
local vehModel = getElementModel(getPedOccupiedVehicle(localPlayer))
if (armedVehicles[vehModel]) then
triggerEvent("onClientVehicleWeaponFire", localPlayer, vehicleFireType, vehModel)
end
end
bindKey("vehicle_fire", "down", vehicleWeaponFire, "primary")
bindKey("vehicle_secondary_fire", "down", vehicleWeaponFire, "secondary")

local tim = nil

function armatka(ftype, veh)
if not veh or veh ~=407 and veh ~=601 then return end
if ftype == "primary" or ftype == "secondary" then
if getElementData(getPedOccupiedVehicle(localPlayer), "NAPEŁNIENIE") <= 0 then
setControlState("vehicle_fire", false)
setTimer(toggleControl, 10, 1, "vehicle_fire", false)
setTimer(toggleControl, 10, 1, "vehicle_secondary_fire", false)
setElementData(getPedOccupiedVehicle(localPlayer), "NAPEŁNIENIE", 0)
else
toggleControl("vehicle_fire", true)
toggleControl("vehicle_secondary_fire", true)
end
if not isTimer(tim) then
tim = setTimer(function()
setElementData(getPedOccupiedVehicle(localPlayer),"NAPEŁNIENIE", (getElementData(getPedOccupiedVehicle(localPlayer), "NAPEŁNIENIE"))- 1)
end, 3000, 0)
end
end
end
addEvent("onClientVehicleWeaponFire", false)
addEventHandler("onClientVehicleWeaponFire", getLocalPlayer(), armatka)


armatka działą, ale nie da sie zatrzymać odejmowania napełnienia.
próbowałem pożyczyć keyState z kody na samej górze, ale nie działa

Postaw piwo autorowi tego posta
 

 
Wysłany: 2026-04-28, 20:25


Axmell

E-Commerce






Wiek: 24
Na forum: 3951 dni
Posty: 279
Nick w MP: %Axmell

Piwa: 224

Respekt: 50

local armedVehicles = { [425] = true, [520] = true, [476] = true, [447] = true, [430] = true, [432] = true, [464] = true, [407] = true, [601] = true }

local drainTimer = nil
local drainVehicle = nil
local firing = { primary = false, secondary = false }

local function getFill(veh)
    if not isElement(veh) then
        return 0
    end
    local v = getElementData(veh, "NAPEŁNIENIE")
    v = tonumber(v) or 0
    if v < 0 then
        v = 0
    end
    return v
end

local function setFill(veh, v)
    if not isElement(veh) then
        return
    end
    v = tonumber(v) or 0
    if v < 0 then
        v = 0
    end
    setElementData(veh, "NAPEŁNIENIE", v)
end

local function stopDrain()
    if drainTimer and isTimer(drainTimer) then
        killTimer(drainTimer)
    end
    drainTimer = nil
    drainVehicle = nil
    firing.primary = false
    firing.secondary = false
end

local function startDrain(veh)
    if not isElement(veh) then
        return
    end

    drainVehicle = veh

    if drainTimer and isTimer(drainTimer) then
        return
    end

    drainTimer = setTimer(function()
        local v = drainVehicle
        if not isElement(v) then
            stopDrain()
            return
        end

        local current = getPedOccupiedVehicle(localPlayer)
        if current ~= v then
            stopDrain()
            return
        end

        local fill = getFill(v)
        if fill <= 0 then
            setFill(v, 0)
            toggleControl("vehicle_fire", false)
            toggleControl("vehicle_secondary_fire", false)
            stopDrain()
            return
        end

        setFill(v, fill - 1)
    end, 3000, 0)
end

function vehicleWeaponFire(key, keyState, vehicleFireType)
    local veh = getPedOccupiedVehicle(localPlayer)
    if not veh then
        return
    end

    local vehModel = getElementModel(veh)
    if armedVehicles[vehModel] then
        triggerEvent("onClientVehicleWeaponFire", localPlayer, vehicleFireType, vehModel)
    end
end

local function vehicleWeaponStop(key, keyState, vehicleFireType)
    if vehicleFireType == "primary" then
        firing.primary = false
    elseif vehicleFireType == "secondary" then
        firing.secondary = false
    end

    if not firing.primary and not firing.secondary then
        stopDrain()
    end
end

bindKey("vehicle_fire", "down", vehicleWeaponFire, "primary")
bindKey("vehicle_secondary_fire", "down", vehicleWeaponFire, "secondary")
bindKey("vehicle_fire", "up", vehicleWeaponStop, "primary")
bindKey("vehicle_secondary_fire", "up", vehicleWeaponStop, "secondary")

function armatka(ftype, vehModel)
    if not vehModel or (vehModel ~= 407 and vehModel ~= 601) then
        return
    end
    if ftype ~= "primary" and ftype ~= "secondary" then
        return
    end

    local veh = getPedOccupiedVehicle(localPlayer)
    if not veh then
        stopDrain()
        return
    end

    if getElementModel(veh) ~= vehModel then
        return
    end

    if ftype == "primary" then
        firing.primary = true
    else
        firing.secondary = true
    end

    local fill = getFill(veh)
    if fill <= 0 then
        setControlState("vehicle_fire", false)
        toggleControl("vehicle_fire", false)
        toggleControl("vehicle_secondary_fire", false)
        setFill(veh, 0)
        stopDrain()
        return
    end

    toggleControl("vehicle_fire", true)
    toggleControl("vehicle_secondary_fire", true)
    startDrain(veh)
end

addEvent("onClientVehicleWeaponFire", false)
addEventHandler("onClientVehicleWeaponFire", localPlayer, armatka)

addEventHandler("onClientPlayerVehicleExit", localPlayer, function()
    stopDrain()
end)

addEventHandler("onClientPlayerWasted", localPlayer, function()
    stopDrain()
end)

addEventHandler("onClientResourceStop", resourceRoot, function()
    stopDrain()
end)

addEventHandler("onClientRender", root, function()
    local veh = getPedOccupiedVehicle(localPlayer)
    if not veh then
        return
    end

    local model = getElementModel(veh)
    if model ~= 407 and model ~= 601 then
        return
    end

    local fill = getFill(veh)
    local sx, sy = guiGetScreenSize()

    local text = "NAPEŁNIENIE: " .. tostring(fill)
    local x = sx - 20
    local y = sy - 140

    dxDrawText(text, x + 1, y + 1, x + 1, y + 1, tocolor(0, 0, 0, 220), 1.0, "default-bold", "right", "top", false, false, false)
    dxDrawText(text, x, y, x, y, tocolor(255, 255, 255, 240), 1.0, "default-bold", "right", "top", false, false, false)
end)


Postaw piwo autorowi tego posta
 

 
Tagi: armatka :: wodna
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » armatka wodna v2 Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku