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

Wysłany: 2018-03-05, 16:45


Yami

Mapper / Uczeń LUA






Wiek: 25
Na forum: 3059 dni
Posty: 379

Piwa: 97

Respekt: 235
Respekt: 235Respekt: 235

Siema
Da rade nadawa? paintjoby w bazie danych? Bo jak dam je tak na serwerze i zrestartuje skrypt na pojazdy to PaintJob si? usuwa.
Nazwa skryptu: lss-vehicles
Z G?ry Dzi?ki

Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-03-05, 16:50


Ciastuuś

Truck soon...






Wiek: 26
Na forum: 3071 dni
Posty: 799
Nick w MP: Ciastuuś

Piwa: 4297

Respekt: 640
Respekt: 640Respekt: 640

"ReMiK1337" napisał/a:

Siema
Da rade nadawa? paintjoby w bazie danych? Bo jak dam je tak na serwerze i zrestartuje skrypt na pojazdy to PaintJob si? usuwa.
Nazwa skryptu: lss-vehicles
Z G?ry Dzi?ki


Musisz utworzy? odczyt oraz zapis takowych paintjob?w

Podpis
Truck soon...
Postaw piwo autorowi tego posta
 

 
Wysłany: 2018-03-07, 20:36


Yami

Mapper / Uczeń LUA






Wiek: 25
Na forum: 3059 dni
Posty: 379

Piwa: 97

Respekt: 235
Respekt: 235Respekt: 235

Niestety od tych dw?ch dni pr?bowa?em co? zrobi?, na r??ne sposoby lecz nie da?em rady tego zrobi?
Je?li mia?by kto? ochote pom?c to daje kod do lss-vehicles

