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

Wysłany: 2019-01-27, 18:15


Janushek*







Wiek: 27
Na forum: 3156 dni
Posty: 10

Piwa: 1

Respekt: 50

Witam! Przychodz? tutaj z ma?ym problemikiem dot. mechanika na GM ogrpg

Podam kod a pod nim obja?ni? o co mi chodzi.

https://pastebin.com/TtMMVS6V -jest do do?? d?ugie dlatego pastebin

Mianowicie chce zrobi? co? takiego, aby na ka?dy inny pojazd by?y inne ceny napraw, ale co? mi nie wychodzi

Prosz? o pomoc, wiem, ?e to jest banalne, ale ja si? dopiero ucz? :D

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-01-27, 20:48


Wilq







Wiek: 24
Na forum: 4570 dni
Posty: 3409

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Wykona?bym to w taki spos?b:
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 doCosts ={ [507] = {50, 20, 20, 15, 15, 15, 15, 40, 10, 10, 20, 20, 20, 20},
                 [508] = {40, 30, 15, 25, 30, 45, 32, 61, 20, 10, 64, 44, 52, 39}}

local wm={}
local isVehicles=nil
wm.window = guiCreateWindow(0.18, 0.21, 0.64, 0.52, "", true)
guiWindowSetSizable(wm.window, false)
guiSetVisible(wm.window, false)
guiSetAlpha(wm.window, 1.00)
wm.gridlist = guiCreateGridList(0.01, 0.07, 0.97, 0.75, true, wm.window)
guiGridListAddColumn(wm.gridlist, "Nazwa", 0.5)
guiGridListAddColumn(wm.gridlist, "Koszt", 0.5)
guiGridListAddRow(wm.gridlist)
wm.fixall = guiCreateButton(0.75, 0.85, 0.24, 0.11, "Napraw wszystko (200 PLN)", true, wm.window)
wm.fixparts = guiCreateButton(0.02, 0.85, 0.24, 0.11, "Napraw wybran? cz???", true, wm.window)

 
function wybrane()
    local pojazd = getPedOccupiedVehicle(getLocalPlayer())
    local model = getElementModel(pojazd)
    if doCosts[model] then
        local koszt = doCosts[model][<id cz??ci>]    
    end
end


Tworz? tabelk? z cenami cz??ci [doCosts] (odpowiednia pozycja to odpowiednia cz???) gdzie indeksem tabeli jest ID pojazdu.
Sprawdzam, czy pojazd gracza, kt?ry naprawia sw?j pojazd jest w naszej tabeli z cenami i pobieram cen? z tej tabeli z okre?lonej pozycji (np. gracz chce naprawi? Silnik, czyli pozycja numer 1).

W funkcji "wybrane" nie przesy?asz wskazanej cz??ci do naprawy i musisz to poprawi?, p??niej podmie? "<id cz??ci>" na w?a?nie pozycj? cz??ci, kt?r? chcesz naprawi?.

Nie wiem jak wygl?da Tw?j ca?y kod (chodzi o event gdzie gracz wybiera co chce naprawi?) wi?c nie jestem w stanie Ci? nakierowa? jak to dok?adnie wykona?. Je?li j??wy?lesz b?d? m?g? Ci pom?c tak?e w tym.

Oczywi?cie funkcja 'wybrane' nic nie wykonuje, nie powiedzia?e? co tam chcesz robi? - zwraca? cen? czy od razu j? pobra? z konta gracza naprawiaj?cego sw?j pojazd.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Janushek*
Wysłany: 2019-01-28, 22:11


Janushek*







Wiek: 27
Na forum: 3156 dni
Posty: 10

Piwa: 1

Respekt: 50

[ Dodano: 2019-01-28, 22:11 ]
Skrypt sam w sobie ju? dzia?a, ale nadal nie wczytuje cen element?w pojazdu

http://prntscr.com/mdeyu3

a oto ca?y kod (pystories 3.0 orgprg):

C_Side: https://pastebin.com/nkA8gm3C

Mo?e si? przyda - S_side: https://pastebin.com/KLCDUWsF

Og??em funkcja "wybrane" ma na celu pobranie cen danego pojazdu po czym nast?pnie wyswietlic to w gui (reszta kodu)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-01-28, 22:34


Wilq







Wiek: 24
Na forum: 4570 dni
Posty: 3409

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

W kodzie ?le pobiera?e? cen? z tabeli dla danego pojazdu, szybciej b?dzie je?li wklej? Ci gotowy kod, ty por?wnasz go z poprzednim kodem i wyci?gniesz wnioski ni? ja zaczn? opisywa? b??d.
Tak wi?c kr?tko:
funkcja 'pobierzCene' zwraca cene wskazanej cz??ci dla modelu pojazdu, je?li go nie ma w tabeli losuje cene mi?dzy 20 a 60.

https://pastebin.com/meM3G7sb

