Jump to content

Шкала бензина


Recommended Posts

Ку всем, есть скрипт бензина, с dxdraw полосой уровня бензина).Как мне заменить полосу на шкалу к примеру на эту http://images.yandex.ru/yandsearch?text=%D1%88%D0%BA%D0%B0%D0%BB%D0%B0%20%D0%B1%D0%B5%D0%BD%D0%B7%D0%B8%D0%BD%D0%B0&pos=13&rpt=simage&img_url=http%3A%2F%2Fstorage.pressfoto.ru%2F2012.04%2F12183668186a6b281f9bc4f610196af46185a4e45f8_s.jpg

Вот код: Клиент

local carFuel = {}; 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        local xml = xmlLoadFile("carData.xml"); 
        local xmlNodes = xmlNodeGetChildren(xml); 
        for i,node in ipairs(xmlNodes) do 
           carFuel[tonumber(xmlNodeGetAttribute(node,'id'))] = tonumber(xmlNodeGetAttribute(node,'fuel')); 
        end 
        xmlUnloadFile(xml); 
    end 
) 
  
addEvent("onPedSyphonFuel",true); 
function startSyphon() 
    if not isPedInVehicle(localPlayer) then 
        if isPedOnGround(localPlayer) then 
            local px, py, pz = getElementPosition(localPlayer); 
            local rot = getPedRotation(localPlayer); 
              
            local a = math.rad(90 - rot); 
          
            local dx = math.cos(a) * 1.5; 
            local dy = math.sin(a) * 1.5; 
            local ppx = math.cos(a) * 0.2; 
            local ppy = math.sin(a) * 0.2; 
          
            local ex = px-dx; 
            local ey = py+dy; 
            px = px-ppx; 
            py = py+ppy; 
            hit, x, y, z, elementHit = processLineOfSight(px, py, pz+1, ex, ey, pz); 
            if elementHit then 
                if getElementType(elementHit) == 'vehicle' then 
                    triggerServerEvent('pedSyphonVehicle',localPlayer,elementHit); 
                end 
            end 
        end 
    end 
end 
addEventHandler("onPedSyphonFuel",getRootElement(),startSyphon); 
addCommandHandler('syphon',startSyphon) 
  
addEvent("onPedReFuel",true); 
function fillHerUp() 
    local vehicle = getPedOccupiedVehicle(localPlayer); 
    if not isPedInVehicle(localPlayer) then 
        if isPedOnGround(localPlayer) then 
            local px, py, pz = getElementPosition(localPlayer); 
            local rot = getPedRotation(localPlayer); 
              
            local a = math.rad(90 - rot); 
          
            local dx = math.cos(a) * 1.5; 
            local dy = math.sin(a) * 1.5; 
            local ppx = math.cos(a) * 0.2; 
            local ppy = math.sin(a) * 0.2; 
          
            local ex = px-dx; 
            local ey = py+dy; 
            px = px-ppx; 
            py = py+ppy; 
            hit, x, y, z, elementHit = processLineOfSight(px, py, pz+1, ex, ey, pz); 
            if elementHit then 
                if getElementType(elementHit) == 'vehicle' then 
                    triggerServerEvent('pedRefuelVehicle',localPlayer,elementHit); 
                end 
            end 
        end 
    end 
end 
addEventHandler("onPedReFuel",getRootElement(),fillHerUp); 
addCommandHandler('refuel',fillHerUp) 
  
function drawGUI() 
    local vehicle = getPedOccupiedVehicle(localPlayer); 
    if vehicle then 
        local x,y = guiGetScreenSize(); 
        if getVehicleType(vehicle) ~= 'Automobile' and getVehicleType(vehicle) ~= 'Bike' and getVehicleType(vehicle) ~= 'Monster Truck' and getVehicleType(vehicle) ~= 'Quad' then return end 
        local driver = getVehicleController(vehicle); 
        if driver ~= localPlayer then return end --### 
        if getVehicleEngineState(vehicle) == false then return end --### 
        dxDrawRectangle(x-30,(y/2)-75,20,142,0x66224466); 
        local maxFuel = carFuel[0]; 
        local curFuel = getElementData(vehicle,'fuel'); 
        if curFuel == false then return end 
        if carFuel[getElementModel(vehicle)] then maxFuel = carFuel[getElementModel(vehicle)]; end 
        local fuel = (curFuel/maxFuel)*100; 
        local colour = nil; 
        if fuel > 90 then 
            colour = 0x9922CC33; 
            dxDrawRectangle(x-28,(y/2)-71,16,21,colour); 
        end 
        if fuel > 75 then 
            if colour == nil then 
                colour = 0x99009900; 
            end 
            dxDrawRectangle(x-28,(y/2)-48,16,21,colour); 
        end 
        if fuel > 60 then 
            if colour == nil then 
                colour = 0x99339900; 
            end 
            dxDrawRectangle(x-28,(y/2)-25,16,21,colour); 
        end 
        if fuel > 45 then 
            if colour == nil then 
                colour = 0x99999900; 
            end 
            dxDrawRectangle(x-28,(y/2)-2,16,21,colour); 
        end 
        if fuel > 30 then 
            if colour == nil then 
                colour = 0x99996600; 
            end 
            dxDrawRectangle(x-28,(y/2)+21,16,21,colour); 
        end 
        if colour == nil then 
            if fuel > 15 then 
                colour = 0x99993300; 
            else 
                colour = 0x99990000; 
            end 
        end 
            dxDrawRectangle(x-28,(y/2)+44,16,21,colour); 
         
        --dxDrawText(tostring(fuel)..'%',x-105,y-50); 
    end 
