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

Wysłany: 2018-12-02, 10:29


Pyrek24







Wiek: 25
Na forum: 3438 dni
Posty: 546
Nick w MP: Pyrek

Piwa: 10

Respekt: 50

Witam ot?? mam kod na elektryki i chcia?ym o pomoc jak to przerobi? na powi?kszane baki pr?bowa?em, doda? sam, stworzy? zapisy w sql "bak" oraz element daty, lecz nie ogarniam, wi?c prosi? bym o pomoc w przerobieniu elektryk?w !
kod

c_paliwo
--[[
    ResourceOURGame
    DevelopersSplit <split.programista@gmail.com>
    Copyright <split.programista@gmail.com2015-2016
    You have no right to use this code without my permission.
]]

-- Kod odpowiadaj?cy za odejmowanie paliwa oraz dodawanie paliwa
-- Wszelkie inne rzeczy sw systemie pojazd?// Split
local time=getTickCount()
local isBike={[509]=true,[481]=true,[510]=true}

elektrytki = {
[507] = true,
[559] = true,
}
function isEventHandlerAddedsEventNamepElementAttachedTofunc )
    if 
        typesEventName ) == 'string' and 
        isElementpElementAttachedTo ) and 
        typefunc ) == 'function' 
    then
        local aAttachedFunctions getEventHandlerssEventNamepElementAttachedTo )
        if typeaAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
            for iv in ipairsaAttachedFunctions ) do
                if == func then
                    return true
                end
            end
        end
    end
 
    return false
end
local function naliczaj(veh)
    if getTickCount()-time>5000 then
        time getTickCount()
        local fuel getElementData(veh"vehicle:fuel") or 0
        local mileage getElementData(veh,"vehicle:mileage") or 0
        local vx,vy,vz getElementVelocity(veh)
        local spd=((vx^vy^vz^2)^(0.5)/2)
        if spd>0 then
            if not elektrytki[getElementModel(veh)] then
            fuel fuel-((spd*1.75)/3)
            elseif elektrytki[getElementModel(veh)] then
            fuel fuel-((spd*0.5)/3)
            end
            setElementData(veh"vehicle:fuel"fuel)
            mileage mileage+(spd 1.25)
            setElementData(veh"vehicle:mileage"mileage)
        end
    end
end

