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

Wysłany: 2020-10-04, 17:10


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

Witajcie bawi? si? w tworzenie systemu naprawy i napotka?em problem z wykryciem kierowcy podpowiem, ?e chc? by wykry?o, ?e kierowca jest w cuboidzie


addEventHandler("onClientMarkerHit", resourceRoot, function(el,md)
    if not md or el~=localPlayer then return end
   local cs=getElementData(source, "snn_cs")
    if not cs then return end
    vehicles=getElementsWithinColShape(cs,"vehicle")
    vehicles2=getElementsWithinColShape(cs,"player")
    driver=getVehicleController(vehicles2)
     if #vehicles < 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym nie znajduje si?\npojazd', 'error')
        return
    end
    if #vehicles > 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym znajduje si?\nzbyt du?a ilo?? pojazd?w', 'error')
        return
    end
    if not driver then triggerEvent('onClientAddNotification', localPlayer, 'Brak kierowcy', 'error')
        return
    end


Marker b?dzie u?ywa?a osoba trzecia nie osoba kt?ra sied? w aucie.

Ostatnio zmieniony przez killercycDDS 2020-10-04, 17:23, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 17:23


NotPaladyn







Wiek: 23
Na forum: 2931 dni
Posty: 866
Nick w MP: NotPaladyn

Piwa: 3150

Respekt: 690
Respekt: 690Respekt: 690


   Vice Admin: Jeśli potrzebujesz pomocy w sprawach organizacyjnych lub technicznych - skontaktuj się ze mną.
W argumencie funkcji getVehicleController podaje si? zmienn? pojazdu z kt?rego chcesz pobra? kierowc? a ty poda?e? gracza

Spr?buj tak:

driver=getVehicleController(vehicles)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 17:25


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

Marker b?dzie u?ywa?a osoba trzecia nie osoba kt?ra sied? w aucie.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 18:02


NotPaladyn







Wiek: 23
Na forum: 2931 dni
Posty: 866
Nick w MP: NotPaladyn

Piwa: 3150

Respekt: 690
Respekt: 690Respekt: 690


   Vice Admin: Jeśli potrzebujesz pomocy w sprawach organizacyjnych lub technicznych - skontaktuj się ze mną.
Sorki, ?le zauwa?y?em

Kierowce pobierz tak:

addEventHandler("onClientMarkerHit", resourceRoot, function(el,md)
    if not md or el~=localPlayer then return end
   local cs=getElementData(source, "snn_cs")
    if not cs then return end
    vehicles=getElementsWithinColShape(cs,"vehicle")
    vehicles2=getElementsWithinColShape(cs,"player")
pojazd=getPedOccupiedVehicle(localPlayer)
    driver=getVehicleController(pojazd)
     if #vehicles < 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym nie znajduje si?\npojazd', 'error')
        return
    end
    if #vehicles > 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym znajduje si?\nzbyt du?a ilo?? pojazd?w', 'error')
        return
    end
    if not driver then triggerEvent('onClientAddNotification', localPlayer, 'Brak kierowcy', 'error')
        return
    end


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 21:46


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

NotPaladyn, dalej wywala b??d


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 22:02


NotPaladyn







Wiek: 23
Na forum: 2931 dni
Posty: 866
Nick w MP: NotPaladyn

Piwa: 3150

Respekt: 690
Respekt: 690Respekt: 690


   Vice Admin: Jeśli potrzebujesz pomocy w sprawach organizacyjnych lub technicznych - skontaktuj się ze mną.
Spr?buj tak, ja testowa?em i mi dzia?a:
addEventHandler("onClientMarkerHit", resourceRoot, function(el,md)
    if not md or el~=localPlayer then return end
   local cs=getElementData(source, "snn_cs")
    if not cs then return end
    vehicles=getElementsWithinColShape(cs,"vehicle")
    vehicles2=getElementsWithinColShape(cs,"player")
    pojazd=getPedOccupiedVehicle(localPlayer)
     if #vehicles < 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym nie znajduje si?\npojazd', 'error')
        return
    end
    if #vehicles > 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym znajduje si?\nzbyt du?a ilo?? pojazd?w', 'error')
        return
    end
    if getVehicleController(pojazd) ~= localPlayer then triggerEvent('onClientAddNotification', localPlayer, 'Brak kierowcy', 'error')
        return
    end


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-04, 22:30


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

NotPaladyn, dzia?a ale nie tak jak chce. Dzia?a jak ja siedz? jako kierowca i wjad? w marker. A gdy inna osoba siedzi i ja wejd? w marker by mu naprawi? to wywala ten b??d co jest wy?ej




--local cub = createColCuboid(-1679.6823730469, -197.16946411133, 12.8984375, 8 , 4.5, 3)

function przecinek(liczba)  
    local format = liczba  
    while true do      
        format, k = string.gsub(format, "^(-?%d+)(%d%d%d)", '%1,%2')    
        if ( k==0 ) then      
            break  
        end  
    end  
    return format
end



local matker = createMarker(-1680.82, -210.11, 14.15-0.8,"cylinder",2,255,215,0)

mojeW,mojeH = 1280, 1024
sW,sH = guiGetScreenSize()
w, h = (sW/mojeW), (sH/mojeH)

local sx, sy = guiGetScreenSize ()

--local marker2 = createMarker(-1679.57, -198.90, 14.15-0.8,"cylinder",2,255,215,0)

naprawa = false

function gui()
    dxDrawImage(315*w, 313*h, 650*w, 400*h, "naprawa-psrpg.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
end

function gui_rozpoczecia_duty()
    local wynagrodzenie = (5000)
    local xd = getElementData(localPlayer,"mech:minuty") or 0
    local kasa = tonumber(xd)*tonumber(wynagrodzenie) or 0
    dxDrawImage(593, 269, 606, 617, ":ec-logowanie/img/to_fajen.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
    dxDrawText("Rozpocz?cie S?u?by Mechanika", 595, 270, 1199, 327, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    dxDrawText("Tutaj mo?esz rozpocz?? s?u?b? jako machanik aut./nPraca w tym polega na naprawianiu aut innym gracz?.\nZa godzin? s?u?b? otrzymasz X PLN.", 597, 333, 1199, 677, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    dxDrawRectangle(777, 805, 182, 81, tocolor(0, 0, 0, 164), false)
    dxDrawRectangle(1017, 805, 182, 81, tocolor(0, 0, 0, 164), false)
    dxDrawText("Przepracowa?e?: "..xd.." min\nOtrzymasz: "..kasa.." PLN", 1017, 677, 1199, 805, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    dxDrawText("Wyp?a? przepracowane minuty", 1017, 805, 1199, 886, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    if getElementData(localPlayer,"mechanik:duty") then 
    dxDrawText("Zako?cz S?u?b?", 777, 805, 959, 886, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    else
    dxDrawText("Rozpocznij S?u?b?", 777, 805, 959, 886, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, false, false)
    end
end

function napis()
    if((getTickCount()-tickxd) > 1000)then
        tickxd=getTickCount();
        timexd=timexd+1;
    end
    dxDrawText("#3366FFMechanik:#FFFFFF "..secondsToClock(timexd).. "", 1711, 979, 1820, 1044, tocolor(255, 255, 255, 255), 1.30, "default", "center", "center", false, false, false, true, false)
end

local doFixed={
    {"Silnik", 1, fn=function(veh) if getElementHealth(veh)>=2040 then return true end; return false end},
    {"Maska", 2, fn=function(veh) if getVehicleDoorState(veh, 0)==0 then return true end; return false end},
    {"Baga?nik", 3, fn=function(veh) if getVehicleDoorState(veh, 1)==0 then return true end; return false end},
    {"Drzwi lewy prz?d", 4, fn=function(veh) if getVehicleDoorState(veh, 2)==0 then return true end; return false end},
    {"Drzwi prawy prz?d", 5, fn=function(veh) if getVehicleDoorState(veh, 3)==0 then return true end; return false end},
    {"Drzwi lewy ty?", 6, fn=function(veh) if getVehicleDoorState(veh, 4)==0 then return true end; return false end},
    {"Drzwi prawy ty?", 7, fn=function(veh) if getVehicleDoorState(veh, 5)==0 then return true end; return false end},
    {"Szyba przednia", 8, fn=function(veh) if getVehiclePanelState(veh, 4)==0 then return true end; return false end},
    {"Zderzak przedni", 9, fn=function(veh) if getVehiclePanelState(veh, 5)==0 then return true end; return false end},
    {"Zderzak tylni", 10, fn=function(veh) if getVehiclePanelState(veh, 6)==0 then return true end; return false end},
    {"?wiat?o lewe przednie", 11, fn=function(veh) if getVehicleLightState(veh, 0)==0 then return true end; return false end},
    {"?wiat?a prawe przednie", 12, fn=function(veh) if getVehicleLightState(veh, 1)==0 then return true end; return false end},
    {"?wiat?a lewe tylnie", 13, fn=function(veh) if getVehicleLightState(veh, 2)==0 then return true end; return false end},
    {"?wiat?a prawe tylnie", 14, fn=function(veh) if getVehicleLightState(veh, 3)==0 then return true end; return false end},
}

local wm={}
local isVehicles=nil
wm.gridlist = guiCreateGridList(357*w, 393*h, 567*w, 218*h, false)
guiGridListAddColumn(wm.gridlist, "Cz???", 0.45)
guiGridListAddColumn(wm.gridlist, "Koszt", 0.45)
guiGridListAddRow(wm.gridlist)
guiSetVisible(wm.gridlist, false)
guiSetAlpha(wm.gridlist, 0.8)
guiSetFont(wm.gridlist, "default-bold-small")

local function refreshGUI()
    if not isVehicles then return end
    guiGridListClear(wm.gridlist)
    for i,v in pairs(doFixed) do
        if v.fn(isVehicles)==false then
            local row = guiGridListAddRow(wm.gridlist)
            guiGridListSetItemText(wm.gridlist, row, 1, v[1], false, false)
            guiGridListSetItemData(wm.gridlist, row, 1, i)
            guiGridListSetItemText(wm.gridlist, row, 2, przecinek(doCosts[i]).." PLN", false, false)
            guiGridListSetItemData(wm.gridlist, row, 2, doCosts[i])
end
end
end
local doCosts ={ 5000, 1000, 1000, 2000, 1000, 2000, 1500, 15000, 2000, 10000, 100000, 4000, 3300, 1500 }

addEvent("napison",true)
addEventHandler("napison",resourceRoot,function()
    tickxd = getTickCount()
    timexd = 0
    addEventHandler("onClientRender", root, napis)
end)
addEvent("napisoff",true)
addEventHandler("napisoff",resourceRoot,function()
    tickxd = getTickCount()
    timexd = 0
    removeEventHandler("onClientRender", root, napis)
end)

addEventHandler("onClientMarkerHit", matker, function(el,md)
    if el~=localPlayer then return end
    if getPedOccupiedVehicle(el) then return end
        showCursor(true)
        addEventHandler("onClientRender", root, gui_rozpoczecia_duty)
        setElementData(el, "marker:mechanik", true)
end)

addEventHandler("onClientMarkerHit", resourceRoot, function(el,md)
    if not md or el~=localPlayer then return end
   cs=getElementData(source, "snn_cs")
    if not cs then return end
    vehicles=getElementsWithinColShape(cs,"vehicle")
    --pojazd=getPedOccupiedVehicle(localPlayer)
     if #vehicles < 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym nie znajduje si?\npojazd', 'error')
        return
    end
    if #vehicles > 1 then
        triggerEvent('onClientAddNotification', localPlayer, 'Na stanowisku naprawczym znajduje si?\nzbyt du?a ilo?? pojazd?w', 'error')
        return
    end
    --[[pojazd=getPedOccupiedVehicle(vehicles)
    kierowca = getVehicleController(vehicles)
    if kierowca then triggerEvent('onClientAddNotification', localPlayer, 'Brak kierowcy', 'error')
        return
    end--]]
    showCursor(true, false)
    guiSetVisible(wm.gridlist, true)
    if naprawa == false then
    addEventHandler("onClientRender",root,gui)
    naprawa = true
    isVehicles = vehicles[1]
    guiGridListClear(wm.gridlist)
    for i,v in pairs(doFixed) do
        if v.fn(isVehicles)==false then
            local row = guiGridListAddRow(wm.gridlist)
            guiGridListSetItemText(wm.gridlist, row, 1, v[1], false, false)
            guiGridListSetItemData(wm.gridlist, row, 1, i)
            guiGridListSetItemText(wm.gridlist, row, 2,przecinek(doCosts[i]).." $", false, false)
            guiGridListSetItemData(wm.gridlist, row, 2, doCosts[i])
            guiGridListSetItemText(wm.gridlist, row, 1, v[1], false, false)
            guiGridListSetItemData(wm.gridlist, row, 1, i)
end
end
end
end)

addEventHandler("onClientMarkerLeave", resourceRoot, function(el,md)
    if el~=localPlayer then return end
    guiSetVisible(wm.gridlist, false)
    removeEventHandler("onClientRender",root,gui)
    naprawa = false
    isVehicles=nil
    showCursor(false)
end)

addEventHandler("onClientClick", root, function(btn, state)
    if btn == "left" and state == "down" then
    if mysz(777, 805, 182, 81) and isEventHandlerAdded("onClientRender", root, gui_rozpoczecia_duty) then
    triggerServerEvent("rozpocznij:sluzbe",root,localPlayer,localPlayer)
    removeEventHandler("onClientRender", root, gui_rozpoczecia_duty)
    showCursor(false)
    setElementData(localPlayer,"marker:mechanik",false)
end 
end
end)



function secondsToClock(seconds)
    seconds = seconds or 0
    if seconds <= 0 then
        return "00:00"
    else
        hours = string.format("%02.f", math.floor(seconds/3600))
        mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)))
        secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60))
        return "" .. mins .." minuty " .. secs .. " sekundy "
    end
    end
    

        function mysz ( x, y, width, height )
            if ( not isCursorShowing( ) ) then
                return false
            end
            local sx, sy = guiGetScreenSize ( )
            local cx, cy = getCursorPosition ( )
            local cx, cy = ( cx * sx ), ( cy * sy )
            if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
                return true
            else
                return false
            end
        end
        
        
        function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
            if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
                 local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
                 if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
                      for i, v in ipairs( aAttachedFunctions ) do
                           if v == func then
                            return true
                       end
                  end
             end
            end
            return false
        end


        function getPartName(t, key)
            for i,v in pairs(t) do
                if v[2]==key then
                    return v[1]
                end
            end
        end

        addEventHandler("onClientClick", root, function(btn, state)
            if btn == "left" and state == "down" then
            if naprawa == true then
            if mysz(352*w, 624*h, 210*w, 78*h) then
            if not isVehicles or not isElement(isVehicles) then return end
            selectedRow = guiGridListGetSelectedItem(wm.gridlist) or -1
            if selectedRow < 0 then return end
            local cost = guiGridListGetItemData(wm.gridlist, selectedRow, 2)
            if cost > getElementData(localPlayer,"kasa:gracza") and not getElementData(localPlayer, "player:duty") == "SP" and not getElementData(localPlayer, "player:duty") == "P" and not getElementData(localPlayer, "player:duty") == "PR" and not getElementData(localPlayer, "player:duty") == "SATS" then
                outputChatBox("#bf0101(&#10006;) #FFFFFFNie masz tyle got?wki!", 255,255,255, true)
                cancelEvent()
                return
            end
            if getElementData(localPlayer, "player:duty") == "SP" then cost = 0 end
            if getElementData(localPlayer, "player:duty") == "P" then cost = 0 end
            if getElementData(localPlayer, "player:duty") == "PR" then cost = 0 end
            local part = guiGridListGetItemData(wm.gridlist, selectedRow, 1)
            if getElementData(vehicles2,"kasa:gracza") < cost then 
                triggerEvent('onClientAddNotification', localPlayer, 'Nie posiadasz wystarczaj?co got?wki\ndo naprawy pojazdu', 'error') return end    
            outputChatBox('(&#10004;) Naprawi?e? cz???: ' .. tostring(getPartName(doFixed, part, 255,255,255, true)))
            setElementData(vehicles2,"kasa:gracza", getElementData(vehicles2,"kasa:gracza")-cost)
            setElementData(localPlayer,"kasa:gracza", getElementData(localPlayer,"kasa:gracza")+cost)
            --triggerServerEvent("takePlayerMoney", localPlayer, cost)
            triggerServerEvent("montazElementu", root, isVehicles, "naprawa", part, cost)
            setTimer(function()
                refreshGUI()
            end, 10000, 2)
            end
            end
            end
        end)
    


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-07, 11:46


kamison

Przyszły programista .lua






Wiek: 25
Na forum: 3443 dni
Posty: 391
Nick w MP: kamison

Piwa: 599

Respekt: 205,3
Respekt: 205,3Respekt: 205,3

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-07, 12:33


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

"kamison" napisał/a:


Auto znajduje si? w cuboidzie a kapk? obok jest marker, kt?ry b?dzie obs?ugiwany przez osob? trzeci? a nie osob?, kt?ra siedzi w poje?dzie :D

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-07, 13:23


kamison

Przyszły programista .lua






Wiek: 25
Na forum: 3443 dni
Posty: 391
Nick w MP: kamison

Piwa: 599

Respekt: 205,3
Respekt: 205,3Respekt: 205,3

"killercycDDS" napisał/a:

"kamison" napisał/a:


Auto znajduje si? w cuboidzie a kapk? obok jest marker, kt?ry b?dzie obs?ugiwany przez osob? trzeci? a nie osob?, kt?ra siedzi w poje?dzie :D


W takim razie po co w og?le sprawdza? czy kto? jest w aucie?
Zr?b tylko sprawdzenie if getElementType(el) == "vehicle" then i tyle. Nie widz? w tym wypadku sensu sprawdzania czy kto? jest w aucie

Podpis
Coś tam kiedyś robiłem.

DC: kamison_.
Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-07, 21:37


killercycDDS

Migacz






Wiek: 26
Na forum: 4653 dni
Posty: 629
Nick w MP: killer_cyc[DDS]

Piwa: 1667

Respekt: 22

"kamison" napisał/a:

"killercycDDS" napisał/a:

"kamison" napisał/a:


Auto znajduje si? w cuboidzie a kapk? obok jest marker, kt?ry b?dzie obs?ugiwany przez osob? trzeci? a nie osob?, kt?ra siedzi w poje?dzie :D


W takim razie po co w og?le sprawdza? czy kto? jest w aucie?
Zr?b tylko sprawdzenie if getElementType(el) == "vehicle" then i tyle. Nie widz? w tym wypadku sensu sprawdzania czy kto? jest w aucie


Jest bo b?d? robi? tak, ?e mechanik jak wybierze opcje i pobierze osobie w aucie hajs a mechanikowi da

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-07, 21:47


kamison

Przyszły programista .lua






Wiek: 25
Na forum: 3443 dni
Posty: 391
Nick w MP: kamison

Piwa: 599

Respekt: 205,3
Respekt: 205,3Respekt: 205,3

Czyli musisz skorzysta? z tej funkcji kt?r? poda?em w przyk?adzie

Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-08, 07:41


chade

bad argument






Wiek: 24
Na forum: 3520 dni
Posty: 19
Nick w MP: Hoskin

Piwa: 2653

Respekt: 70


Więcej informacji znajdziesz w Wikipedii MTA:

getVehicleController


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-08, 08:49


kamison

Przyszły programista .lua






Wiek: 25
Na forum: 3443 dni
Posty: 391
Nick w MP: kamison

Piwa: 599

Respekt: 205,3
Respekt: 205,3Respekt: 205,3

"chade" napisał/a:


Więcej informacji znajdziesz w Wikipedii MTA:

getVehicleController


By?o, on musi skorzysta? z funkcji, kt?r? poda?em w przyk?adzie innej opcji nie ma.

Podpis
Coś tam kiedyś robiłem.

DC: kamison_.
Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-10-14, 13:13


maciek3286

LUA Developer






Wiek: 26
Na forum: 5342 dni
Posty: 230
Nick w MP: maciek00

Piwa: 3211

Respekt: 101,5
Respekt: 101,5

killercycDDS, nie sprawdzisz tego po stronie klienta. Musia? by? tworzy? marker czy tam colshape po stronie serwera i wtedy pobiera? pojazd z colshape je?li jest to wtedy dopiero kierowc?.

Postaw piwo autorowi tego posta
 

 
Tagi: wykrycie :: kierowcy
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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