Jump to content

مشكلة في كود بسيط يرجى المساعدة


Recommended Posts

مافهمت المشكل يقلي هيك

ERROR: UserPanel/inventory_server.lua:79: bad argument #1 to 'ipairs' (table expected, got boolean)

--[[

    [ - ] = Removed : [ + ] Added : [ ! ] Fixed
    FILE : inventory_server.lua
    TODO : 
    Notes : 
    Last edit : 
    05/03/2020 [Simple]
        + Fuel Stations to inventory
        + Restaurants to inventory
        + Vehicles to inventory ( Mustang, Car )
        
    23/02/2020 [Simple]
        + Skins to inventory
        + Group skins to inventory
]]
local PACKS = { "Gold Package", "Silver Package", "Bronze Package" }
local CarIDs = { 477, 438 }
local RM = exports["ResturantManager"]
local FM = exports["FuelManager"]
addEventHandler ( "onResourceStart", resourceRoot,
function ()
    vehicle_db = dbConnect ( "sqlite", ":VehicleSystem/database-edited.db" )
    if vehicle_db then
        outputDebugString ('[ USER PANEL ] Connected success to Vehicles Database')
    end
    package_db = dbConnect ( "sqlite", ":PackagesSystem/Packages.db" )
    if package_db then
        outputDebugString ('[ USER PANEL ] Connected success to Packages Database')
    end
    skins_db = dbConnect ( "sqlite", ":SkinsManagement/Database.db" )
    if skins_db then
        outputDebugString ('[ USER PANEL ] Connected success to Skins Database')
    end
end)