local m_dostep="mechanik-sf"

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 doCosts ={ [507] = {50, 20, 20, 15, 15, 15, 15, 40, 10, 10, 20, 20, 20, 20},
                 [597] = {40, 30, 15, 25, 30, 45, 32, 61, 20, 10, 64, 44, 52, 39}}

local wm={}
local isVehicles=nil
wm.window = guiCreateWindow(0.18, 0.21, 0.64, 0.52, "", true)
guiWindowSetSizable(wm.window, false)
guiSetVisible(wm.window, false)
guiSetAlpha(wm.window, 1.00)
wm.gridlist = guiCreateGridList(0.01, 0.07, 0.97, 0.75, true, wm.window)
guiGridListAddColumn(wm.gridlist, "Nazwa", 0.5)
guiGridListAddColumn(wm.gridlist, "Koszt", 0.5)
guiGridListAddRow(wm.gridlist)
wm.fixall = guiCreateButton(0.75, 0.85, 0.24, 0.11, "Napraw wszystko (200 PLN)", true, wm.window)
wm.fixparts = guiCreateButton(0.02, 0.85, 0.24, 0.11, "Napraw wybran? cz???", true, wm.window)

 
function pobierzCene(czesc)
    local model = getElementModel(isVehicles)
    if doCosts[model] then
        local koszt = doCosts[model][czesc] 
        if koszt > 0 then
            return koszt
        end
    else
        return math.random(20, 60)
    end
end



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, pobierzCene(i) .. " PLN", false, false)
            guiGridListSetItemData(wm.gridlist, row, 2, pobierzCene(i))
        end
    end
end

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
    local vehicles=getElementsWithinColShape(cs,"vehicle")
    if #vehicles < 1 then
        outputChatBox("* Na stanowisku naprawczym nie znajduje si? pojazd.", 255, 0, 0)
        return
    end
    if #vehicles > 1 then
        outputChatBox("* Na stanowisku naprawczym znajduje si? zbyt du?a ilo?? pojazd?w.", 255, 0, 0)
        return
    end
    --[[if getElementHealth(vehicles[1]) > 990 then
        outputChatBox("* Pojazd na stanowisku naprawczym jest sprawny.")
        return
    end]]
    showCursor(true, false)
    guiSetVisible(wm.window, 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, pobierzCene(i).." PLN", false, false)
            guiGridListSetItemData(wm.gridlist, row, 2, pobierzCene(i))
        end
    end
end)

addEventHandler("onClientMarkerLeave", resourceRoot, function(el,md)
    if el~=localPlayer then return end
    guiSetVisible(wm.window, false)
    isVehicles=nil
    showCursor(false)
end)

addEventHandler("onClientGUIClick", wm.fixparts, function()
    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 > getPlayerMoney(localPlayer) then
        outputChatBox("* Nie posiadasz tyle got?wki!")
        return
    end

    local part = guiGridListGetItemData(wm.gridlist, selectedRow, 1)
    outputChatBox('* Naprawiles ' .. tostring(getPartName(doFixed, part)))
    triggerServerEvent("takePlayerMoney", localPlayer, cost)
    triggerServerEvent("montazElementu", root, isVehicles, "naprawa", part, cost)
    setTimer(function()
        refreshGUI()
    end, 200, 2)
end)

addEventHandler("onClientGUIClick", wm.fixall, function()
    if not isVehicles or not isElement(isVehicles) then return end
    if 200 > getPlayerMoney(localPlayer) then
        outputChatBox("* Nie posiadasz tyle got?wki!")
        return
    end

    local elementyDoNaprawy=0
    for i,v in pairs(doFixed) do
        if v.fn(isVehicles)==false then
            elementyDoNaprawy=elementyDoNaprawy+1
        end
    end
    if elementyDoNaprawy==0 then
        outputChatBox('* Pojazd jest ju? naprawiony.')
        return
    end

    triggerServerEvent("takePlayerMoney", localPlayer, 200)
    outputChatBox('* Naprawi?e?(a?) wszystkie elementy w poje?dzie.')
    triggerServerEvent("montazElementu", root, isVehicles, "naprawa", "all", 200)
    setTimer(function()
        refreshGUI()
    end, 200, 2)
end)

-- utils
function getPartName(t, key)
    for i,v in pairs(t) do
        if v[2]==key then
            return v[1]
        end
    end
end
fileDelete('c_naprawa.lua')


Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Janushek*
Wysłany: 2019-01-29, 17:21


Janushek*







Wiek: 27
Na forum: 3156 dni
Posty: 10

Piwa: 1

Respekt: 50

Kod dzia?a jak chcia?em i wszystko jest ok. Rozumiem w jakim? tam stopniu na czym polega? m?j b??d, ale dla mnie napisanie nawet takiej cz??ci kodu stanowi problem :/ Jeszcze raz wielkie dzi?ki! Pozdrawiam.

Postaw piwo autorowi tego posta
 

 
Tagi: mechanik
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

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