local function veh_create(v)
--    outputDebugString("Tworzenie " .. v.id)
    v.loc=split(v.loc,",")
    v.rot=split(v.rot,",")
    local pojazd=createVehicle(v.modelv.loc[1],v.loc[2],v.loc[3],v.rot[1],v.rot[2],v.rot[3],v.tablica .. string.format("%06s",v.id)) -- tablica nie dziala?

    if getElementModel(pojazd)==439 then setVehicleVariant(pojazd1255end
    if getElementModel(pojazd)==555 then setVehicleVariant(pojazd0255end

    if (tonumber(v.d)>0then
      setElementDimension(pojazdtonumber(v.d))
    end
    if (tonumber(v.i)>0then
      setElementInterior(pojazdtonumber(v.i))
    end

    if (v.special and type(v.special)=="string" and string.len(v.special)>1then
        setElementData(pojazd,"special",v.special)
    end

    if (tonumber(v.variant)) then
        setVehicleVariant(pojazdv.variant255)
    end


    setVehicleDamageProof(pojazdtrue)
    v.hp=tonumber(v.hp)
    if (v.hp<301then v.hp=301 end
    setElementHealth(pojazd,v.hp)
    setElementData(pojazd,"dbid",v.id)



    setElementData(pojazd,"paliwo", { tonumber(v.paliwo) or 25tonumber(v.bak) or 25})

    if (tonumber(v.hp)>and tonumber(v.model)~=510 and tonumber(v.model)~=509 and tonumber(v.model)~=481then
        setVehicleLocked(pojazdtonumber(v.locked)>0)
        setElementFrozen(pojazdtonumber(v.frozen)>0)
    end

    if (v.headlightcolor and type(v.headlightcolor)=="string"then
        v.headlightcolor=split(v.headlightcolor,",")
--        srun setVehicleHeadLightColor(getPedOccupiedVehicle(getPlayerFromName("Shawn_Hanks")), 100,255,255)
        setVehicleHeadLightColor(pojazdtonumber(v.headlightcolor[1]) or 255tonumber(v.headlightcolor[2]) or 255 tonumber(v.headlightcolor[3]) or 255)
    end

    if (v.owning_faction and (type(v.owning_faction)=="string" or type(v.owning_faction)=="number")) then
        setElementData(pojazd"owning_faction"tonumber(v.owning_faction))
    end
    if (v.owning_co and (type(v.owning_co)=="string" or type(v.owning_co)=="number")) then
        setElementData(pojazd"owning_co"tonumber(v.owning_co))
    end

    if (v.fprint1then    setElementData(pojazd,"fingerprint:1"v.fprint1 or "-")    end
    if (v.fprint2then    setElementData(pojazd,"fingerprint:2"v.fprint2 or "-")    end
    if (v.fprint3then    setElementData(pojazd,"fingerprint:3"v.fprint3 or "-")    end
    if (v.fprint4then    setElementData(pojazd,"fingerprint:4"v.fprint4 or "-")    end
    if (v.fprint5then    setElementData(pojazd,"fingerprint:5"v.fprint5 or "-")    end
    if (v.cb and tonumber(v.cb)>0then
        setElementData(pojazd,"cb"true)
    end
    if (v.kogut and tonumber(v.kogut)>0then
        setElementData(pojazd,"kogut"true)
    end

    if (v.neony and tonumber(v.neony)>0then
        setElementData(pojazd,"neony"tonumber(v.neony))
    end


    if (v.damageproof and tonumber(v.damageproof)==1then
        setElementData(pojazd,"damageproof"true)
    end


    if (v.gps and tonumber(v.gps)>0then
        setElementData(pojazd,"gps"truefalse)
    end

    setElementData(pojazd,"przebieg"tonumber(v.przebieg) or 0)
    v.wheelstates=split(v.wheelstates,",")
    setVehicleWheelStates(pojazdunpack(v.wheelstates))
    if (v.panelstates~="0,0,0,0,0,0,0"then
        v.panelstates=split(v.panelstates,",")
        for i,v in ipairs(v.panelstates) do
          setVehiclePanelState(pojazd,i-1tonumber(v))
        end
    else
        v.panelstates=split(v.panelstates,",")
    end
    if (v.upgrades and type(v.upgrades)=="string"then
        v.upgrades=split(v.upgrades,",")
        for i,v in ipairs(v.upgrades) do
            addVehicleUpgrade(pojazdtonumber(v))
        end
    end

    if (v.opis and type(v.opis)=="string"then
        setElementData(pojazd,"opis"v.opis)
    end

    setVehicleColor pojazdmath.floor(v.c1/65536), math.floor(v.c1/256%256), v.c1%256math.floor(v.c2/65536), math.floor(v.c2/256%256), v.c2%256math.floor(v.c3/65536), math.floor(v.c3/256%256), v.c3%256math.floor(v.c4/65536), math.floor(v.c4/256%256), v.c4%256)
    setVehicleEngineState pojazdfalse )
end

function veh_reload(id)
    if (not idthen return end
    -- reload bez save!
    for i,v in ipairs(getElementsByType("vehicle")) do
    local dbid=getElementData(v,"dbid")
    if dbid and tonumber(dbid)==tonumber(idthen

            local zneony=getElementData(v,"zneony")
            if (zneony and type(zneony)=="table"then
                destroyElement(zneony[1])
                destroyElement(zneony[2])
            end


        destroyElement(v)
    end
    end
    veh_load(id)
end

function veh_load(id)
    local pojazd=exports.DB:pobierzWyniki("select id,przebieg,model,loc,d,i,rot,locked,frozen,tablica,hp,fprint1,fprint2,fprint3,fprint4,fprint5,owning_faction,owning_co,c1,c2,c3,c4,headlightcolor,cb,gps,kogut,neony,upgrades,wheelstates,panelstates,opis,paliwo,bak,special,damageproof from lss_vehicles WHERE przechowalnia=0 AND id="..tonumber(id))
    if pojazd and pojazd.id then
        veh_create(pojazd)
    end
end

function veh_init()
    local pojazdy=exports.DB:pobierzTabeleWynikow("select id,przebieg,model,loc,d,i,rot,locked,frozen,tablica,hp,fprint1,fprint2,fprint3,fprint4,fprint5,owning_faction,owning_co,c1,c2,c3,c4,headlightcolor,cb,gps,kogut,neony,upgrades,wheelstates,panelstates,opis,paliwo,bak,special,damageproof,variant from lss_vehicles WHERE przechowalnia=0")
    for i,v in ipairs(pojazdy) do
    veh_create(v)
--[[
    if (tonumber(v.model)==578then
        createSpecialVehicle(pojazd)
    end
]]--
    end
end

-- zapisujemy stan pojazdu do bazy danych
function veh_save(vehicle)
    local dbid=getElementData(vehicle"dbid")
    if (not dbidthen
    return
    end
    local x,y,z=getElementPosition(vehicle)
    local rx,ry,rz=getElementRotation(vehicle)
    local hp=getElementHealth(vehicle)
    local fp1=getElementData(vehicle,"fingerprint:1")        if (not fp1 or type(fp1)~="string"then fp1="-" end
    local fp2=getElementData(vehicle,"fingerprint:2")        if (not fp1 or type(fp2)~="string"then fp2="-" end
    local fp3=getElementData(vehicle,"fingerprint:3")        if (not fp1 or type(fp3)~="string"then fp3="-" end
    local fp4=getElementData(vehicle,"fingerprint:4")        if (not fp1 or type(fp4)~="string"then fp4="-" end
    local fp5=getElementData(vehicle,"fingerprint:5")        if (not fp1 or type(fp5)~="string"then fp5="-" end
    local pp=getElementData(vehicle,"paliwo")
    local paliwo=25
    local bak=25
    if (ppthen
        paliwo=tonumber(pp[1]) or 25
        bak=tonumber(pp[2]) or 25
    end
    local wheelstates=table.concat({getVehicleWheelStates(vehicle)},",")
    local panelstates={}
    for i=0,do
      table.insert(panelstatesgetVehiclePanelState(vehicle,i))
    end
    panelstates=table.concat(panelstates,",")
    local przebieg=getElementData(vehicle,"przebieg") or 0
    local locked=isVehicleLocked(vehicle) and or 0
    local frozenisElementFrozen(vehicle) and or 0
    local vm=getElementModel(vehicle)
    if (vm==510 or vm==509 or vm==481then    -- rowery
        locked=0
        frozen=0
    end
    local c11,c12,c13c21,c22,c23c31,c32,c33c41,c42,c43 getVehicleColor(vehicle,true)
    local opis=getElementData(vehicle,"opis")
    if (opis and string.len(opis)>=3then
        opis='"' .. exports.DB:esc(opis) .. '"'
    else
        opis="NULL"
    end
    local vehUpgrades=getVehicleUpgrades(vehicle)
    if not vehUpgrades then vehUpgrades={} end
    local upgrades=exports.DB:esc(table.concat(vehUpgrades,","))

    local query=string.format("UPDATE lss_vehicles SET przebieg='%.2f',upgrades='%s',loc='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',hp=%d,locked=%d,frozen=%d,fprint1='%s',fprint2='%s',fprint3='%s',fprint4='%s',fprint5='%s',c1=%d,c2=%d,c3=%d,c4=%d,wheelstates='%s',panelstates='%s',opis=%s,paliwo=%.3f,bak=%d WHERE id=%d LIMIT 1",
    przebieg,upgrades,x,y,z,rx,ry,rz,hp,lockedfrozen,
    exports.DB:esc(fp1), exports.DB:esc(fp2), exports.DB:esc(fp3), exports.DB:esc(fp4), exports.DB:esc(fp5),
    c13+c12*256+c11*256*256c23+c22*256+c21*256*256c33+c32*256+c31*256*256c43+c42*256+c41*256*256,
    exports.DB:esc(wheelstates), exports.DB:esc(panelstates),
    opis,
    paliwo,bak,
    dbid)
    exports.DB:zapytanie(query)
end

function veh_saveall()
    local pojazdy=getElementsByType("vehicle",resourceRoot)
    for i,v in ipairs(pojazdy) do
    veh_save(v)
    end
end

function createVehicleEx(model,x,y,z,rx,ry,rz)
    local pojazd=createVehicle(modelx,y,z,rx,ry,rz) -- tablica nie dziala?
    setVehicleDamageProof(pojazdtrue)
    local query=string.format("INSERT INTO lss_vehicles SET created=NOW(),model=%d,loc='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',locked=1"modelx,y,z,rx,ry,rz)
    exports.DB:zapytanie(query)
    local dbid=exports.DB:insertID()
    setVehicleLocked(pojazd,true)
    if (dbid and dbid>0then
    setElementData(pojazd,"dbid",dbid)
    setElementData(pojazd,"paliwo", { 0.525})
    setElementData(pojazd,"przebieg"math.random(1,50)/10)
    return dbid,pojazd
    else
    return false
    end
end

function unregisterVehicle(dbid)
    if not dbid then return false end
    local query=string.format("DELETE FROM lss_vehicles WHERE id=%d LIMIT 1"dbid)
    exports.DB:zapytanie(query)
    return true
end

function assignVehicleToOwner(vehicle,owning_player,owning_faction)
    if (not vehicle or not isElement(vehicle)) then return end
    local dbid=getElementData(vehicle,"dbid")
    if (not dbidthen return end

    if (owning_factionthen
    exports.DB:zapytanie(string.format("UPDATE lss_vehicles SET owning_faction=%d WHERE id=%d LIMIT 1"owning_factiondbid))
    setElementData(vehicle,"owning_faction"tonumber(owning_faction))
    elseif (getElementData(vehicle,"owning_faction")) then
        exports.DB:zapytanie(string.format("UPDATE lss_vehicles SET owning_faction=NULL WHERE id=%d LIMIT 1"dbid))
    removeElementData(vehicle,"owning_faction")
    end
    if (owning_playerthen
    exports.DB:zapytanie(string.format("UPDATE lss_vehicles SET owning_player=%d WHERE id=%d LIMIT 1"owning_playerdbid))
    else
        exports.DB:zapytanie(string.format("UPDATE lss_vehicles SET owning_player=NULL WHERE id=%d LIMIT 1"dbid))
    end

end

addEventHandler("onResourceStart",resourceRootveh_init)
addEventHandler("onResourceStop",resourceRootveh_saveall)

addEventHandler("onVehicleEnter"resourceRoot, function(plr,seat)
    local vm=getElementModel(source)
    if (vm==481 or vm==509 or vm==510then return end    -- rowery
    if (seat~=0then return end
    setVehicleEngineState sourcefalse )
    end)

addEventHandler("onVehicleExit"resourceRoot, function(plr,seat)
    if (seat==0then
        setVehicleEngineState sourcefalse )
        setVehicleOverrideLights(source1)
    end



    veh_save(source)
    end)

function e_setVehicleLocked(state)
    setVehicleLocked(source,state)
    if (statethen
    for i=0,do
        setVehicleDoorOpenRatio(source,i,0,1000)
    end
    end
    veh_save(source)
end
addEvent("setVehicleLocked"true)
addEventHandler("setVehicleLocked"resourceRoote_setVehicleLocked)


function e_setVehicleDoorOpenRatio(doorratiotime)
    setVehicleDoorOpenRatio(source,door,ratiotime or 1000)
end
addEvent("setVehicleDoorOpenRatio"true)
addEventHandler("setVehicleDoorOpenRatio"resourceRoote_setVehicleDoorOpenRatio)

addEvent("setVehicleEngineState"true)
addEventHandler("setVehicleEngineState"resourceRoot, function(state)
    if (statethen
        local pp=getElementData(source,"paliwo")
        if (pp and pp[2] and pp[2]>0then
            local paliwo,bak=unpack(pp)
            if (paliwo<0.01then
                local kierowca=getVehicleController(source)
                if (kierowcathen
                  setTimer(    triggerEvent5001"broadcastCaptionedEvent"kierowca"Silnik pojazdu nie mo?e odpali?."55true)
                end
                return false
            end
        end

    end
    setVehicleEngineState(source,state)
end)

addEvent("setVehicleFrozen"true)
addEventHandler("setVehicleFrozen"resourceRoot, function(state)
    -- jezeli pojazd ma przyczepeto najpierw zamrazamy tylko j?!
    local przyczepa=getVehicleTowedByVehicle(source)
    if przyczepa and state then
        detachTrailerFromVehicle(sourceprzyczepa)
        setElementFrozen(przyczepa,state)
        return
    end

    -- w przeciwnym wypadku wszystko normalnie
    setElementFrozen(source,state)
end)

-- todo spedycja
--[[
addEventHandler("onTrailerAttach"resourceRoot, function(pojazd)
--     setElementFrozen(sourcefalse)
    local kierowca=getVehicleController(pojazd)
    if kierowca then
        setElementSyncersourcekierowca)    nie dziala
    end
end)
]]--

addEventHandler("onTrailerDetach"resourceRoot, function()
--    setElementData(source,"lastDetach"math.floor(getTickCount()/1000),falsetodo
    veh_save(source)
end)




addEvent("setVehicleOverrideLights"true)
addEventHandler("setVehicleOverrideLights"resourceRoot, function(state)
    setVehicleOverrideLights(sourcestate)
    local przyczepa=getVehicleTowedByVehicle(source)
    if przyczepa then
        setVehicleOverrideLights(przyczepa,state)
    end

end)


addEventHandler("onVehicleDamage"resourceRoot, function(loss)
    local hp=getElementHealth(source)
    if (hp<5then
        setElementFrozen(source,false)
    end
end)

local function silaGraczyWPoblizuPojazdu(element)
    local x,y,z=getElementPosition(element)
    local sumaSily=0
    local cs=createColSphere(x,y,z,7)
    local gracze=getElementsWithinColShape(cs)
    destroyElement(cs)
    for i,gracz in ipairs(gracze) do
    local c=getElementData(gracz,"character")
    if (and c.energythen
        sumaSily=sumaSily+tonumber(c.energy)
    end
    end
    return sumaSily
end

addEvent("flipVehicle"true)
addEventHandler("flipVehicle"root, function(plr)
    if (getElementType(source)~="vehicle"then return end

    sila=silaGraczyWPoblizuPojazdu(source)
    if (sila<200then
    outputChatBox("(( Osoby w pobli?u pojazdu nie posiadaj? odpowiednio du?ej si?y aby go obr?ci?. ))"plr)
    outputChatBox("(( Dostepne: " .. sila .. ", wymagane: 200 ))"plr)
    triggerEvent("broadcastCaptionedEvent"plr"Osoby w pobli?u bezskutecznie pr?buj? odwr?ci? pojazd na ko?a."515true)
    return
    end

    local _,_,getElementRotation(source)
    setElementRotation(source0,0,z)
    triggerEvent("broadcastCaptionedEvent"plr"Osoby w pobli?u pojazdu odwracaj? go na ko?a."515true)
end)


local plOffsets={
  [405]={-0.5,-0.1,0.76},    -- sentinel
  [426]={-0.5, -0.10.88},    -- premier
  [525]={0, -0.51.3},    -- holownik
  [554]={001.1},    -- yosemite
  [560]={-0.500.85},    -- sultan
  [426]={-0.500.85},    -- premier
  [574]={00.451.27},    -- sweeper
--  [578]={-0.73.51.4},    -- laweta
  [602]={-0.4, -0.30.73},    -- alpha
  [552]={00.61.39},    -- Utility Van
  [579]={-0.4, -0.11.28},    -- huntley
  [408]={-0.42.71.05},    -- smieciarka
  [486]={0, -1.451.45},    -- dozer
  [411]={-0.501.2}, -- Infek
  [541]={-0.4, -0.20.66},    -- bullet
  [482]={0.350.31}, --Burek

}

-- triggerServerEvent("toggleVehiclePL"vehicle)
addEvent("toggleVehiclePL"true)
addEventHandler("toggleVehiclePL"root, function(plr)
  local kogut=getElementData(source,"kogut")
  if (type(kogut)=="userdata" and getElementType(kogut)=="object"then
    destroyElement(kogut)
    setElementData(source,"kogut"true)
--    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " zdejmuje koguta z dachu pojazdu."525true)
    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " od??cza kogut z pojazdu."525true)
    removeVehicleSirens(source)
  else
    local m getElementModel(source)
    if not plOffsets[mthen
        outputChatBox("(( zak?adanie koguta na ten model pojazdu nie jest oprogramowane, zglos to administracji ))"plr)
        return
    end
    kogut=createObject(3964,0,0,0)
    setElementData(source,"kogut"kogut)
    attachElements(kogut,source,unpack(plOffsets[m]))
--    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " zak?ada koguta na dach pojazdu."525true)
    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " za??cza kogut w poje?dzie."525true)
    addVehicleSirens(source12truetruetrue)
  end
end)

local nlOffsets={
    [411]={-1,0,-0.6},    -- infernus
    [470]={-1,0,-0.4},    -- patriot
    [541]={-0.9,0,-0.4},    -- bulelt
    [549]={-0.9,0,-0.4},    -- tampa
    [587]={-1,0,-0.5},    -- euros
}

local nlIDX={
    3962,2113,1784,2054,2428,2352
}

addEvent("toggleVehicleNL"true)
addEventHandler("toggleVehicleNL"root, function(plr)
  local rodzajneonu=tonumber(getElementData(source,"neony"))
  if not rodzajneonu then return end
  local zneony=getElementData(source,"zneony")
  if (zneony and type(zneony)=="table"then
    destroyElement(zneony[1])
    destroyElement(zneony[2])
    removeElementData(source,"zneony")

    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " wciska przycisk przy kokpicie."55true)

  else
    local m getElementModel(source)
    local of
    if not nlOffsets[mthen
        of={-1,0,-0.5}
    else
        of=nlOffsets[m]
    end
    neon1=createObject(nlIDX[rodzajneonu] or 3962,0,0,0)
    neon2=createObject(nlIDX[rodzajneonu] or 3962,0,0,0)
    setElementData(source,"zneony", {neon1neon2})
    attachElements(neon1,source,of[1],of[2],of[3])
    attachElements(neon2,source,-of[1],of[2],of[3])
    triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " wciska przycisk przy kokpicie."525true)
  end
end)

addEvent("toggleVehicleRoof"true)
addEventHandler("toggleVehicleRoof"root, function(plr)
    local v1,v2,v3 getVehicleVariant(source)
    local engine getVehicleEngineState(source)
    if getElementModel(source)==555 then --windsor
        if (v1==0then --jest
            setVehicleVariant(source1255)
            triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " otwiera dach."55true)
        elseif (v1==1then --nie ma
            setVehicleVariant(source0255)
            triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " zamyka dach."55true)
        end
    elseif getElementModel(source)==439 then --stallion
        if (v1==1then --jest
            setVehicleVariant(source2255)
            triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " otwiera dach."55true)
        elseif (v1==2then --nie ma
            setVehicleVariant(source1255)
            triggerEvent("broadcastCaptionedEvent"plrgetPlayerName(plr) .. " zamyka dach."55true)
        end
    end
    setTimer(function(veh,engine)
        if not engine then
            setVehicleEngineState(veh,false)
        end
    end1001source,engine)
end)


Postaw piwo autorowi tego posta
 

 
Tagi: paintjob
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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