addEvent ( 'UI:onInventoryTabClientSelect', true )
function onInventoryTabClientSelect ()
    local ITEMS = {}
    for i,v in ipairs ( dbPoll(dbQuery(package_db, "SELECT * FROM Packages WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if tonumber(v['number']) > 0 then
            table.insert ( ITEMS, { ['ITEM_NAME'] = tostring ( PACKS[tonumber(v['number'])] ) , ['ITEM_AMMOUNT'] = v['ammount'], ['ITEM_TYPE'] = 'package'})
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
            end
        end
    end
    if RM:isPlayerHasResturant(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Restaurant' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'restaurant'})
    end
    if FM:isPlayerHasFuel(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Fuel station' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'fuel'})
    end
    --[[
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM PaintOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Paintjobs WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = v['type']})
            end
        end
    end
    --]]
    if getElementData ( source, 'Group' ) then
        for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?",  getElementData ( source, 'Group' )), -1) ) do
            if v['account'] then
                local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
                if SkinInfo and #SkinInfo ~= 0 then
                    table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
                end
            end
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(vehicle_db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if isAllowedModel ( tonumber ( v['Model'] ) ) then
            table.insert ( ITEMS, { ['ITEM_NAME'] = getVehicleNameFromModel( v['Model'] ) , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'vehicle'})
        end
    end
    triggerClientEvent ( source, 'UI:UpdateClientPlayerItems', source, ITEMS )
end
addEventHandler ( 'UI:onInventoryTabClientSelect', root, onInventoryTabClientSelect )

function isAllowedModel ( model )
    for i,v in ipairs ( CarIDs ) do
        if v == model then
            return true
        end
    end
    return false
end

Link to comment

مانتبهت له حبيت مساعدة فقط

--[[

    [ - ] = Removed : [ + ] Added : [ ! ] Fixed
    FILE : inventory_server.lua
    TODO : 
    Notes : 
    Last edit : 
    05/03/2020 [Simple]
        + Fuel Stations to inventory
        + Restaurants to inventory
        + Vehicles to inventory ( Mustang, Car )
        
    23/02/2020 [Simple]
        + Skins to inventory
        + Group skins to inventory
]]
local PACKS = { "Gold Package", "Silver Package", "Bronze Package" }
local CarIDs = { 477, 438 }
local RM = exports["ResturantManager"]
local FM = exports["FuelManager"]
addEventHandler ( "onResourceStart", resourceRoot,
function ()
    vehicle_db = dbConnect ( "sqlite", ":VehicleSystem/database-edited.db" )
    if vehicle_db then
        outputDebugString ('[ USER PANEL ] Connected success to Vehicles Database')
    end
    package_db = dbConnect ( "sqlite", ":PackagesSystem/Packages.db" )
    if package_db then
        outputDebugString ('[ USER PANEL ] Connected success to Packages Database')
    end
    skins_db = dbConnect ( "sqlite", ":SkinsManagement/Database.db" )
    if skins_db then
        outputDebugString ('[ USER PANEL ] Connected success to Skins Database')
    end
end)

addEvent ( 'UI:onInventoryTabClientSelect', true )
function onInventoryTabClientSelect ()
    local ITEMS = {}
    for i,v in ipairs ( dbPoll(dbQuery(package_db, "SELECT * FROM Packages WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if tonumber(v['number']) > 0 then
            table.insert ( ITEMS, { ['ITEM_NAME'] = tostring ( PACKS[tonumber(v['number'])] ) , ['ITEM_AMMOUNT'] = v['ammount'], ['ITEM_TYPE'] = 'package'})
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
            end
        end
    end
    if RM:isPlayerHasResturant(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Restaurant' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'restaurant'})
    end
    if FM:isPlayerHasFuel(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Fuel station' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'fuel'})
    end
    --[[
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM PaintOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Paintjobs WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = v['type']})
            end
        end
    end
    --]]
    if getElementData ( source, 'Group' ) then
        for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?",  getElementData ( source, 'Group' )), -1) ) do
            if v['account'] then
                local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
                if SkinInfo and #SkinInfo ~= 0 then
                    table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
                end
            end
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(vehicle_db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if isAllowedModel ( tonumber ( v['Model'] ) ) then
            table.insert ( ITEMS, { ['ITEM_NAME'] = getVehicleNameFromModel( v['Model'] ) , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'vehicle'})
        end
    end
    triggerClientEvent ( source, 'UI:UpdateClientPlayerItems', source, ITEMS )
end
addEventHandler ( 'UI:onInventoryTabClientSelect', root, onInventoryTabClientSelect )

function isAllowedModel ( model )
    for i,v in ipairs ( CarIDs ) do
        if v == model then
            return true
        end
    end
    return false
end

 

Link to comment
  • Scripting Moderators

الأفضل ماتسوي لوب بعد ما تجيب النتيجة من القاعدة على طول

شوف النتيجة وسوي تحقق انها جدول أول

type (value) == "table"

وفيه نصيحة كويسة لو تسويها بيكون افضل لك

بدال ماتسوي قاعدة مختلفة لكل مود

يمديك تسوي مود واحد فيه قاعدة البيانات وملف واحد ويمديك تضيف فيه اكثر من جدول بنفس القاعدة
وتسوي لها  اكسبورت بدال ماتسوي 3 اتصالات بكل مود

mysql كذا بتقلل الرام وتقدر بكل بسهولة لو قررت مستقبلًا تحوله 

Edited by xLive
  • Like 1
Link to comment
On 16/08/2020 at 13:09, Faycel... said:

مانتبهت له حبيت مساعدة فقط


--[[

    [ - ] = Removed : [ + ] Added : [ ! ] Fixed
    FILE : inventory_server.lua
    TODO : 
    Notes : 
    Last edit : 
    05/03/2020 [Simple]
        + Fuel Stations to inventory
        + Restaurants to inventory
        + Vehicles to inventory ( Mustang, Car )
        
    23/02/2020 [Simple]
        + Skins to inventory
        + Group skins to inventory
]]
local PACKS = { "Gold Package", "Silver Package", "Bronze Package" }
local CarIDs = { 477, 438 }
local RM = exports["ResturantManager"]
local FM = exports["FuelManager"]
addEventHandler ( "onResourceStart", resourceRoot,
function ()
    vehicle_db = dbConnect ( "sqlite", ":VehicleSystem/database-edited.db" )
    if vehicle_db then
        outputDebugString ('[ USER PANEL ] Connected success to Vehicles Database')
    end
    package_db = dbConnect ( "sqlite", ":PackagesSystem/Packages.db" )
    if package_db then
        outputDebugString ('[ USER PANEL ] Connected success to Packages Database')
    end
    skins_db = dbConnect ( "sqlite", ":SkinsManagement/Database.db" )
    if skins_db then
        outputDebugString ('[ USER PANEL ] Connected success to Skins Database')
    end
end)

addEvent ( 'UI:onInventoryTabClientSelect', true )
function onInventoryTabClientSelect ()
    local ITEMS = {}
    for i,v in ipairs ( dbPoll(dbQuery(package_db, "SELECT * FROM Packages WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if tonumber(v['number']) > 0 then
            table.insert ( ITEMS, { ['ITEM_NAME'] = tostring ( PACKS[tonumber(v['number'])] ) , ['ITEM_AMMOUNT'] = v['ammount'], ['ITEM_TYPE'] = 'package'})
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
            end
        end
    end
    if RM:isPlayerHasResturant(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Restaurant' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'restaurant'})
    end
    if FM:isPlayerHasFuel(getPlayerSerial(source)) then
        table.insert ( ITEMS, { ['ITEM_NAME'] = 'Fuel station' , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'fuel'})
    end
    --[[
    for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM PaintOwners WHERE account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if v['account'] then
            local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Paintjobs WHERE name = ?", v['skin']), -1)
            if SkinInfo and #SkinInfo ~= 0 then
                table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = v['type']})
            end
        end
    end
    --]]
    if getElementData ( source, 'Group' ) then
        for i,v in ipairs ( dbPoll(dbQuery(skins_db, "SELECT * FROM SkinsOwners WHERE account = ?",  getElementData ( source, 'Group' )), -1) ) do
            if v['account'] then
                local SkinInfo = dbPoll(dbQuery(skins_db, "SELECT * FROM Skins WHERE name = ?", v['skin']), -1)
                if SkinInfo and #SkinInfo ~= 0 then
                    table.insert ( ITEMS, { ['ITEM_NAME'] = v['skin'] , ['ITEM_AMMOUNT'] = SkinInfo[1]['id'], ['ITEM_TYPE'] = 'skin'})
                end
            end
        end
    end
    for i,v in ipairs ( dbPoll(dbQuery(vehicle_db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountName ( getPlayerAccount ( source ) )), -1) ) do
        if isAllowedModel ( tonumber ( v['Model'] ) ) then
            table.insert ( ITEMS, { ['ITEM_NAME'] = getVehicleNameFromModel( v['Model'] ) , ['ITEM_AMMOUNT'] = 1, ['ITEM_TYPE'] = 'vehicle'})
        end
    end
    triggerClientEvent ( source, 'UI:UpdateClientPlayerItems', source, ITEMS )
end
addEventHandler ( 'UI:onInventoryTabClientSelect', root, onInventoryTabClientSelect )

function isAllowedModel ( model )
    for i,v in ipairs ( CarIDs ) do
        if v == model then
            return true
        end
    end
    return false
end

 

اتوقع مشكلتك
 

vehicle_db = dbConnect ( "sqlite", ":VehicleSystem/database-edited.db" )

اتاكد اذا المود شغال .. واسم الداتا باسي نفسه

Link to comment

@xLive سو مثل ما قال لك  الأخ

false في سطر 79 مارجعت لك جدول, رجعت لك dbPoll لأن واضح من الخطأ أن وظيفة.

عشان كذا في البداية لازم تسوي تحقق أن الوظيفة رجعت لك جدول, طبعاً ذا مابيصحح الخطأ, بس دام مارجعت لك جدول كذا عندك خلل, حسب كلام الويكي :

 

 

false: Returns false if the query string contained an error, the connection has been lost or the query handle is incorrect. This automatically frees the query handle, so you do not have to call dbFree.

 Account أو  VhicleList بمعنى يمكن انه خطأ في النص اللي كتبته, يمكن من 

أو خطأ في الاتصال بقاعدة البيانات سواء انحذفت أو اي مشكله صارت.

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...