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

Wysłany: 2020-03-15, 19:26


Mazeusz







Wiek: 30
Na forum: 2673 dni
Posty: 52
Nick w MP: Mazeusz*



Respekt: 50

Ostrzeżeń: 80%
Witam chcia?bym zrobi? tak interakcje ?e gdy pojazd przekroczy dany przebieg silnik nie odpali zrobi?em tak ale nadal odpala

c

local font dxCreateFont("font.ttf"14) or default-bold
local font2 dxCreateFont("font.ttf"16) or default-bold

local sw,sh guiGetScreenSize();
local baseX 1920;
local zoom 1;
local minzoom 2;
if sw baseX then
    zoom math.min(minzoombaseX/sw);
end;

local selected 1;
local tick getTickCount();
local interaction = {};
local type_i "join"

local tick_int getTickCount();
local int false;
local type "join";

local a1,a2,a3 0,0,0;

local img = {
  ["car"] = dxCreateTexture("img/settings/car.png""argb"false"clamp"),
  ["click_off"] = dxCreateTexture("img/settings/click_on.png""argb"false"clamp"),
  ["click_on"] = dxCreateTexture("img/settings/click_off.png""argb"false"clamp"),

  ["engine"] = dxCreateTexture("img/engine.png""argb"false"clamp"),
  ["handbrake"] = dxCreateTexture("img/handbrake.png""argb"false"clamp"),
  ["leave"] = dxCreateTexture("img/leave.png""argb"false"clamp"),
  ["light"] = dxCreateTexture("img/light.png""argb"false"clamp"),
  ["lock"] = dxCreateTexture("img/lock.png""argb"false"clamp"),
  ["settings"] = dxCreateTexture("img/settings.png""argb"false"clamp"),
  ["reload"] = dxCreateTexture("img/reload.png""argb"false"clamp"),
};

function isMouseIn(xywh)
    if not isCursorShowing() then return end

    local pos = {getCursorPosition()}
    pos[1],pos[2] = (pos[1]*sw),(pos[2]*sh)

    if pos[1] >= and pos[1] <= (x+w) and pos[2] >= and pos[2] <= (y+hthen
        return true
    end
    return false
end

function isEventHandlerAddedsEventNamepElementAttachedTofunc )
        local aAttachedFunctions getEventHandlerssEventNamepElementAttachedTo )
        if #aAttachedFunctions > 0 then
            for iv in ipairsaAttachedFunctions ) do
                if == func then
                    return true
                end
            end
        end

    return false
end

local selected_option = {
  function(vehoptiontrigger)
    if trigger then
      if option == 1 then
        return "switchLIGHT"
      elseif option == 2 then
        return "switchENGINE"
      elseif option == 3 then
        return "switchHANDBRAKE"
      elseif option == 4 then
        return "kickOCCUPANTS"
      elseif option == 5 then
        return "changeLOCKED"
      elseif option == 7 then
        return "changeTYPE"
      end
    else
      if option == 1 then
        return getVehicleOverrideLights(veh) == and "Odpal lampy" or "Zga? lampy"
      elseif option == 2 then
        return getVehicleEngineState(veh) == true and "Zga? silnik" or "Odpal silnik"
      elseif option == 3 then
        return getElementData(veh"vehicle:handbrake") and "Spu?? r?czny" or "Zaci?gnij r?czny"
      elseif option == 4 then
        return "Wysad? pasa?er?w"
      elseif option == 5 then
        return isVehicleLocked(veh) == true and "Otw?rz zamek" or "Zamknij zamek"
      elseif option == 6 then
        return "Wi?cej opcji"
      elseif option == 7 then
        return getElementData(veh"vehicle:actualType") == "LPG" and "Prze??cz na benzyne" or "Prze??cz na gaz"
      end
    end
  end
}