function rendering()
    local vehicle getPedOccupiedVehicle(localPlayer)
    if not vehicle then return end
    if isBike[getElementModel(vehicle)] then return end
    if not getVehicleEngineState(vehiclethen return end
    if getElementData(vehicle,"vehicle:fuel") and getElementData(vehicle,"vehicle:fuel") or getElementData(vehicle,"vehicle:mileage") and getElementData(vehicle,"vehicle:mileage"then
        naliczaj(vehicle)
        if getElementData(vehicle,"vehicle:fuel")<1 then
            setVehicleEngineState(vehiclefalse)
        end

    end
end
addEventHandler("onClientVehicleEnter",root,function(p)
if ~= localPlayer then return end
if isTimer(timerthen killTimer(timerend
time=getTickCount()
timer setTimer(rendering,5000,0)
end)
addEventHandler("onClientVehicleExit",root,function(p)
if ~= localPlayer then return end
if isTimer(timerthen killTimer(timerend
end)


client

local cena 250
barr guiCreateStaticImage(0.270.630.530.32"logo.png"true)    
guiSetVisible(barr,false)
bar guiCreateProgressBar(0.310.830.450.07true)  
guiSetVisible(bar,false)

label =  guiCreateLabel(0.360.850.390.03"Paliwo: 100 % | Przetrzymaj spacje aby zatankowa?"true)
guiSetVisible(label,false)
guiLabelSetColor(label0090255)
guiLabelSetHorizontalAlign(label"center"false)
guiLabelSetVerticalAlign(label"center")
local tekst string.format("%s PLN",cena)
label2 guiCreateLabel(0.430.760.070.03teksttrue)
local font0_minus guiCreateFont(":ogrpg-gui/minus.ttf"16)
guiSetVisible(label2,false)
guiSetFont(label2font0_minus)
guiLabelSetColor(label23223222)
guiLabelSetHorizontalAlign(label2"center"false)
guiLabelSetVerticalAlign(label2"center")    



stacja_ladowania = {
}
addEventHandler("onClientResourceStart"resourceRoot,
    function()
        stacja_ladowania[1] = guiCreateButton(0.640.850.180.07"Na?aduj"true)
        local font0_def guiCreateFont(":Radio-auta/files/def.ttf"24)
        guiSetFont(stacja_ladowania[1], font0_def)
        guiSetProperty(stacja_ladowania[1], "NormalTextColour""FF443AC4")
        addEventHandler"onClientGUIClick"stacja_ladowania[1], naladowaniefalse )

        stacja_ladowania[2] = guiCreateLabel(0.540.550.340.10"Do ilu % akumulatora chcesz naladowa?"true)
        local font1_def guiCreateFont(":Radio-auta/files/def.ttf"21)
        guiSetFont(stacja_ladowania[2], font1_def)
        guiLabelSetHorizontalAlign(stacja_ladowania[2], "center"false)
        guiLabelSetVerticalAlign(stacja_ladowania[2], "center")


        stacja_ladowania[3] = guiCreateLabel(0.610.750.220.08"100%"true)
        local font2_def guiCreateFont(":Radio-auta/files/def.ttf"36)
        guiSetFont(stacja_ladowania[3], font2_def)
        guiLabelSetHorizontalAlign(stacja_ladowania[3], "center"false)
        guiLabelSetVerticalAlign(stacja_ladowania[3], "center")
        stacja_ladowania[4] = guiCreateScrollBar(82852335315truefalse)    
        for i=1,do
        guiSetVisible(stacja_ladowania[i],false)
        end
    end
)



elektrytki = {
[507] = true,
[559] = true,
}


function procenty()
if math.floor(guiScrollBarGetScrollPosition(stacja_ladowania[4])) < math.floor(getElementData(getPedOccupiedVehicle(localPlayer),"vehicle:fuel")) then
guiScrollBarSetScrollPosition(stacja_ladowania[4],getElementData(getPedOccupiedVehicle(localPlayer),"vehicle:fuel"))
end
guiSetText(stacja_ladowania[3],math.floor(guiScrollBarGetScrollPosition(stacja_ladowania[4])))
end

addEventHandler("onClientMarkerHit",resourceRoot,function(e)
    if e==localPlayer then
        if getElementType(e)=="player" then
            if getPedOccupiedVehicle(ethen
                if getElementData(getPedOccupiedVehicle(e),"vehicle:fuel"then
                    if getElementData(source,"stacja"then
                        if elektrytki[getElementModel(getPedOccupiedVehicle(e))] then outputChatBox("** To jest auto elektryczne nie mozesz go zatankowac .") return end
                        guiSetVisible(bar,true)
                        guiSetVisible(barr,true)
                        guiSetVisible(label,true)
                        guiSetVisible(label2,true)
                        guiSetText(label,"Paliwo: "..math.floor(getElementData(getPedOccupiedVehicle(e),"vehicle:fuel")).." L | Przetrzymaj spacje aby zatankowa?")
                        cena getElementData(source,"cena")
                        local tekst string.format("%s PLN",cena)
                        guiSetText(label2,tekst)
                        guiProgressBarSetProgress(bar,getElementData(getPedOccupiedVehicle(e),"vehicle:fuel"))
                    elseif getElementData(source,"stacja_elektryk"then
                        if getVehicleController(getPedOccupiedVehicle(e)) ~= localPlayer then return end
                        if not elektrytki[getElementModel(getPedOccupiedVehicle(e))] then outputChatBox("** Twoje auto nie jest elektryczne! ") return end
                        guiScrollBarSetScrollPosition(stacja_ladowania[4],getElementData(getPedOccupiedVehicle(e),"vehicle:fuel"))
                        timer setTimer(procenty,100,0)
                        for i=1,do
                            guiSetVisible(stacja_ladowania[i],true)
                        end
                    end
                end
            end
        end
    end
end)

function timertankuj()
if getPedOccupiedVehicle(localPlayerthen
if getElementData(getPedOccupiedVehicle(localPlayer),"vehicle:fuel"then
if getKeyState"space" ) == true then
tankuj()
end
end
end
end
setTimer(timertankuj1150)

addEventHandler("onClientMarkerLeave",resourceRoot,function(e)
    if e==localPlayer then
        if getElementData(source,"stacja"then
            guiSetVisible(bar,false)
            guiSetVisible(barr,false)
            guiSetVisible(label,false)
            guiSetVisible(label2,false)
        elseif getElementData(source,"stacja_elektryk"then
            if isTimer(timerthen killTimer(timerend
            for i=1,do
            guiSetVisible(stacja_ladowania[i],false)
            end
        end
    end
end)

function tankuj()
    if getPedOccupiedVehicle(localPlayerthen
        if getElementData(getPedOccupiedVehicle(localPlayer),"vehicle:fuel")>= 100 then return end
        triggerServerEvent("TANKUJ",localPlayer)
    end
end


function naladowanie button )
    if button == "left" then
                if isTimer(timerthen killTimer(timerend
        triggerServerEvent("NALADOWANIE",root,math.floor(guiScrollBarGetScrollPosition(stacja_ladowania[4])))
    end
end

addEvent("TANKUJ",true)
addEventHandler("TANKUJ",root,function()
    if source==localPlayer then
        local fuel=getElementData(getPedOccupiedVehicle(source),"vehicle:fuel")
        setElementData(getPedOccupiedVehicle(source),"vehicle:fuel",fuel+1)
        guiSetText(label,"Paliwo: "..math.floor(getElementData(getPedOccupiedVehicle(source),"vehicle:fuel")).." L | Przetrzymaj spacje aby zatankowa?")
        guiProgressBarSetProgress(bar,getElementData(getPedOccupiedVehicle(source),"vehicle:fuel"))
    end
end)


server

elektrytki = {
[507] = true,
[559] = true,
}
local aktualnie_laduje = {}
cena math.random(100000,120000)
function cenas(x)
if not x then x math.random(100000,120000end
cena x
for i,m in pairs(getElementsByType("marker",resourceRoot)) do
if getElementData(m,"stacja"then
setElementData(m,"cena",cena)
local text getElementData(m,"text")
setElementData(text,"name","Cena za paliwo: "..cena.."$")
end
end
--outputChatBox("*[INFORMACJA] Nowa cena paliwa..",root,255,0,0)
end
sync_czas 1000*60*10 -- co 10 minut zmiana ceny
setTimer(cenas,sync_czas,0)
local stacje={
    {-2023.76157.4628.84},
    {-1557.34394.957.19},
{-1296.48, -472.6114.15},
}
for _,v in ipairs(stacje)do
    local marker=createMarker(v[1],v[2],v[3]-0.9,"cylinder",3,0,200,0)
    setElementData(marker,"stacja",true)
    local blipStacji =createBlipAttachedTo marker56 )
    setBlipVisibleDistance(blipStacji400)
    local text createElement('text')
    setElementData(text,"name","Cena za paliwo: "..cena.."$")
    setElementPosition(text,v[1],v[2],v[3]+0.3)
    setElementData(marker,"text",text)
    setElementData(marker,"cena",cena)
    mkr=marker
end

addEvent("NALADOWANIE",true)
addEventHandler("NALADOWANIE",root,function(procent)
    local veh getPedOccupiedVehicle(client)
    if not veh then return end
    if not procent then return end
    if not elektrytki[getElementModel(veh)] then outputChatBox("** Twoje auto nie jest elektryczne! ",client) return end
    local p getElementData(veh,"vehicle:fuel")
    if procent p then  outputChatBox("** Chcesz sie pozbyc bateri?! ",client) return end
    local procent2 = (procent getElementData(veh,"vehicle:fuel"))
    local czas procent2 60000 10
    if czas 50 then outputChatBox("* Masz naladowane w pelni auto!",client) return end
    setElementData(veh,"ladowany",true)
    local opis getElementData(veh,"vehicle:desc") or ""
    setElementFrozen(veh,true)
    setVehicleLocked(veh,true)
    setElementData(veh,"vehicle:desc","?aduje si?.....")
    aktualnie_laduje[veh] = setTimer(function()
    if isElement(vehthen
    setElementData(veh,"vehicle:fuel",procent)
    setVehicleLocked(veh,false)
    setElementData(veh,"ladowany",false)
    setElementData(veh,"vehicle:desc",opis)
    end
    end,czas,1)
    local czas tonumber(czas)/60000
    removePedFromVehicle(client)
    local x,y,=getElementPosition(veh)
    setElementPosition(client,x,y-1.25,z)
    czas string.format("%0.2f",czas)
    outputChatBox("** Pozosta?y czas do naladowania to "..czas.." minut",client,0,255,0)
end)

addEventHandler("onVehicleStartEnter",root,function(p)
 if isTimer(aktualnie_laduje[source]) then
    local czas,_,_getTimerDetails(aktualnie_laduje[source])
    czas tonumber(czas)/600000
    czas string.format("%0.2f",czas)
    outputChatBox("** Pozosta?y czas do naladowania to "..czas.." minut",p,0,255,0)
 end
end)

addEvent("TANKUJ",true)
addEventHandler("TANKUJ",root,function()
    if getPlayerMoney(source)>= cena then
        for i,m in pairs(getElementsByType("marker",resourceRoot)) do
            if getElementData(m,"stacja"then
                if isElementWithinMarker(source,mthen
                takePlayerMoney(source,cena)
                triggerClientEvent("TANKUJ",source)
                end
            end
        end
    end
end)

function zgasSilnik()
    for i,v in ipairs(getElementsByType("vehicle")) do
    local data getElementData(v"vehicle:fuel")
        if data then
        if tonumber(data) < 0 then
            setVehicleEngineState(vfalse)
        end
end
    end
end
setTimer(zgasSilnik10000)


local stacje_elektryk={
{-1557.87389.987.19},
}

for _,v in ipairs(stacje_elektryk)do
    local marker=createMarker(v[1],v[2],v[3]-0.9,"cylinder",3,0,200,0)
    setElementData(marker,"stacja_elektryk",true)
    local t createElement('text')
    setElementData(t,'name',"Stacja Szybkiego ?adowania")
    setElementPosition(t,v[1],v[2],v[3])
    attachElements(t,marker)
    local blipStacji =createBlipAttachedTo marker)
    setBlipVisibleDistance(blipStacji400)
end

addEventHandler("ustawpaliwo",function(plr,cmd,cenar)

if not cenar then cenas() return end
local cenar tonumber(cenar)
local cenar math.floor(cenar)
--if cenar 1 then cenas() return end
cenas(cenar)
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 12:04


kuba43







Wiek: 45
Na forum: 3225 dni
Posty: 166
Nick w MP: definitly

Piwa: 17

Respekt: 30,5

w tabeli z pojazdami dodajesz kolumne kt?ra ma domy?lna warto?c iles tam litr?w i wykorzystujesz
Więcej informacji znajdziesz w Wikipedii MTA:

dbExec
kt?ra zmieniasz domyslna warto?? na wy?sza potem robisz skrypt z pobieraniem maxymalnego paliwa i ??czysz to z skryptem od stacji.

Podpis
„(…) wystarczy, że odpowiesz sobie na jedno zajebiście, ale to zajebiście, ważne pytanie: co lubię w życiu robić. A potem zacznij to robić.”.
Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-12-02, 12:35


Pyrek24







Wiek: 25
Na forum: 3438 dni
Posty: 546
Nick w MP: Pyrek

Piwa: 10

Respekt: 50

Dzi?ki, lecz zbytnio nie wiem jak si? za to zabra?, jaka? podpowied??

Podpis
amta
Postaw piwo autorowi tego posta
 

 
Tagi: powiekszony :: bak
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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