Wysłany: 2018-06-25, 17:48
Kulegg
Wiek: 46 Na forum: 3125 dni Posty: 283
Piwa : 20
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 kupi ? trzy pojazdy
local cmd = "sprzedaj.pojazd"
local cmd2 = "akceptuj"
local sprzedazPojazdu ={}
marker2 = nil
local timer = nil
local pozycjeMarkerowv2 ={
-- Opis nad markerem , x , y , z , int , dim
{ "Gie?da\nSprzeda? pojazd?w" , 2169.53 , 1416.61 , 10.82 },
}
for i , v in pairs ( pozycjeMarkerowv2 ) do
mkr = createMarker ( v [ 2 ], v [ 3 ], v [ 4 ]- 0.90 , "cylinder" , 2 , 255 , 11 , 11 , 125 )
setElementDimension ( mkr2 , v [ 6 ] or 0 )
setElementInterior ( mkr2 , v [ 5 ] or 0 )
marker2 = mkr
local t = createElement ( "text" )
setElementData ( t , "name" , v [ 1 ])
setElementPosition ( t , v [ 2 ], v [ 3 ], v [ 4 ])
setElementDimension ( t , v [ 6 ] or 0 )
setElementInterior ( t , v [ 5 ] or 0 )
end
function checkVehiclePlayer ( plr )
-- Pobieramy tabel ? i nast ? pnie zwracamy j ?
local result = exports [ "og-db" ]: getRekord ( "SELECT * FROM og_vehicles" )
local number = 0
-- Uruchamiamy p ? tl ? spradzaj ? c ? pojazdy 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 [ plr ] then 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 ], plr , 255 , 255 , 0 )
outputChatBox ( "* ID: " .. getElementData ( veh , "vehicle:id" ).. " | Przebieg: " .. getElementData ( veh , "vehicle:mileage" ).. "" , plr , 255 , 255 , 0 )
outputChatBox ( "* Aby potwierdzi? zakup prosz? wpisa? /akceptuj, masz 20 sekund" , plr , 255 , 255 , 0 )
timer = setTimer (function()
sprzedazPojazdu [ plr ]= nil
outputChatBox ( "* Transakcja zosta?a anulowana." , plr , 255 , 0 , 0 )
removeCommandHandler ( "akceptuj" , akceptujTransakcje ) -- usuwanie komendy
end , 20000 , 1 )
addCommandHandler ( "akceptuj" , akceptujTransakcje ) -- tworzenie komendy
end
function akceptujTransakcje ( plr , cmd )
if not sprzedazPojazdu [ plr ] then 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 ( plr ) then
outputChatBox ( "* Nie posiadasz tyle got?wki." , plr )
return
end
givePlayerMoney ( target , cost )
takePlayerMoney ( plr , cost )
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 , marker2 ) then
outputChatBox ( "* Nie jeste? w miejscu przeznaczonym do tego." , plr , 255 , 0 , 0 )
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." , plr , 255 , 0 , 0 )
return
end
if not isElementWithinMarker ( target , marker2 ) then
outputChatBox ( "* Gracz nie jest w miejscu przeznaczonym do tego." , plr , 255 , 0 , 0 )
return
end
if tonumber ( costt ) < 0 then
outputChatBox ( "* Poda?e? nieprawid?ow? warto??." , plr , 255 , 0 , 0 )
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?." , plr , 255 , 0 , 0 )
return
end
for _ , vehicle in ipairs ( getElementsByType ( "vehicle" )) do
if tonumber ( getElementData ( vehicle , "vehicle:id" )) == tonumber ( id ) then
if tonumber ( getElementData ( vehicle , "vehicle:ownedPlayer" )) ~= tonumber ( getElementData ( plr , "player:uid" )) then
outputChatBox ( "* Nie jeste? w?a?cicielem pojazdu." , plr , 255 , 0 , 0 )
return
end
sprzedazPojazdu [ target ]={ plr , target , vehicle , costt }
end
end
-- Warunek sprawdzaj ? ca ile gracz ma pojazd ? w , je ? eli bedzie mia ?
-- wi ? cej ni ? LIMIT na g ? rze to wy ? wietli mu si ? komunikat .
if checkVehiclePlayer ( target ) and checkVehiclePlayer ( target ) >= LIMIT then
outputChatBox ( "* Maksymalnie ten gracz mo?e mie?: " .. LIMIT .. " pojazd?w" , plr , 255 , 0 , 0 )
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 )
Wysłany: 2018-06-25, 18:04
PatryKK.
Emeryt LUA
Wiek: 26 Na forum: 3061 dni Posty: 1060
Nick w MP: PatryKK.
Piwa : 2322
Dlatego, ?e musisz pod??czy? pod swoj? baz? danych odpowiednie warto?ci.
Podpis
GG:75080675
- ✔
- ✔
- ✔
- ✔
Aktualny projekt: BRAK
Wysłany: 2018-06-25, 18:07
Kulegg
Wiek: 46 Na forum: 3125 dni Posty: 283
Piwa : 20
Wysłany: 2018-06-25, 18:08
PatryKK.
Emeryt LUA
Wiek: 26 Na forum: 3061 dni Posty: 1060
Nick w MP: PatryKK.
Piwa : 2322
Musisz si? nauczy? sam robic, bo got?wce to nie wszystko.
local LIMIT = 300 -- tylko gracz mo ? e kupi ? trzy pojazdy
local cmd = "sprzedaj.pojazd"
local cmd2 = "akceptuj"
local sprzedazPojazdu ={}
marker2 = nil
local timer = nil
local pozycjeMarkerowv2 ={
-- Opis nad markerem , x , y , z , int , dim
{ "Gie?da\nSprzeda? pojazd?w" , 2169.53 , 1416.61 , 10.82 },
}
for i , v in pairs ( pozycjeMarkerowv2 ) do
mkr = createMarker ( v [ 2 ], v [ 3 ], v [ 4 ]- 0.90 , "cylinder" , 2 , 255 , 11 , 11 , 125 )
setElementDimension ( mkr2 , v [ 6 ] or 0 )
setElementInterior ( mkr2 , v [ 5 ] or 0 )
marker2 = mkr
local t = createElement ( "text" )
setElementData ( t , "name" , v [ 1 ])
setElementPosition ( t , v [ 2 ], v [ 3 ], v [ 4 ])
setElementDimension ( t , v [ 6 ] or 0 )
setElementInterior ( t , v [ 5 ] or 0 )
end
function checkVehiclePlayer ( plr )
-- Pobieramy tabel ? i nast ? pnie zwracamy j ?
local result = exports [ "pystories-db" ]: getRekord ( "SELECT * FROM pystories_vehicles" )
local number = 0
-- Uruchamiamy p ? tl ? spradzaj ? c ? pojazdy 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 [ plr ] then 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 ], plr , 255 , 255 , 0 )
outputChatBox ( "* ID: " .. getElementData ( veh , "vehicle:id" ).. " | Przebieg: " .. getElementData ( veh , "vehicle:mileage" ).. "" , plr , 255 , 255 , 0 )
outputChatBox ( "* Aby potwierdzi? zakup prosz? wpisa? /akceptuj, masz 20 sekund" , plr , 255 , 255 , 0 )
timer = setTimer (function()
sprzedazPojazdu [ plr ]= nil
outputChatBox ( "* Transakcja zosta?a anulowana." , plr , 255 , 0 , 0 )
removeCommandHandler ( "akceptuj" , akceptujTransakcje ) -- usuwanie komendy
end , 20000 , 1 )
addCommandHandler ( "akceptuj" , akceptujTransakcje ) -- tworzenie komendy
end
function akceptujTransakcje ( plr , cmd )
if not sprzedazPojazdu [ plr ] then 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 ( plr ) then
outputChatBox ( "* Nie posiadasz tyle got?wki." , plr )
return
end
givePlayerMoney ( target , cost )
takePlayerMoney ( plr , cost )
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 , marker2 ) then
outputChatBox ( "* Nie jeste? w miejscu przeznaczonym do tego." , plr , 255 , 0 , 0 )
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." , plr , 255 , 0 , 0 )
return
end
if not isElementWithinMarker ( target , marker2 ) then
outputChatBox ( "* Gracz nie jest w miejscu przeznaczonym do tego." , plr , 255 , 0 , 0 )
return
end
if tonumber ( costt ) < 0 then
outputChatBox ( "* Poda?e? nieprawid?ow? warto??." , plr , 255 , 0 , 0 )
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?." , plr , 255 , 0 , 0 )
return
end
for _ , vehicle in ipairs ( getElementsByType ( "vehicle" )) do
if tonumber ( getElementData ( vehicle , "vehicle:id" )) == tonumber ( id ) then
if tonumber ( getElementData ( vehicle , "vehicle:ownedPlayer" )) ~= tonumber ( getElementData ( plr , "player:uid" )) then
outputChatBox ( "* Nie jeste? w?a?cicielem pojazdu." , plr , 255 , 0 , 0 )
return
end
sprzedazPojazdu [ target ]={ plr , target , vehicle , costt }
end
end
-- Warunek sprawdzaj ? ca ile gracz ma pojazd ? w , je ? eli bedzie mia ?
-- wi ? cej ni ? LIMIT na g ? rze to wy ? wietli mu si ? komunikat .
if checkVehiclePlayer ( target ) and checkVehiclePlayer ( target ) >= LIMIT then
outputChatBox ( "* Maksymalnie ten gracz mo?e mie?: " .. LIMIT .. " pojazd?w" , plr , 255 , 0 , 0 )
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
Tagi: gielda :: nie :: dziala
Anonymous
Na forum: 245 dni
Posty: 1
Anonymous Koniecznie zajrzyj na: