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: 3015 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: 4428 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

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


local doCosts ={ [507] = {5020201515151540101020202020},
                 [508] = {4030152530453261201064445239}}

local wm={}
local isVehicles=nil
wm.window guiCreateWindow(0.180.210.640.52""true)
guiWindowSetSizable(wm.windowfalse)
guiSetVisible(wm.windowfalse)
guiSetAlpha(wm.window1.00)
wm.gridlist guiCreateGridList(0.010.070.970.75truewm.window)
guiGridListAddColumn(wm.gridlist"Nazwa"0.5)
guiGridListAddColumn(wm.gridlist"Koszt"0.5)
guiGridListAddRow(wm.gridlist)
wm.fixall guiCreateButton(0.750.850.240.11"Napraw wszystko (200 PLN)"truewm.window)
wm.fixparts guiCreateButton(0.020.850.240.11"Napraw wybran? cz???"truewm.window)

 
function wybrane()
    local pojazd getPedOccupiedVehicle(getLocalPlayer())
    local model getElementModel(pojazd)
    if doCosts[modelthen
        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: 3015 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: 4428 dni
Posty: 3410

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"1fn=function(veh) if getElementHealth(veh)>=2040 then return true end; return false end}, 
    {"Maska"2fn=function(veh) if getVehicleDoorState(veh0)==0 then return true end; return false end},
    {"Baga?nik"3fn=function(veh) if getVehicleDoorState(veh1)==0 then return true end; return false end},
    {"Drzwi lewy prz?d"4fn=function(veh) if getVehicleDoorState(veh2)==0 then return true end; return false end},
    {"Drzwi prawy prz?d"5fn=function(veh) if getVehicleDoorState(veh3)==0 then return true end; return false end},
    {"Drzwi lewy ty?"6fn=function(veh) if getVehicleDoorState(veh4)==0 then return true end; return false end},
    {"Drzwi prawy ty?"7fn=function(veh) if getVehicleDoorState(veh5)==0 then return true end; return false end},
    {"Szyba przednia"8fn=function(veh) if getVehiclePanelState(veh4)==0 then return true end; return false end},
    {"Zderzak przedni"9fn=function(veh) if getVehiclePanelState(veh5)==0 then return true end; return false end},
    {"Zderzak tylni"10fn=function(veh) if getVehiclePanelState(veh6)==0 then return true end; return false end},
    {"?wiat?o lewe przednie"11fn=function(veh) if getVehicleLightState(veh0)==0 then return true end; return false end},
    {"?wiat?a prawe przednie"12fn=function(veh) if getVehicleLightState(veh1)==0 then return true end; return false end},
    {"?wiat?a lewe tylnie"13fn=function(veh) if getVehicleLightState(veh2)==0 then return true end; return false end},
    {"?wiat?a prawe tylnie"14fn=function(veh) if getVehicleLightState(veh3)==0 then return true end; return false end},
    
}


local doCosts ={ [507] = {5020201515151540101020202020},
                 [597] = {4030152530453261201064445239}}

local wm={}
local isVehicles=nil
wm.window guiCreateWindow(0.180.210.640.52""true)
guiWindowSetSizable(wm.windowfalse)
guiSetVisible(wm.windowfalse)
guiSetAlpha(wm.window1.00)
wm.gridlist guiCreateGridList(0.010.070.970.75truewm.window)
guiGridListAddColumn(wm.gridlist"Nazwa"0.5)
guiGridListAddColumn(wm.gridlist"Koszt"0.5)
guiGridListAddRow(wm.gridlist)
wm.fixall guiCreateButton(0.750.850.240.11"Napraw wszystko (200 PLN)"truewm.window)
wm.fixparts guiCreateButton(0.020.850.240.11"Napraw wybran? cz???"truewm.window)

 
function pobierzCene(czesc)
    local model getElementModel(isVehicles)
    if doCosts[modelthen
        local koszt doCosts[model][czesc] 
        if koszt 0 then
            return koszt
        end
    else
        return math.random(2060)
    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.gridlistrow1v[1], falsefalse)
            guiGridListSetItemData(wm.gridlistrow1i)
            guiGridListSetItemText(wm.gridlistrow2pobierzCene(i) .. " PLN"falsefalse)
            guiGridListSetItemData(wm.gridlistrow2pobierzCene(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."25500)
        return
    end
    if #vehicles > 1 then
        outputChatBox("* Na stanowisku naprawczym znajduje si? zbyt du?a ilo?? pojazd?w."25500)
        return
    end
    --[[if getElementHealth(vehicles[1]) > 990 then
        outputChatBox("* Pojazd na stanowisku naprawczym jest sprawny.")
        return
    end]]
    showCursor(truefalse)
    guiSetVisible(wm.windowtrue)
    isVehicles vehicles[1]
    guiGridListClear(wm.gridlist)
    for iv in pairs(doFixed) do
        if v.fn(isVehicles)==false then
            local row guiGridListAddRow(wm.gridlist)
            guiGridListSetItemText(wm.gridlistrow1v[1], falsefalse)
            guiGridListSetItemData(wm.gridlistrow1i)
            guiGridListSetItemText(wm.gridlistrow2pobierzCene(i).." PLN"falsefalse)
            guiGridListSetItemData(wm.gridlistrow2pobierzCene(i))
        end
    end
end)

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

addEventHandler("onClientGUIClick"wm.fixparts, function()
    if not isVehicles or not isElement(isVehiclesthen return end
    selectedRow guiGridListGetSelectedItem(wm.gridlist) or -1
    if selectedRow 0 then return end
    local cost guiGridListGetItemData(wm.gridlistselectedRow2)
    if cost getPlayerMoney(localPlayerthen
        outputChatBox("* Nie posiadasz tyle got?wki!")
        return
    end

    local part guiGridListGetItemData(wm.gridlistselectedRow1)
    outputChatBox('* Naprawiles ' .. tostring(getPartName(doFixedpart)))
    triggerServerEvent("takePlayerMoney"localPlayercost)
    triggerServerEvent("montazElementu"rootisVehicles"naprawa"partcost)
    setTimer(function()
        refreshGUI()
    end2002)
end)

addEventHandler("onClientGUIClick"wm.fixall, function()
    if not isVehicles or not isElement(isVehiclesthen return end
    if 200 getPlayerMoney(localPlayerthen
        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"localPlayer200)
    outputChatBox('* Naprawi?e?(a?) wszystkie elementy w poje?dzie.')
    triggerServerEvent("montazElementu"rootisVehicles"naprawa""all"200)
    setTimer(function()
        refreshGUI()
    end2002)
end)

-- utils
function getPartName(tkey)
    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: 3015 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