end 
addEventHandler("onClientRender",getRootElement(),drawGUI); 
  
  
addEventHandler("onClientElementStreamIn",getRootElement(),function () 
    if getElementType(source) ~= 'vehicle' then return end 
    if getVehicleType(source) ~= 'Automobile' and getVehicleType(source) ~= 'Bike' and getVehicleType(source) ~= 'Monster Truck' and getVehicleType(source) ~= 'Quad' then return end 
    triggerServerEvent('giveVehicleFuelOnSpawn',source); 
end); 

Сервер

local carFuel = {}; 
local gasStations = {}; 
local gasStationsBlip = {}; 
local gasStationsMarkers = {}; 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        local xml = xmlLoadFile("carData.xml"); 
        local xmlNodes = xmlNodeGetChildren(xml); 
        for i,node in ipairs(xmlNodes) do 
           carFuel[tonumber(xmlNodeGetAttribute(node,'id'))] = tonumber(xmlNodeGetAttribute(node,'fuel')); 
        end 
        xmlUnloadFile(xml); 
        local xml = xmlLoadFile("garageData.xml"); 
        local xmlNodes = xmlNodeGetChildren(xml); 
        for i,node in ipairs(xmlNodes) do 
            local name = xmlNodeGetAttribute(node,'name'); 
            local x = tonumber(xmlNodeGetAttribute(node,'x')); 
            local y = tonumber(xmlNodeGetAttribute(node,'y')); 
            local z = tonumber(xmlNodeGetAttribute(node,'z')); 
            gasStationsBlip[name] = createBlip(x,y,z,51,0,0,0,0,0,0,0); 
            local moreKids = xmlNodeGetChildren(node); 
            gasStationsMarkers[name] = {}; 
            for i,v in ipairs(moreKids) do 
                local mx = tonumber(xmlNodeGetAttribute(v,'x')); 
                local my = tonumber(xmlNodeGetAttribute(v,'y')); 
                local mz = tonumber(xmlNodeGetAttribute(v,'z')); 
                gasStationsMarkers[name][i] = createMarker(mx,my,mz,'corona',3,128,128,0,64); 
                setElementData(gasStationsMarkers[name][i],'gasStation',true); 
            end 
        end 
        xmlUnloadFile(xml); 
    end 
) 
  
function fuelUse(p) 
    local vehicle = getPedOccupiedVehicle(p); 
    if vehicle then 
        setTimer(fuelUse,1000,1,p); 
        if getVehicleType(vehicle) ~= 'Automobile' and getVehicleType(vehicle) ~= 'Bike' and getVehicleType(vehicle) ~= 'Monster Truck' and getVehicleType(vehicle) ~= 'Quad' then return end 
        if getVehicleController(vehicle) ~= p then return end --### 
        if getVehicleEngineState(vehicle) == false then return end --### 
         
        local fuel = getCarFuel(vehicle) 
        if fuel == 0 then setVehicleEngineState(vehicle,false); return end --### 
         
        --[[local speedX, speedY, speedZ = getElementVelocity(vehicle); 
        vel = (speedX^2 + speedY^2 + speedZ^2)^(0.5)+(math.random(100,1000)/25000);]] 
        local newX,newY,newZ = getElementPosition(vehicle); 
        local oldX = getElementData(vehicle,'oldX') or newX; 
        local oldY = getElementData(vehicle,'oldY') or newY; 
        local oldZ = getElementData(vehicle,'oldZ') or newZ; 
        local vel = (getDistanceBetweenPoints2D(oldX,oldY,newX,newY)/70)+(math.random(100,1000)/50000); 
         
        local oldX = setElementData(vehicle,'oldX',newX); 
        local oldY = setElementData(vehicle,'oldY',newY); 
        local oldZ = setElementData(vehicle,'oldZ',newZ) 
         
        --if vel < 0.01 then return end --### 
         
        local remainingFuel = takeCarFuel(vehicle,vel); 
        if remainingFuel < 0.001 then 
            remainingFuel = 0; 
            outputChatBox('Your car has ran out of fuel.',v); 
            setVehicleEngineState(vehicle,false); 
        end 
    end 
