Jump to content

PROBLEMA COM CONCESSIONARIA


Recommended Posts

Eu to criando uma concessionaria, e eu quero que o player não consiga comprar carro do mesmo modelo, mas no script que eu criei ele tá conseguindo comprar varios do mesmo modelo esse e o script:

-----------------------------------------------------------------------------------------------------------
 
SpawnVeiculos = {   
[1] = {475,2772.91821,-1875.39771,9.76530}, 
[2] = {579,2777.66089, -1875.530649.79008},
[3] = {602,2782.63550, -1876.054449.81087},
[4] = {475,2787.60474, -1875.875129.83121},
}
 
-----------------------------------------------------------------------------------------------------------
 
function NovoID()
    local result = dbPoll(dbQuery(db, "SELECT ID FROM Veiculos ORDER BY ID ASC"), -1)
    newID = false
    for i, id in pairs (result) do
    if id["ID"] ~= i then
    newID = i
    break
    end
    end
    if newID then return newID else return #result + 1 end
    end
 
-----------------------------------------------------------------------------------------------------------


 
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()),
    function()
        db = dbConnect("sqlite""database.db")
        dbExec(db, "CREATE TABLE IF NOT EXISTS Veiculos (loggin,ID,Model)")
    end
)
 
-----------------------------------------------------------------------------------------------------------
 
function onResourceStart(source)
    if #SpawnVeiculos > 0 then  
for i,v in ipairs(SpawnVeiculos) do  
    SpawnVeiculos = createVehicle(v[1], v[2], v[3], v[4])
    setElementFrozen(SpawnVeiculostrue)
end
else
return
end
end
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart )


 
-----------------------------------------------------------------------------------------------------------
 
function enterVehicle (theVehicle)  
 
    outputChatBox ( "/comprarveiculo Para Comprar o Veiculo", source )
    



 
end
 
addEventHandler ( "onPlayerVehicleEnter"getRootElement(), enterVehicle )


 
-----------------------------------------------------------------------------------------------------------
 
function comprarveiculo(source,theVehicle
 
local data = dbPoll(dbQuery(db, "SELECT * FROM Veiculos WHERE loggin = ?"getAccountID(getPlayerAccount(source))), -1
local theVehicle = getPedOccupiedVehicle (source)
Model =  getElementModel(theVehicle)
 
abc = false
 
for i, data in ipairs (data) do
    if data["Model"] == tonumber(Model) then
    abc = true
    break
    end
end
    
if abc == true 
outputChatBox("#c1c1c1Você já tem este veiculo.", source, 38122216true
return 
end
 
if getPlayerMoney(source) >= 1200 then
    takePlayerMoney(source,1200 )
    setElementFrozen(theVehicle, false)
    local NewID = NovoID()
    dbExec(db, "INSERT INTO Veiculos VALUES(?,?,?)"getAccountName(getPlayerAccount(source)),tonumber(NewID), tonumber(Model))
 
else 
 
    outputChatBox ( "você não tem dinheiro para comprar-lo", source,255,255,255,true)
 
end
end
addCommandHandler("comprarveiculo", comprarveiculo )

 

Edited by Pimenta
Link to comment
16 hours ago, Pimenta said:

Eu to criando uma concessionaria, e eu quero que o player não consiga comprar carro do mesmo modelo, mas no script que eu criei ele tá conseguindo comprar varios do mesmo modelo esse e o script:

-----------------------------------------------------------------------------------------------------------
 
SpawnVeiculos = {   
[1] = {475,2772.91821,-1875.39771,9.76530}, 
[2] = {579,2777.66089, -1875.530649.79008},
[3] = {602,2782.63550, -1876.054449.81087},
[4] = {475,2787.60474, -1875.875129.83121},
}
 
-----------------------------------------------------------------------------------------------------------
 
function NovoID()
    local result = dbPoll(dbQuery(db, "SELECT ID FROM Veiculos ORDER BY ID ASC"), -1)
    newID = false
    for i, id in pairs (result) do
    if id["ID"] ~= i then
    newID = i
    break
    end
    end
    if newID then return newID else return #result + 1 end
    end
 
-----------------------------------------------------------------------------------------------------------


 
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()),
    function()
        db = dbConnect("sqlite""database.db")
        dbExec(db, "CREATE TABLE IF NOT EXISTS Veiculos (loggin,ID,Model)")
    end
)
 
-----------------------------------------------------------------------------------------------------------
 
function onResourceStart(source)
    if #SpawnVeiculos > 0 then  
for i,v in ipairs(SpawnVeiculos) do  
    SpawnVeiculos = createVehicle(v[1], v[2], v[3], v[4])
    setElementFrozen(SpawnVeiculostrue)
end
else
return
end
end
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart )


 
-----------------------------------------------------------------------------------------------------------
 