bindKey("lshift""both", function(_state)
    local veh getPedOccupiedVehicle(localPlayer)
  if not veh then return end
  if getElementData(veh"vehicle.selling"then return end

    if getVehicleController(veh) ~= localPlayer then return end
  if getVehicleName(veh) == "Bike" or getVehicleName(veh) == "BMX" or getVehicleName(veh) == "Mountain Bike" then return end

  if state == "up" then
    if selected == 6 then
      if not int then
        addEventHandler("onClientRender"rootgui)
        addEventHandler("onClientClick"rootclicked)
        addEventHandler("onClientKey"rootkey)

        showCursor(truefalse)

        tick_int getTickCount()
        type "join"
      end
    else
      triggerServerEvent(selected_option[1](vehselectedtrue), resourceRootveh)
    end

    type_i "quit";
    tick getTickCount();

    unbindKey("arrow_r""down"down)
    unbindKey("mouse_wheel_down""down"down)
    unbindKey("arrow_l""down"up)
    unbindKey("mouse_wheel_up""down"up)
  elseif(state == "down" and not isCursorShowing())then
    if(not isEventHandlerAdded("onClientRender"rootguiInter))then
      addEventHandler("onClientRender"rootguiInter)
    end;
    
    selected 1;
    tick getTickCount();
    type_i "join";
    a1,a2,a3 0,0,0;

    bindKey("arrow_r""down"down)
    bindKey("mouse_wheel_down""down"down)
    bindKey("arrow_l""down"up)
    bindKey("mouse_wheel_up""down"up)
    end
end)

local tbl = {
  [1] = "light",
  [2] = "engine",
  [3] = "handbrake",
  [4] = "leave",
  [5] = "lock",
  [6] = "settings",
  [7] = "reload",
};

function guiInter()
    local v getPedOccupiedVehicle(localPlayer)
    if not v then
    removeEventHandler("onClientRender"rootguiInter)

    unbindKey("arrow_r""down"down)
    unbindKey("mouse_wheel_down""down"down)
    unbindKey("arrow_l""down"up)
    unbindKey("mouse_wheel_up""down"up)
        return
  end

  if type_i == "join" then
    a1,a2,a3 interpolateBetween(a1a2a3255100200, (getTickCount()-tick)/500"Linear");
  elseif type_i == "quit" then
    a1,a2,a3 interpolateBetween(a1a2a3000, (getTickCount()-tick)/500"Linear");

    if(a1 == 0)then
      removeEventHandler("onClientRender"rootguiInter);
    end;
  end;

  dxDrawRectangle(00swshtocolor(151515a3), false)
  
  local max getElementData(v"vehicle:type") == "LPG" and or 6;
  local x = (960/zoom) - (32/zoom);
  local y = (540/zoom) - (82/zoom);

  if(selected and selected max)then
    dxDrawImage(x+100/zoomy64/zoom64/zoomimg[tbl[selected+1]], 000tocolor(255255255a2), false);
    dxDrawImage(xy64/zoom64/zoomimg[tbl[selected]], 000tocolor(255255255a1), false);
    dxDrawImage(x-100/zoomy64/zoom64/zoomimg[tbl[selected-1]], 000tocolor(255255255a2), false);
  elseif(selected == 1)then
    dxDrawImage(x+100/zoomy64/zoom64/zoomimg[tbl[2]], 000tocolor(255255255a2), false);
    dxDrawImage(xy64/zoom64/zoomimg[tbl[1]], 000tocolor(255255255a1), false);
  elseif(selected == max)then
    dxDrawImage(xy64/zoom64/zoomimg[tbl[selected]], 000tocolor(255255255a1), false);
    dxDrawImage(x-100/zoomy64/zoom64/zoomimg[tbl[selected-1]], 000tocolor(255255255a2), false);
  end;

  dxDrawText(selected_option[1](vselected), 110/zoom+1sw+1sh+1tocolor(000a1), 1font"center""center"falsefalsetruetrue)
  dxDrawText(selected_option[1](vselected), 010/zoomswshtocolor(255255255a1), 1font"center""center"falsefalsetruetrue)
end;

function gui()
    local v getPedOccupiedVehicle(localPlayer)
    if not v then
    tick_int getTickCount()
    type "quit"

    showCursor(false)
        return
    end

  if type == "join" then
    a interpolateBetween(00025500, (getTickCount()-tick_int)/500"Linear")

    if == 255 then
        int false
    else
        int true
    end
  elseif type == "quit" then
    a interpolateBetween(25500000, (getTickCount()-tick_int)/500"Linear")

    if == 0 then
        int false

        removeEventHandler("onClientRender"rootgui)
        removeEventHandler("onClientClick"rootclicked)
        removeEventHandler("onClientKey"rootkey)
    else
        int true
    end
  end

  dxDrawRectangle(00swshtocolor(151515200 and 200 or a), false)

  dxDrawText("Aby anulowa? kliknij dowolny klawisz."120/zoom+1sw+1sh+1tocolor(000a), 1font2"center""top"falsefalsetruetruefalse)
  dxDrawText("Aby anulowa? kliknij dowolny klawisz."020/zoomswshtocolor(255255255a), 1font2"center""top"falsefalsetruetruefalse)

  dxDrawImage(sw/2-650/2/zoomsh/2-650/2/zoom650/zoom650/zoomimg["car"], 000tocolor(255,30,30a), false)

    if getVehicleDoorOpenRatio(v0) == 0 then -- maska
        dxImage(sw/2-50/2/zoom190/zoom50/zoom50/zoomimg["click_on"], a)
    else
        dxImage(sw/2-50/2/zoom190/zoom50/zoom50/zoomimg["click_off"], a)
  end

    if getVehicleDoorOpenRatio(v1) == 0 then -- bagaznik
        dxImage(sw/2-50/2/zoomsh-(240/zoom), 50/zoom50/zoomimg["click_on"], a)
    else
        dxImage(sw/2-50/2/zoomsh-(240/zoom), 50/zoom50/zoomimg["click_off"], a)
    end

    if getVehicleDoorOpenRatio(v2) == 0 then -- lewo przod
        dxImage(sw/2-190/zoomsh-(564/zoom), 50/zoom50/zoomimg["click_on"], a)
    else
        dxImage(sw/2-190/zoomsh-(564/zoom), 50/zoom50/zoomimg["click_off"], a)
    end

    if getVehicleDoorOpenRatio(v3) == 0 then -- prawo przod
        dxImage(sw/2+140/zoomsh-(564/zoom), 50/zoom50/zoomimg["click_on"], a)
    else
        dxImage(sw/2+140/zoomsh-(564/zoom), 50/zoom50/zoomimg["click_off"], a)
    end

    if getVehicleMaxPassengers(v) == 3 then
        if getVehicleDoorOpenRatio(v4) == 0 then -- lewy tyl
            dxImage(sw/2-190/zoomsh-(500/zoom), 50/zoom50/zoomimg["click_on"], a)
        else
            dxImage(sw/2-190/zoomsh-(500/zoom), 50/zoom50/zoomimg["click_off"], a)
        end

        if getVehicleDoorOpenRatio(v5) == 0 then -- prawy tyl
            dxImage(sw/2+140/zoomsh-(500/zoom), 50/zoom50/zoomimg["click_on"], a)
        else
            dxImage(sw/2+140/zoomsh-(500/zoom), 50/zoom50/zoomimg["click_off"], a)
        end
  end
end

function dxImage(xywhimga)
    if isMouseIn(xywh) and not int then
        dxDrawImage(xywhimg000tocolor(255255255200), true)
    else
        dxDrawImage(xywhimg000tocolor(255255255a), true)
    end
end

function key(buttonpress)
  if button ~= "mouse1" and button ~= "mouse2" and press and not int then
    tick_int getTickCount()
    type "quit"

    showCursor(false)
  end
end

function clicked(btnstate)
    if btn ~= "state" and state ~= "down" then return end

    local v getPedOccupiedVehicle(localPlayer)
    if not v then return end

    if isMouseIn(sw/2-50/2/zoom190/zoom50/zoom50/zoomthen
        triggerServerEvent("wiecejOpcji"resourceRootv1)
    elseif isMouseIn(sw/2-50/2/zoomsh-(240/zoom), 50/zoom50/zoomthen
        triggerServerEvent("wiecejOpcji"resourceRootv2)
    elseif isMouseIn(sw/2-190/zoomsh-(564/zoom), 50/zoom50/zoomthen
        triggerServerEvent("wiecejOpcji"resourceRootv3)
  elseif isMouseIn(sw/2+140/zoomsh-(564/zoom), 50/zoom50/zoomthen
    triggerServerEvent("wiecejOpcji"resourceRootv4)
    elseif isMouseIn(sw/2-190/zoomsh-(500/zoom), 50/zoom50/zoom) and getVehicleMaxPassengers(v) == 3 then
        triggerServerEvent("wiecejOpcji"resourceRootv5)
    elseif isMouseIn(sw/2+140/zoomsh-(500/zoom), 50/zoom50/zoom) and getVehicleMaxPassengers(v) == 3 then
        triggerServerEvent("wiecejOpcji"resourceRootv6)
    end
end

function up()
  tick getTickCount()
  selected math.max(selected 11)
end

function down()
  local v getPedOccupiedVehicle(localPlayer)
  local max getElementData(v"vehicle:type") == "LPG" and or 6

  tick getTickCount()
  selected math.min(selected 1max)
end
-----------
local function openWindow()
    local veh getPedOccupiedVehicle(localPlayer)
    if veh then
        local vehType getVehicleType(veh)
        if vehType ~= "Automobile" and vehType ~= "Monster Truck" then return end
        if getElementData(veh"vehicle:mileage"then
        if tonumber(getElementData(veh"vehicle:mileage")) >= 30000 then 
            outputChatBox("* Masz 30,000 przebiegu, Tw?j silnik nie odpali! Udaj si? na zerowanie!"localPlayer25500)
            return 
        end
    end
        local seat getPedOccupiedVehicleSeat(localPlayer)
        if seatWindows[seat] and getVehicleDoorState(veh,seat+2) < 2 then
            triggerServerEvent("openWindow",resourceRoot,veh,seat,not isVehicleWindowOpen(veh,seatWindows[seat]))
        end
    end
end

addEvent("windowOpened",true)
local function windowOpened(veh,seat,state)
    setVehicleWindowOpen(veh,seatWindows[seat],state)
end
addEventHandler("windowOpened",resourceRoot,windowOpened)

local function bindInteraction(plr,seat)
    if plr ~= localPlayer then return end
    veh getPedOccupiedVehicle(plr)
    if getVehicleID(veh) == 605 and tonumber(getElementData(veh"vehicle:mileage")) >= 500 then 
        outputChatBox("#ff0000&#10008; #ffffff- Twoj pojazd posiada niewymieniony zbiornik, wymie? go aby odpali? silnik!"25500,true)
        return end 
        if getElementData(veh"vehicle:mileage"then
        if tonumber(getElementData(veh"vehicle:mileage")) >= 25000 then 
            outputChatBox("* Masz ju? ponad 25.000 przebiegu, je?li osi?gniesz 30.000 przebiegu - Tw?j silnik nie odpali!"25500end 
        end
    bindKey("lshift","down",openWindow)
    if seat == 0 then
        
        bindKey("lshift","both",wlaczInterakcje)
    end
end
addEventHandler("onClientVehicleEnter",root,bindInteraction)


db3 https://imgur.com/PXpB57k

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-15, 19:31


P.Wiśnia

Programista LUA






Wiek: 24
Na forum: 4044 dni
Posty: 568
Nick w MP: P.Wiśnia

Piwa: 376

Respekt: 100
Respekt: 100

Ja w tym co podes?a?e? nie widz? funkcji na w??czenie silnika.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-15, 19:44


Mazeusz







Wiek: 30
Na forum: 2673 dni
Posty: 52
Nick w MP: Mazeusz*



Respekt: 50

Ostrzeżeń: 80%
Serwer


local tick = {}


addEvent("switchENGINE"true)
addEventHandler("switchENGINE"resourceRoot, function(veh)
    setVehicleEngineState(vehnot getVehicleEngineState(veh))

    if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
        tick[client] = getTickCount()
    elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
        return
    end
    
    local text getVehicleEngineState(veh) ~= true and "gasi" or "odpala"
end)

addEvent("switchLIGHT"true)
addEventHandler("switchLIGHT"resourceRoot, function(veh)
    setVehicleOverrideLights(veh, (getVehicleOverrideLights(veh) == and or 2))
end)

addEvent("switchHANDBRAKE"true)
addEventHandler("switchHANDBRAKE"resourceRoot, function(veh_)
        if getElementData(veh"vehicle:handbrake") and not _ then
            setControlState(client"handbrake"false)
            setElementData(veh"vehicle:handbrake"false)
            setElementFrozen(vehfalse)

            if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
                tick[client] = getTickCount()
            elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
                return
            end
        else
            setControlState(client"handbrake"true)
            setElementData(veh"vehicle:handbrake"true)
            setElementFrozen(vehtrue)

            if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
                tick[client] = getTickCount()
            elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
                return
            end
    end
end)

addEvent("changeLOCKED"true)
addEventHandler("changeLOCKED"resourceRoot, function(veh)
    if isVehicleLocked(veh) == true then
        setVehicleLocked(vehfalse)

        if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
            tick[client] = getTickCount()
        elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
            return
        end

    else
        for 0,do
            setVehicleDoorOpenRatio(vehi02500)
        end

        setVehicleLocked(vehtrue)

        if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
            tick[client] = getTickCount()
        elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
            return
        end

    end
end)

addEvent("changeTYPE"true)
addEventHandler("changeTYPE"resourceRoot, function(veh)
    local newType getElementData(veh"vehicle:actualType") == "Benzyna" and "LPG" or "Benzyna"
    setElementData(veh"vehicle:actualType"newType)
end)

addEvent("kickOCCUPANTS"true)
addEventHandler("kickOCCUPANTS"resourceRoot, function(veh)
    local occupants getVehicleOccupants(veh)
    for i,v in pairs(occupants) do
        if ~= client then
            setControlState(v"enter_exit"true)
            setTimer(function()
                setControlState(v"enter_exit"false)
            end2001)

            if not tick[client] or tick[client] and (getTickCount() - tick[client]) > 3000 then
                tick[client] = getTickCount()
            elseif tick[client] and (getTickCount() - tick[client]) < 3000 then
                return
            end

        end
    end
end)

addEventHandler("onVehicleEnter"root, function(playerseat)
    if seat ~= 0 then return end

    if getElementData(source"vehicle:handbrake"then
        setControlState(player"handbrake"true)
        setElementFrozen(sourcefalse)
    end

    if getVehicleName(source) == "Bike" or getVehicleName(source) == "BMX" or getVehicleName(source) == "Mountain Bike" then
        setVehicleEngineState(sourcetrue)
        setElementData(source"vehicle:handbrake"false)
        setControlState(player"handbrake"false)
    end
end)

addEventHandler("onVehicleStartEnter"root, function(playerseat)
    if seat ~= 0 then return end
    
    if getVehicleController(source) == player then
        setVehicleLocked(sourcefalse)
    end
end)

addEventHandler("onVehicleExit"root, function(playerseat)
    for 0,do
        if == 2 then
            setVehicleDoorOpenRatio(sourcei01000)
        end
    end

    if seat == and getElementData(source"vehicle:handbrake"then
        setControlState(player"handbrake"false)
        setElementFrozen(sourcetrue)
        setVehicleLocked(sourcefalse)
    end
end)

addEvent("wiecejOpcji"true)
addEventHandler("wiecejOpcji"resourceRoot, function(vehx)
    if == 1 then
        if getVehicleDoorOpenRatio(veh0) == 0 then
            setVehicleDoorOpenRatio(veh01500)
        else
            setVehicleDoorOpenRatio(veh00500)
        end
    elseif == 2 then
        if getVehicleDoorOpenRatio(veh1) == 0 then
            setVehicleDoorOpenRatio(veh11500)
        else
            setVehicleDoorOpenRatio(veh10500)
        end
    elseif == 3 then
        if getVehicleDoorOpenRatio(veh2) == 0 then
            setVehicleDoorOpenRatio(veh21500)
        else
            setVehicleDoorOpenRatio(veh20500)
        end
    elseif == 4 then
        if getVehicleDoorOpenRatio(veh3) == 0 then
            setVehicleDoorOpenRatio(veh31500)
        else
            setVehicleDoorOpenRatio(veh30500)
        end
    elseif == 5 then
        if getVehicleDoorOpenRatio(veh4) == 0 then
            setVehicleDoorOpenRatio(veh41500)
        else
            setVehicleDoorOpenRatio(veh40500)
        end
    elseif == 6 then
        if getVehicleDoorOpenRatio(veh5) == 0 then
            setVehicleDoorOpenRatio(veh51500)
        else
            setVehicleDoorOpenRatio(veh50500)
        end
    end
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-15, 19:46


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Sprawdzaj przebieg w evencie switchENGINE.
Funkcje od wy??czenia silnika w poje?dzie ju? masz.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-15, 20:09


Mazeusz







Wiek: 30
Na forum: 2673 dni
Posty: 52
Nick w MP: Mazeusz*



Respekt: 50

Ostrzeżeń: 80%
Nie wiem jak to zrobi? mo?esz co? dopowiedziec

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-15, 23:38


Wilq







Wiek: 24
Na forum: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Co tutaj jest niezrozumia?ego, musisz sprawdza? przebieg w evencie switchENGINE. Je?li jest wi?kszy od danej liczby musisz anulowa? reszt? kodu za pomoc? "return end".

Postaw piwo autorowi tego posta
 

 
Tagi: interakcja :: przebieg
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Interakcja, przebieg 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