Jump to content

Vehicle shop


itHyperoX

Recommended Posts

Hi.

I'm working on my own vehicle shop, and in the end, i got some problems. 

Here is the code


 

local vehicles = {
{411,80000},
{509,5000},
{481,10000},
{462,35000},
{521,115000},
{463,95000},
{510,14000},
{522,175000},
{461,100000},
{448,50000},
{468,95000},
{586,95000}
}

local carNames =
{
    [500] = "Dozer",
    [455] = "BMW M4",
    [597] = "Test"

}
function getVehicleRealName(vehicle)
    if vehicle then
        local vehicleModel = getElementModel(vehicle)
        if carNames[vehicleModel] then
            return carNames[vehicleModel]
        else
            return getVehicleNameFromModel(v[1])
        end
    end
end

for i,v in ipairs(vehicles) do
    local row = guiGridListAddRow(bikglVehicleSelection)
    guiGridListSetItemText(bikglVehicleSelection,row,1,getVehicleRealName(tostring(v[1])),false,true) -- Here is the error
    guiGridListSetItemText(bikglVehicleSelection,row,2,tostring(v[2]),false,true)
end

The problem is, the gui not showing the vehicles real name. I got some debug error, tried to fix, but nothing helped me. 

debug: Bad argmunet @ 'getElementModel' [Expected element at argument 1, got string '411']  

 attemt to index global 'v' (nil value)

 

any help please?

 

 

When i'm using normal vehiclenames, everything work.

Here is the default

local vehicles = {
{411,80000},
{509,5000},
{481,10000},
{462,35000},
{521,115000},
{463,95000},
{510,14000},
{522,175000},
{461,100000},
{448,50000},
{468,95000},
{586,95000}
}

for i,v in ipairs(vehicles) do
    local bikName = getVehicleNameFromModel(v[1])
    local row = guiGridListAddRow(bikglVehicleSelection)
    guiGridListSetItemText(bikglVehicleSelection,row,1,bikName,false,true)
    guiGridListSetItemText(bikglVehicleSelection,row,2,tostring(v[2]),false,true)
end

 

Edited by TheMOG
Link to comment
ocal biks = {
{411,80000},
{455,5000},
{597,10000},
{462,35000},
{521,115000},
{463,95000},
{510,14000},
{522,175000},
{461,100000},
{448,50000},
{468,95000},
{586,95000}
}

local carNames =
{
    [411] = "Ferrari",
    [455] = "BMW M4",
    [597] = "Test"

}
function getVehicleRealName(vehicle)
    if vehicle then
        local vehicleModel = tonumber(getElementModel(vehicle))
        if carNames[vehicleModel] then
            return carNames[vehicleModel]
        else
            return getVehicleNameFromModel(vehicleModel)
        end
    end
end


for i,v in ipairs(biks) do
	local bikName = getVehicleRealName(v[1])
	local row = guiGridListAddRow(bikglVehicleSelection)
	guiGridListSetItemText(bikglVehicleSelection,row,1,bikName,false,true)
	guiGridListSetItemText(bikglVehicleSelection,row,2,tostring(v[2]),false,true)
end

 

 

Here is, i getting so many debug error

 

From the "carNames" starting the "custom" car names, and i want that, if the vehicle have custom name, it showing the "custom" name, not the default.

I hope you understand

Edited by TheMOG
Link to comment

Ohh man, just realised something, Give me a minute, gonna fix it, and send it here.

local vehicles = {
{411,80000},
{509,5000},
{481,10000},
{462,35000},
{521,115000},
{463,95000},
{510,14000},
{522,175000},
{461,100000},
{448,50000},
{468,95000},
{586,95000}
}

local carNames =
{
    [500] = "Dozer",
    [455] = "BMW M4",
    [597] = "Test"

}
function getVehicleRealName(vehicleModel)
	if carNames[vehicleModel] then
		return carNames[vehicleModel]
	else
		return getVehicleNameFromModel(vehicleModel)
	end
end

for i,v in ipairs(vehicles) do
    local row = guiGridListAddRow(bikglVehicleSelection)
    guiGridListSetItemText(bikglVehicleSelection,row,1,getVehicleRealName(v[1]),false,true)
    guiGridListSetItemText(bikglVehicleSelection,row,2,tostring(v[2]),false,true)
end

This one should work.

Edited by NeXuS™
  • Like 1
Link to comment

@NeXuS™

 

edit:

 

when i'm buying car it saying : ERROR: Database query failed: no such column: Sad 

When i'm buying the car which is dont have custom name, thats work. Only getting error when trying to buy "custom" named vehicle

 

I tried after the error with the default names, and no debug error. What can be the problem?

Edited by TheMOG
Link to comment
addEvent("jarmuVetel1",true)
addEventHandler("jarmuVetel1",getRootElement(),
function(id,cost,name)
    if (exports.serverExport:getMoney(source)>= tonumber(cost)) then
        local account = getPlayerAccount(source)
        local name = getAccountName(account)
        local playercar = executeSQLQuery("SELECT vehID FROM jarmuslot1 WHERE AccNAME = ?",name)
        if #playercar > 0 then
            outputChatBox("#CA5454[Jármű - Rendszer]#FFFFFF Ezen a sloton már van járműved. (1)",source,255,255,255,true)
        else
            exports.serverExport:takeMoney(source,tonumber(cost))
            local addVehicle = executeSQLQuery("INSERT INTO jarmuslot1 (AccNAME,vehID,vehiclePRICE) VALUES(?,?,?)", tostring(name), tonumber(id), tonumber(cost), " ", " ", " ")  -- Line 51 ERRORMSG
            if addVehicle then
                outputChatBox("#6F9F86[Jármű - Rendszer]#FFFFFF Sikeresen megvetted a kiválasztott járművet.",source,255,255,255,true)
            else
                outputChatBox("#CA5454[Jármű - Rendszer]#FFFFFF Sikertelen jármű vásárlás.",source,255,255,255,true)
            end
        end
    else
        outputChatBox("#CA5454[Jármű - Rendszer]#FFFFFF Nincs elég pénzed hogy megvedd ezt a járművet.",source,255,255,255,true)
    end
end)

 

 

 

When im buy the car which dont have custom name, i dont get any error. Errors only appear when i'm trying to buy a "custom named" car.

I think the problem is  the vehicle custom name

Edited by TheMOG
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...