function enterVehicle (theVehicle)  
 
    outputChatBox ( "/comprarveiculo Para Comprar o Veiculo", source )
    



 
end
 
addEventHandler ( "onPlayerVehicleEnter"getRootElement(), enterVehicle )


 
-----------------------------------------------------------------------------------------------------------
 
function comprarveiculo(source,theVehicle
 
local data = dbPoll(dbQuery(db, "SELECT * FROM Veiculos WHERE loggin = ?"getAccountID(getPlayerAccount(source))), -1
local theVehicle = getPedOccupiedVehicle (source)
Model =  getElementModel(theVehicle)
 
abc = false
 
for i, data in ipairs (data) do
    if data["Model"] == tonumber(Model) then
    abc = true
    break
    end
end
    
if abc == true 
outputChatBox("#c1c1c1Você já tem este veiculo.", source, 38122216true
return 
end
 
if getPlayerMoney(source) >= 1200 then
    takePlayerMoney(source,1200 )
    setElementFrozen(theVehicle, false)
    local NewID = NovoID()
    dbExec(db, "INSERT INTO Veiculos VALUES(?,?,?)"getAccountName(getPlayerAccount(source)),tonumber(NewID), tonumber(Model))
 
else 
 
    outputChatBox ( "você não tem dinheiro para comprar-lo", source,255,255,255,true)
 
end
end
addCommandHandler("comprarveiculo", comprarveiculo )

 

-----------------------------------------------------------------------------------------------------------

SpawnVeiculos = {   
    [1] = {475,2772.91821,-1875.39771,9.76530}, 
    [2] = {579,2777.66089, -1875.53064, 9.79008},
    [3] = {602,2782.63550, -1876.05444, 9.81087},
    [4] = {475,2787.60474, -1875.87512, 9.83121},
}

-----------------------------------------------------------------------------------------------------------

function NovoID()
    local result = dbPoll(dbQuery(db, "SELECT ID FROM Veiculos ORDER BY ID ASC"), -1)
    newID = false
    for i, id in pairs (result) do
        if id["ID"] ~= i then
            newID = i
            break
        end
    end
    if newID then return newID else return #result + 1 end
end

-----------------------------------------------------------------------------------------------------------



addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
function()
    db = dbConnect("sqlite", "database.db")
    dbExec(db, "CREATE TABLE IF NOT EXISTS Veiculos (loggin,ID,Model)")
end
)

-----------------------------------------------------------------------------------------------------------

function onResourceStart(source)
    if #SpawnVeiculos > 0 then  
        for i,v in ipairs(SpawnVeiculos) do  
            SpawnVeiculos = createVehicle(v[1], v[2], v[3], v[4])
            setElementFrozen(SpawnVeiculos, true)
        end
    else
        return
    end
end
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart )



-----------------------------------------------------------------------------------------------------------

function enterVehicle (theVehicle)  
    outputChatBox ( "/comprarveiculo Para Comprar o Veiculo", source )
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle )



-----------------------------------------------------------------------------------------------------------

function comprarveiculo(theVehicle) 
    local data = dbPoll(dbQuery(db, "SELECT * FROM Veiculos WHERE loggin = ?", getAccountID(getPlayerAccount(client))), -1) 
    local theVehicle = getPedOccupiedVehicle (source)
    local Model =  getElementModel(theVehicle)
    local possui = false
    for i, data in ipairs (data) do
        if data["Model"] == Model then
            possui = true
            break
        end
    end
    if not possui then
        if getPlayerMoney(source) >= 1200 then
            takePlayerMoney(source,1200 )
            setElementFrozen(theVehicle, false)
            local NewID = NovoID()
            dbExec(db, "INSERT INTO Veiculos VALUES(?,?,?)", getAccountName(getPlayerAccount(client)),tonumber(NewID), tonumber(Model))
        else 
            outputChatBox ( "você não tem dinheiro para comprar-lo", source,255,255,255,true)
        end
    end
end
addCommandHandler("comprarveiculo", comprarveiculo )

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...