end 
  
function startFuelUse(p,seat,jacked) 
    if getVehicleType(source) ~= 'Automobile' and getVehicleType(source) ~= 'Bike' and getVehicleType(source) ~= 'Monster Truck' and getVehicleType(source) ~= 'Quad' then return end 
    if seat ~= 0 then return end 
    if getCarFuel(source) <= 0 then setVehicleEngineState(source,false); end 
    setTimer(fuelUse,1000,1,p); 
end 
addEventHandler("onVehicleEnter",getRootElement(),startFuelUse) 
  
function switchEngine(playerSource) 
    local theVehicle = getPedOccupiedVehicle(playerSource); 
    if theVehicle and getVehicleController(theVehicle) == playerSource then 
        local state = getVehicleEngineState(theVehicle) 
        if state then 
            setVehicleEngineState(theVehicle, false); 
            outputChatBox('Car engine turned off.',playerSource); 
        else 
            if getCarFuel(theVehicle) <= 0 then return end 
            setVehicleEngineState(theVehicle, true); 
            outputChatBox('Car engine turned on.',playerSource); 
        end 
    end 
end 
addCommandHandler("engine",switchEngine); 
  
addEvent('pedSyphonVehicle',true); 
function pedSyphon(v) 
    if getCarFuel(source) >= carFuel[-1] then outputChatBox("You are holding as much fuel as you can carry.",source); return end 
    local n = math.random(100,200)/1000; 
    local left = takeCarFuel(v,n); 
    local total = addCarFuel(source,n); 
    if left <= 0 then outputChatBox("That car has no more fuel left.",source); return end 
    triggerClientEvent("onPedSyphonFuel",source); 
end 
addEventHandler('pedSyphonVehicle',getRootElement(),pedSyphon); 
  
addEvent('pedRefuelVehicle',true); 
function pedSyphon(v) 
    if getCarFuel(source) <= 0 then outputChatBox("You have no more fuel left.",source); return end 
    local maxFuel = carFuel[0]; 
    if carFuel[getElementModel(v)] then 
        maxFuel = getFuel[getElementModel(v)]; 
    end 
    if getCarFuel(v) >= maxFuel then 
        outputChatBox("That car is fully refueled.",source); return 
    end 
    local n = math.random(100,200)/1000; 
    local left = takeCarFuel(source,n); 
    local total = addCarFuel(v,n); 
    triggerClientEvent("onPedReFuel",source); 
end 
addEventHandler('pedRefuelVehicle',getRootElement(),pedSyphon); 
  
addEvent('onVehicleRefuel',true); 
function vehicleRefuel(v,m) 
    if not getElementData(m,'gasStation') then return end 
    if getElementType(v) ~= 'vehicle' then return end 
    if getVehicleType(v) ~= 'Automobile' and getVehicleType(v) ~= 'Bike' and getVehicleType(v) ~= 'Monster Truck' and getVehicleType(v) ~= 'Quad' then return end 
    local driver = getVehicleOccupants(v); 
    if not driver[0] then return end 
    if not isElementWithinMarker(v,m) then return end --### 
    local maxFuel = carFuel[0]; 
    if getPlayerMoney(driver[0]) < 25 then outputChatBox("You can't afford any more fuel.",p); return end 
    if carFuel[getElementModel(v)] then 
        maxFuel = carFuel[getElementModel(v)]; 
    end 
    if getCarFuel(v) >= maxFuel then return end 
    addCarFuel(v,15); 
    takePlayerMoney(driver[0],25); 
    if getCarFuel(v) >= maxFuel then outputChatBox("Your car has been fully refueled.",p); takeCarFuel(v,getCarFuel(v)-maxFuel); return end 
    setTimer(vehicleRefuel,500,1,v,m); 
end 
addEventHandler('onVehicleRefuel',getRootElement(),vehicleRefuel); 
function hitTheMarker(e) 
    setTimer(vehicleRefuel,1500,1,e,source); 
end 
addEventHandler('onMarkerHit',getRootElement(),hitTheMarker); 
  
