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

Wysłany: 2015-07-08, 20:51


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Witam, chcia?bym zrobi? skrypt na teleportacje poprzez ID pojazdu.
Stawiam :piwo:

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 20:54


Jurandovsky

Kurdebele






Wiek: 17
Na forum: 4979 dni
Posty: 915

Piwa: 2697

Respekt: 955,3
Respekt: 955,3Respekt: 955,3

No to robisz :

addCommandHandler("teleport", function(plr, cmd, param)
if tonumber(param) then
for _, v in ipairs(getElementsByType("vehicle)) do
if param == getElementData(v, "car:id") then
local x, y, z = getElementPosition(plr)
setElementPosition(v, x, y, z + 5)
warpPedIntoVehicle(plr, v)
end
end
end)


Podpis
Jedyny kontakt ze mną to PW forum

Kod:


local noobs = getElementsByTitle("player", "Programista LUA")
for k, v in ipairs(noobs) do
outputChatBox("Bez mózgu jest użytkownik o nicku: "..getPlayerName(v), root)
destroyElement(v)
end
Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:16


Maximerr

Programmer PHP, LUA






Wiek: 25
Na forum: 4568 dni
Posty: 548

Piwa: 1051

Respekt: 365,3
Respekt: 365,3Respekt: 365,3Respekt: 365,3Respekt: 365,3

Iksdekowski, jeden cudzys??w zjda?e?.
addCommandHandler("teleport", function(plr, cmd, param)
if tonumber(param) then
for _, v in ipairs(getElementsByType("vehicle")) do
if param == getElementData(v, "car:id") then
local x, y, z = getElementPosition(plr)
setElementPosition(v, x, y, z + 5)
warpPedIntoVehicle(plr, v)
end
end
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:19


Jurandovsky

Kurdebele






Wiek: 17
Na forum: 4979 dni
Posty: 915

Piwa: 2697

Respekt: 955,3
Respekt: 955,3Respekt: 955,3

Oj racja, sorry

Podpis
Jedyny kontakt ze mną to PW forum

Kod:


local noobs = getElementsByTitle("player", "Programista LUA")
for k, v in ipairs(noobs) do
outputChatBox("Bez mózgu jest użytkownik o nicku: "..getPlayerName(v), root)
destroyElement(v)
end
Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:28


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

trochu nie dzia?a.
Mam pytanie do tego co mi dali?cie.
To ma teleportowa? pojazd do mnie
np. pojazd ma ID 1, i jest np w sf to piszemy tpc 1 i pojazd tepa si? do mnie.
Za pomoc daje :piwo: :)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:29


Maximerr

Programmer PHP, LUA






Wiek: 25
Na forum: 4568 dni
Posty: 548

Piwa: 1051

Respekt: 365,3
Respekt: 365,3Respekt: 365,3Respekt: 365,3Respekt: 365,3

Podaj elementDat? jak? nadajesz na pojazd jako jego ID.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:48


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

po stronie serwera :

addEvent("kupPojazdSalon", true)
addEventHandler("kupPojazdSalon", getRootElement(),
function(id)
local cena = salonowePojazdy[id]
    if cena then
        if getPlayerMoney(source) >= cena then
        local account = getPlayerAccount(source)
          if account then
          local wlasciciel = getAccountName(account)
            if 5 >= getYourVehicleCount(wlasciciel) then
            takePlayerMoney(source, cena)
            triggerClientEvent(source, "potwierdzKupnoPojazduPrywatnego", root)
            fadeCamera(source, false)
                setTimer(function(source)
                local x, y, z, rot = -1987.46, 276.18, 34.86, 270
                local veh = createVehicle(id, x, y, z)
                setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                setElementData(veh, "pojazd_przebieg", 0)
                local r, g, b = getVehicleColor(veh, true)
                fadeCamera(source, true)
                --<<-->>
                local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                local r, g, b = getVehicleHeadLightColor(veh)
                dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b)
                --<<-->>
                setElementRotation(veh, 0, 0, rot)
                ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                warpPedIntoVehicle(source, veh)
                end, 1500, 1, source)
            else
            outputChatBox("Mo?esz posiada? maksymalnie 5 pojazd?w.", source, 255, 255, 255, true)
            end
          end
        else
        outputChatBox("Potrzebujesz "..cena.."Euro by kupi? ten pojazd.", source, 255, 255, 255, true)
        end
    end
end)

--komenda tworzaca
function stworzPojazdCMD(player, cmd, id, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
    if acc then
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
        if id and wlasciciel then
        local id = tonumber(id)
            if id then
                if getVehicleNameFromModel(id) then
                local x, y, z = getElementPosition(player)
                local _, _, rot = getElementRotation(player)
                
                local veh = createVehicle(id, x, y, z)
                    if veh then
                    setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                    setElementData(veh, "pojazd_przebieg", 0)
                    local r, g, b = getVehicleColor(veh, true)
                    --<<-->>
                    local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                    local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                    local r, g, b = getVehicleHeadLightColor(veh)
                    dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b)
                    --<<-->>
                    setElementRotation(veh, 0, 0, rot)
                    ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                    else
                    outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                    end
                else
                outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                end
            end
        else
        outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
        end
    end
    end
end
addCommandHandler("stworz", stworzPojazdCMD)



dam jeszcze zapis jak b?dzie potrzebny:


handler = dbConnect("sqlite", "pojazdy.db") 

--pojazdy
dbExec(handler, "CREATE TABLE IF NOT EXISTS pojazdy (id INTEGER PRIMARY KEY AUTOINCREMENT, wlasciciel TEXT, model INTEGER, x FLOAT, y FLOAT, z FLOAT, rot FLOAT, ca INTEGER, cb INTEGER, cc INTEGER, przebieg FLOAT, paliwo FLOAT)")
dbExec(handler, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on pojazdy(id)")

--tuning
dbExec(handler, "CREATE TABLE IF NOT EXISTS tuning (id INTEGER, t0 INTEGER, t1 INTEGER, t2 INTEGER, t3 INTEGER, t4 INTEGER, t5 INTEGER, t6 INTEGER, t7 INTEGER, t8 INTEGER, t9 INTEGER, t10 INTEGER, t11 INTEGER, t12 INTEGER, t13 INTEGER, t14 INTEGER, t15 INTEGER, t16 INTEGER, paintjob INTEGER, hr INTEGER, hg INTEGER, hb INTEGER)")
dbExec(handler, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")


function onStartLoadVehicles()
local query = dbQuery(handler, "SELECT * FROM pojazdy")
local result, num_rows, errormsg = dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh = createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh, 0, 0, v["rot"])
    setVehicleColor(veh, v["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(veh, v["id"], v["wlasciciel"])
    
    --ustawiam paliwo i przebieg
    setElementData(veh, "pojazd_paliwo", v["paliwo"] or 50)
    setElementData(veh, "pojazd_przebieg", v["przebieg"] or 0)
    --<< na koncu -->>
    local query = dbQuery(handler, "SELECT * FROM tuning WHERE id='"..v["id"].."'")
    local result, num_rows, errormsg = dbPoll (query, -1)
    setVehiclePaintjob(veh, result[1].paintjob)
    setVehicleHeadLightColor(veh, result[1].hr, result[1].hg, result[1].hb)
        for i,v in pairs(result) do
            for ii, vv in pairs(v) do
                if (ii ~= "id" and ii ~= "paintjob" and ii ~= "hr" and ii ~= "hg" and ii ~= "hb") then
                local vv = tonumber(vv)
                    if vv ~= 0 then
                    addVehicleUpgrade(veh, vv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(veh, id, wlasciciel) --id = INT, wlasciciel = STRING
setElementData(veh, "car_id", id)
setElementData(veh, "car_owner", wlasciciel)
end

function onVehicleStartEnter(player, seat, jacked)
  if seat == 0 then
  local car_owner = getElementData(source, "car_owner")
    if car_owner then
    local account = getPlayerAccount(player)
        if account then
        local name = getAccountName(account)
            if car_owner == name then
            --mamy prawo wejscia do auta
            prawo_ = true
            end
        end
    
        if prawo_ then
        --wchodzim
        prawo_ = false
        else
        --sio
        outputChatBox("Nie masz kluczyk?w do tego pojazdu.", player, 255, 255, 255, true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, onVehicleStartEnter)

--<<ZAPIS POJAZDU-->>

function zapiszPojazdy()
    for i,v in pairs(getElementsByType("vehicle")) do
    local id = getElementData(v, "car_id")
        if id then
        local owner = getElementData(v, "car_owner")
        local x, y, z = getElementPosition(v)
        local _, _, rot = getElementRotation(v)
        local color1, color2, color3, color4 = getVehicleColor(v, true)
        local paliwo = getElementData(v, "pojazd_paliwo")
        local przebieg = getElementData(v, "pojazd_przebieg")
        dbExec(handler, "UPDATE pojazdy SET x='"..x.."', y='"..y.."', z='"..z.."', rot='"..rot.."', ca='"..color1.."', cb='"..color2.."', cc='"..color3.."', przebieg='"..przebieg.."', paliwo='"..paliwo.."' WHERE id='"..id.."'")
        
        local paintjob = getVehiclePaintjob(v)
        local r, g, b = getVehicleHeadLightColor(v)
        sav = {}
            for i=0, 16 do
            local upgrade = getVehicleUpgradeOnSlot(v, i)
            sav[i] = upgrade or 0
            end
        dbExec(handler, "UPDATE tuning SET t0='"..sav[0].."', t1='"..sav[1].."', t2='"..sav[2].."', t3='"..sav[3].."', t4='"..sav[4].."', t5='"..sav[5].."', t6='"..sav[6].."', t7='"..sav[7].."', t8='"..sav[8].."', t9='"..sav[9].."', t10='"..sav[10].."', t11='"..sav[11].."', t12='"..sav[12].."', t13='"..sav[13].."', t14='"..sav[14].."', t15='"..sav[15].."', t16='"..sav[16].."', paintjob='"..paintjob.."', hr='"..r.."', hg='"..g.."', hb='"..b.."' WHERE id="..id.."")
        sav = nil
        end
    end
end
setTimer(zapiszPojazdy, 900000, 0)

function zapiszKomenda(player)
local acc = getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy.", player, 255, 255, 255, true)
    end
end
addCommandHandler("zapiszpojazdy", zapiszKomenda)

-- mapa, f11
addEvent("pobierzPojazdyGracza", true)
addEventHandler("pobierzPojazdyGracza", getRootElement(),
function()
local account = getPlayerAccount(source)
    if account then
    local name = getAccountName(account)
    local vehs = getVehiclesByOwner(name)
    triggerClientEvent(source, "zwrocPojazdyGracza", root, vehs)
    end
end)

--
--zwraca pojazd o danym ID
function getVehicleByID(poszukiwane_id)
    for i,v in pairs(getElementsByType("vehicle")) do
    local id = getElementData(v, "car_id")
        if id then
        local id = tonumber(id)
        local poszukiwane_id = tonumber(poszukiwane_id)
            if id == poszukiwane_id then
            return v
            end
        end
    end
    return false
end

--zwraca pojazdy ktore posiada dany login
function getVehiclesByOwner(szukany)
tab = {}
    for i,v in pairs(getElementsByType("vehicle")) do
    local owner = getElementData(v, "car_owner")
        if owner then
            if owner == szukany then
            table.insert(tab, v)
            end
        end
    end
    return tab
end

--zwraca liczbe pojazdow jaka ma dany login
function getYourVehicleCount(login)
local vehs = getVehiclesByOwner(login)
return #vehs
end

Za pomoc dam pare :piwo:

[ Dodano: 2015-07-08, 21:50 ]
dobra znalaz?em
setElementData(veh, "car_id", id) 


Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 21:54


Jurandovsky

Kurdebele






Wiek: 17
Na forum: 4979 dni
Posty: 915

Piwa: 2697

Respekt: 955,3
Respekt: 955,3Respekt: 955,3


addCommandHandler("teleport", function(plr, cmd, param)
if tonumber(param) then
for _, v in ipairs(getElementsByType("vehicle")) do
if param == getElementData(v, "car_id") then
local x, y, z = getElementPosition(plr)
setElementPosition(v, x, y, z + 5)
warpPedIntoVehicle(plr, v)
end
end
end)


Podpis
Jedyny kontakt ze mną to PW forum

Kod:


local noobs = getElementsByTitle("player", "Programista LUA")
for k, v in ipairs(noobs) do
outputChatBox("Bez mózgu jest użytkownik o nicku: "..getPlayerName(v), root)
destroyElement(v)
end
Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-08, 22:04


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

nie dzia?a mi to

[ Dodano: 2015-07-08, 22:21 ]
aa i db jest co? z ) tam po end i nie mog? tego zwalczy? :/

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 09:08


Fanciak

BOT






Wiek: 26
Na forum: 4587 dni
Posty: 728
Nick w MP: Fanciak

Piwa: 1572

Respekt: 500
Respekt: 500

Dodaj / usu? end. Pokombinuj

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 10:07


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Ok dzi? b?d? kombinowa? :)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 11:02


Maximerr

Programmer PHP, LUA






Wiek: 25
Na forum: 4568 dni
Posty: 548

Piwa: 1051

Respekt: 365,3
Respekt: 365,3Respekt: 365,3Respekt: 365,3Respekt: 365,3

Jednego endu zabrak?o.
addCommandHandler("teleport", function(plr, cmd, param)
if tonumber(param) then
for _, v in ipairs(getElementsByType("vehicle")) do
if param == getElementData(v, "car_id") then
local x, y, z = getElementPosition(plr)
setElementPosition(v, x, y, z + 5)
warpPedIntoVehicle(plr, v)
end
end
end
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 11:11


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

dalej nie dzia?a to :/ pokazuje db i? co? w 10 linijce z ) jest nie tak. pr?buj? zmieniaj?c, usuwaj?c i dalej to samo.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 11:31


Jurandovsky

Kurdebele






Wiek: 17
Na forum: 4979 dni
Posty: 915

Piwa: 2697

Respekt: 955,3
Respekt: 955,3Respekt: 955,3

A robisz to jako jeden kod w osobnym pliku, czy w jednym pliku w kt?rym s? tez inne funkcje ?

Podpis
Jedyny kontakt ze mną to PW forum

Kod:


local noobs = getElementsByTitle("player", "Programista LUA")
for k, v in ipairs(noobs) do
outputChatBox("Bez mózgu jest użytkownik o nicku: "..getPlayerName(v), root)
destroyElement(v)
end
Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-09, 12:18


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

osobny plik, jak robi?em w tym samym co by?o z pojazdami pliku nie chcia? w og?le chodzi? skrypt.
Plik jest jako 1 skrypt z pojazdami.

Postaw piwo autorowi tego posta
 

 
Tagi: tepanie :: pojazdu
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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