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

Wysłany: 2018-06-25, 17:48


Kulegg







Wiek: 46
Na forum: 3125 dni
Posty: 283

Piwa: 20

Respekt: 50

Witam, mam gielde z og-gielda

i jest jeden problem bo jak pr?buje sprzedac komus auto to pisze ze nie znaleziono podanego gracza:

Kod:

 local LIMIT=300 -- tylko gracz mo?e kupitrzy pojazdy

local cmd="sprzedaj.pojazd"
local cmd2="akceptuj"
local sprzedazPojazdu={}
marker2=nil
local timer=nil

local pozycjeMarkerowv2={
    -- Opis nad markeremx,y,zintdim
    {"Gie?da\nSprzeda? pojazd?w"2169.531416.6110.82},
}

for i,v in pairs(pozycjeMarkerowv2) do
    mkr=createMarker(v[2], v[3], v[4]-0.90"cylinder"22551111125)
    setElementDimension(mkr2v[6] or 0)
    setElementInterior(mkr2v[5] or 0)
    
    marker2=mkr
    
    local t=createElement("text")
    setElementData(t,"name",v[1])
    setElementPosition(t,v[2],v[3],v[4])
    setElementDimension(tv[6] or 0)
    setElementInterior(tv[5] or 0)
end


function checkVehiclePlayer(plr)
    -- Pobieramy tabeli nast?pnie zwracamy j?
    local result=exports["og-db"]:getRekord("SELECT * FROM og_vehicles")
    local number=0
    -- Uruchamiamy p?tlspradzaj?cpojazdy z bazy danych i
    -- por?wnujemy w?a?ciciela z UID osoby kt?ra chce zakupi?
    for i,v in ipairs(result) do
        if result[1].ownedPlayer == getElementData(plr,"player:uid"then
            number=number+1
        end
    end
    -- Zwracamy ilo?? pojazd?w gracza je?eli nie ma zwr?ci
    -- mu false.
    return number
end

local function pokazOperacje(plr)
    if not sprzedazPojazdu[plrthen return end
    local veh=sprzedazPojazdu[plr][3] -- sprawdzanie tablicy
    outputChatBox("* Otrzyma?e?/a? ofert? sprzeda?y pojazdu "..getVehicleNameFromModel(getVehicleModel(veh)).." za cen? "..sprzedazPojazdu[plr][4], plr2552550)
    outputChatBox("* ID: "..getElementData(veh,"vehicle:id").." | Przebieg: "..getElementData(veh,"vehicle:mileage")..""plr2552550)
    outputChatBox("* Aby potwierdzi? zakup prosz? wpisa? /akceptuj, masz 20 sekund"plr2552550)
    timer=setTimer(function()
        sprzedazPojazdu[plr]=nil
        outputChatBox("* Transakcja zosta?a anulowana."plr25500)
        removeCommandHandler("akceptuj"akceptujTransakcje) -- usuwanie komendy
    end200001)
    addCommandHandler("akceptuj"akceptujTransakcje) -- tworzenie komendy
end

function akceptujTransakcje(plr,cmd)
    if not sprzedazPojazdu[plrthen return end
    local veh=sprzedazPojazdu[plr][3]
    local cost=sprzedazPojazdu[plr][4]
    local target=sprzedazPojazdu[plr][1]
    if cost 0 then
        outputChatBox("* Cena jest nieprawid?owa."plr)
        return
    end
    if tonumber(cost) > getPlayerMoney(plrthen
        outputChatBox("* Nie posiadasz tyle got?wki."plr)
        return
    end
    givePlayerMoney(targetcost)
    takePlayerMoney(plrcost)
    killTimer(timer)
    outputChatBox("* Sprzeda? przeprowadzona pomy?lnie."plr)
    outputChatBox("* Sprzeda? przeprowadzona pomy?lnie."target)
    removeCommandHandler("akceptuj"akceptujTransakcje) -- usuwanie komendy
    wykonajZapytanie(veh,plr) -- do bazy danych ustawiamy od razu
end

function wykonajZapytanie(veh,plr)
    setElementData(veh,"vehicle:ownedGroup"0)
    setElementData(veh,"vehicle:ownedFaction"0)
    setElementData(veh,"vehicle:ownedPlayer",getElementData(plr,"player:uid"))
    exports["og-db"]:setRekord("UPDATE og_vehicles SET ownedPlayer=? AND ownedGroup=0 AND ownedFaction=0 WHERE id=?"getElementData(plr,"player:uid"), getElementData(veh,"vehicle:id"))
end

addCommandHandler(cmd, function(plr,_,cel,id,cost)
    if not isElementWithinMarker(plr,marker2then
        outputChatBox("* Nie jeste? w miejscu przeznaczonym do tego."plr25500)
        return
    end
    costt=tonumber(cost)
    if not cel or not costt then
        outputChatBox("* U?ycie: /sprzedaj.pojazd <nick/ID> <id pojazdu> <cena>"plr)
        return
    end
    local target=exports["og-core"]:findPlayer(plr,cel)
    if not target then
        outputChatBox("* Nie znaleziono podanego gracza."plr25500)
        return
    end
    if not isElementWithinMarker(target,marker2then
        outputChatBox("* Gracz nie jest w miejscu przeznaczonym do tego."plr25500)
        return
    end
    if tonumber(costt) < 0 then
        outputChatBox("* Poda?e? nieprawid?ow? warto??."plr25500)
        return
    end
    local result=exports["og-db"]:getRekord("SELECT * FROM og_vehicles WHERE id=? AND parking=1 LIMIT 1;"id)
    if result and #result > 0 then
        outputChatBox("* Pojazd znajduje na parkingu, nie mo?esz go sprzeda?."plr25500)
        return
    end
    for _,vehicle in ipairs(getElementsByType("vehicle")) do
        if tonumber(getElementData(vehicle,"vehicle:id")) == tonumber(idthen
            if tonumber(getElementData(vehicle,"vehicle:ownedPlayer")) ~= tonumber(getElementData(plr,"player:uid")) then
                outputChatBox("* Nie jeste? w?a?cicielem pojazdu."plr25500)
                return
            end
            sprzedazPojazdu[target]={plr,target,vehicle,costt}
        end
    end
    -- Warunek sprawdzaj?ca ile gracz ma pojazd?wje?eli bedzie mia?
    -- wi?cej niLIMIT na g?rze to wy?wietli mu sikomunikat.
    if checkVehiclePlayer(target) and checkVehiclePlayer(target) >= LIMIT then
        outputChatBox("* Maksymalnie ten gracz mo?e mie?: "..LIMIT.." pojazd?w"plr25500)
        return
    end
    pokazOperacje(target)
    outputChatBox("* Pomy?lnie wys?ano ofert? o sprzeda? pojazdu."plr)
end)

addEventHandler("onMarkerHit"marker2, function(el,md)
    outputChatBox("* Wpisz /sprzedaj.pojazd <nick/ID> <id pojazdu> <cena> "el)
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-06-25, 18:04


PatryKK.

Emeryt LUA






Wiek: 26
Na forum: 3061 dni
Posty: 1060
Nick w MP: PatryKK.

Piwa: 2322

Respekt: 331,5
Respekt: 331,5Respekt: 331,5Respekt: 331,5

Dlatego, ?e musisz pod??czy? pod swoj? baz? danych odpowiednie warto?ci.

Podpis
GG:75080675
- ✔
- ✔
- ✔
- ✔

Aktualny projekt: BRAK
Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-06-25, 18:07


Kulegg







Wiek: 46
Na forum: 3125 dni
Posty: 283

Piwa: 20

Respekt: 50

to znaczy?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-06-25, 18:08


PatryKK.

Emeryt LUA






Wiek: 26
Na forum: 3061 dni
Posty: 1060
Nick w MP: PatryKK.

Piwa: 2322

Respekt: 331,5
Respekt: 331,5Respekt: 331,5Respekt: 331,5

Musisz si? nauczy? sam robic, bo got?wce to nie wszystko.

 local LIMIT=300 -- tylko gracz mo?e kupitrzy pojazdy

local cmd="sprzedaj.pojazd"
local cmd2="akceptuj"
local sprzedazPojazdu={}
marker2=nil
local timer=nil

local pozycjeMarkerowv2={
    -- Opis nad markeremx,y,zintdim
    {"Gie?da\nSprzeda? pojazd?w"2169.531416.6110.82},
}

for i,v in pairs(pozycjeMarkerowv2) do
    mkr=createMarker(v[2], v[3], v[4]-0.90"cylinder"22551111125)
    setElementDimension(mkr2v[6] or 0)
    setElementInterior(mkr2v[5] or 0)
    
    marker2=mkr
    
    local t=createElement("text")
    setElementData(t,"name",v[1])
    setElementPosition(t,v[2],v[3],v[4])
    setElementDimension(tv[6] or 0)
    setElementInterior(tv[5] or 0)
end


function checkVehiclePlayer(plr)
    -- Pobieramy tabeli nast?pnie zwracamy j?
    local result=exports["pystories-db"]:getRekord("SELECT * FROM pystories_vehicles")
    local number=0
    -- Uruchamiamy p?tlspradzaj?cpojazdy z bazy danych i
    -- por?wnujemy w?a?ciciela z UID osoby kt?ra chce zakupi?
    for i,v in ipairs(result) do
        if result[1].ownedPlayer == getElementData(plr,"player:uid"then
            number=number+1
        end
    end
    -- Zwracamy ilo?? pojazd?w gracza je?eli nie ma zwr?ci
    -- mu false.
    return number
end

local function pokazOperacje(plr)
    if not sprzedazPojazdu[plrthen return end
    local veh=sprzedazPojazdu[plr][3] -- sprawdzanie tablicy
    outputChatBox("* Otrzyma?e?/a? ofert? sprzeda?y pojazdu "..getVehicleNameFromModel(getVehicleModel(veh)).." za cen? "..sprzedazPojazdu[plr][4], plr2552550)
    outputChatBox("* ID: "..getElementData(veh,"vehicle:id").." | Przebieg: "..getElementData(veh,"vehicle:mileage")..""plr2552550)
    outputChatBox("* Aby potwierdzi? zakup prosz? wpisa? /akceptuj, masz 20 sekund"plr2552550)
    timer=setTimer(function()
        sprzedazPojazdu[plr]=nil
        outputChatBox("* Transakcja zosta?a anulowana."plr25500)
        removeCommandHandler("akceptuj"akceptujTransakcje) -- usuwanie komendy
    end200001)
    addCommandHandler("akceptuj"akceptujTransakcje) -- tworzenie komendy
end

function akceptujTransakcje(plr,cmd)
    if not sprzedazPojazdu[plrthen return end
    local veh=sprzedazPojazdu[plr][3]
    local cost=sprzedazPojazdu[plr][4]
    local target=sprzedazPojazdu[plr][1]
    if cost 0 then
        outputChatBox("* Cena jest nieprawid?owa."plr)
        return
    end
    if tonumber(cost) > getPlayerMoney(plrthen
        outputChatBox("* Nie posiadasz tyle got?wki."plr)
        return
    end
    givePlayerMoney(targetcost)
    takePlayerMoney(plrcost)
    killTimer(timer)
    outputChatBox("* Sprzeda? przeprowadzona pomy?lnie."plr)
    outputChatBox("* Sprzeda? przeprowadzona pomy?lnie."target)
    removeCommandHandler("akceptuj"akceptujTransakcje) -- usuwanie komendy
    wykonajZapytanie(veh,plr) -- do bazy danych ustawiamy od razu
end

function wykonajZapytanie(veh,plr)
    setElementData(veh,"vehicle:ownedGroup"0)
    setElementData(veh,"vehicle:ownedFaction"0)
    setElementData(veh,"vehicle:ownedPlayer",getElementData(plr,"player:uid"))
    exports["pystories-db"]:setRekord("UPDATE pystories-vehicles SET ownedPlayer=? AND ownedGroup=0 AND ownedFaction=0 WHERE id=?"getElementData(plr,"player:uid"), getElementData(veh,"vehicle:id"))
end

addCommandHandler(cmd, function(plr,_,cel,id,cost)
    if not isElementWithinMarker(plr,marker2then
        outputChatBox("* Nie jeste? w miejscu przeznaczonym do tego."plr25500)
        return
    end
    costt=tonumber(cost)
    if not cel or not costt then
        outputChatBox("* U?ycie: /sprzedaj.pojazd <nick/ID> <id pojazdu> <cena>"plr)
        return
    end
    local target=exports["pystories-core"]:findPlayer(plr,cel)
    if not target then
        outputChatBox("* Nie znaleziono podanego gracza."plr25500)
        return
    end
    if not isElementWithinMarker(target,marker2then
        outputChatBox("* Gracz nie jest w miejscu przeznaczonym do tego."plr25500)
        return
    end
    if tonumber(costt) < 0 then
        outputChatBox("* Poda?e? nieprawid?ow? warto??."plr25500)
        return
    end
    local result=exports["pystories-db"]:getRekord("SELECT * FROM pystories-vehicles WHERE id=? AND parking=1 LIMIT 1;"id)
    if result and #result > 0 then
        outputChatBox("* Pojazd znajduje na parkingu, nie mo?esz go sprzeda?."plr25500)
        return
    end
    for _,vehicle in ipairs(getElementsByType("vehicle")) do
        if tonumber(getElementData(vehicle,"vehicle:id")) == tonumber(idthen
            if tonumber(getElementData(vehicle,"vehicle:ownedPlayer")) ~= tonumber(getElementData(plr,"player:uid")) then
                outputChatBox("* Nie jeste? w?a?cicielem pojazdu."plr25500)
                return
            end
            sprzedazPojazdu[target]={plr,target,vehicle,costt}
        end
    end
    -- Warunek sprawdzaj?ca ile gracz ma pojazd?wje?eli bedzie mia?
    -- wi?cej niLIMIT na g?rze to wy?wietli mu sikomunikat.
    if checkVehiclePlayer(target) and checkVehiclePlayer(target) >= LIMIT then
        outputChatBox("* Maksymalnie ten gracz mo?e mie?: "..LIMIT.." pojazd?w"plr25500)
        return
    end
    pokazOperacje(target)
    outputChatBox("* Pomy?lnie wys?ano ofert? o sprzeda? pojazdu."plr)
end)

addEventHandler("onMarkerHit"marker2, function(el,md)
    outputChatBox("* Wpisz /sprzedaj.pojazd <nick/ID> <id pojazdu> <cena> "el)
end)


Teraz sprawd?, gdy? zrobi?em b??d w kodzie.

Podpis
GG:75080675
- ✔
- ✔
- ✔
- ✔

Aktualny projekt: BRAK
Postaw piwo autorowi tego posta
 

 
Tagi: gielda :: nie :: dziala
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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