function getCarFuel(v) 
    if getElementType(v) == 'vehicle' then 
        if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then 
            local fuel = getElementData(v,'fuel'); 
            local model = getElementModel(v); 
            if not carFuel[model] then model = 0; end 
            if not fuel then 
                if carFuel[model] then 
                    fuel = carFuel[model]; 
                    setElementData(v,'fuel',carFuel[model]); 
                else 
                    fuel = carFuel[0]; 
                    setElementData(v,'fuel',carFuel[0]); 
                end 
            end 
            return fuel; 
        end 
    elseif getElementType(v) == 'player' then 
        local fuel = getElementData(v,'fuel'); 
        if not fuel then 
            setElementData(v,'fuel',0); 
            return 0; 
        end 
        return fuel; 
    end 
end 
  
function addCarFuel(v,a) 
    if getElementType(v) == 'vehicle' then 
        if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then 
            local fuel = getElementData(v,'fuel'); 
            local model = getElementModel(v); 
            if not carFuel[model] then model = 0; end 
            if not fuel then 
                if carFuel[model] then 
                    fuel = carFuel[model]; 
                    setElementData(v,'fuel',carFuel[model]); 
                else 
                    fuel = carFuel[0]; 
                    setElementData(v,'fuel',carFuel[0]); 
                end 
            end 
            fuel = fuel + a; 
            if fuel > carFuel[model] then fuel = carFuel[model]; end 
            setElementData(v,'fuel',fuel); 
            return fuel; 
        end 
    elseif getElementType(v) == 'player' then 
        local fuel = getElementData(v,'fuel'); 
        if not fuel then 
            fuel = 0; 
        end 
        fuel = fuel + a; 
        if fuel > carFuel[-1] then fuel = carFuel[-1]; end 
        setElementData(v,'fuel',fuel); 
        return fuel; 
    end 
end 
  
function takeCarFuel(v,a) 
    if getElementType(v) == 'vehicle' then 
        if getVehicleType(v) == 'Automobile' or getVehicleType(v) == 'Bike' or getVehicleType(v) == 'Monster Truck' or getVehicleType(v) == 'Quad' then 
            local fuel = getElementData(v,'fuel'); 
            local model = getElementModel(v); 
            if not carFuel[model] then model = 0; end 
                if not fuel then 
                if carFuel[model] then 
                    fuel = carFuel[model]; 
                    setElementData(v,'fuel',carFuel[model]); 
                else 
                    fuel = carFuel[0]; 
                    setElementData(v,'fuel',carFuel[0]); 
                end 
            end 
            fuel = fuel - a; 
            if fuel < 0 then fuel = 0; end 
            setElementData(v,'fuel',fuel); 
            return fuel; 
        end 
    elseif getElementType(v) == 'player' then 
        local fuel = getElementData(v,'fuel'); 
        if not fuel then 
            fuel = 0; 
        end 
        fuel = fuel - a; 
        if fuel < 0 then fuel = 0; end 
        setElementData(v,'fuel',fuel); 
        return fuel; 
    end 
end 
  
addEvent('giveVehicleFuelOnSpawn',true); 
addEventHandler('giveVehicleFuelOnSpawn',getRootElement(),function() 
    getCarFuel(source); 
end); 

Link to comment

Заменять очень просто...

Короче не мучайся: https://community.multitheftauto.com/index.php?p= ... ils&id=119

З.Ы.-если это всё написано тобой,то создай изображение в таблице(ты поймёшь)-на таблицу ставь таймер,и там уже свой скрипт

Примерно так:

function ImageCreate() 
guiSetVisible ( picture50, false) 
local picture100 = -------(-------------------------)- \\\\\\\\-------картинки 
picture50 = ---------------(--------------------------) 
end 
addEventHandler ("onClientVehicleEnter",getResourceRootElement(),ImageCreate) 
  
function TableWithFuel() 
iconFirst = guiSetVisible ( picture100, true) 
end 
addEventHandler ("onClientVehicleEnter",getResourceRootElement(),TableWithFuel) 
  
function ChangeThisStatus () 
ChangeStatusFIle = guiSetVisible ( picture100, false) 
if iconFirst then 
guiSetVisible ( picture100, false) 
end 
if ChangeStatusFIle then 
guiSetVisible ( picture50, true) 
end 
end 
setTimer (TableWithFuel,600000,1) 
  
function DeleteAllObj () 
guiSetVisible ( picture100, false) 
guiSetVisible ( picture50, false) 
end 
addEventHandler ("onClientVehicleExit",getResourceRootElement(),DeleteAllObj ) 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...