Jump to content

مساعدة في executeSQLQuery


WTF_

Recommended Posts

executeSQLQuery( ' CREATE TABLE IF NOT EXISTS `weaponAmmo` (account, weapon, ammo) ' )


addEventHandler ( "onPlayerQuit", root , function ( )
local checkData = executeSQLQuery( ' SELECT * FROM `weaponAmmo` WHERE account = ? ', getPlayerAccount(source) ) 
local ammoo = getPedTotalAmmo ( source )
local weaponn =  getPedWeapon ( source ) 
if ( type ( checkData ) == 'table' and #checkData == 0 or not checkData ) and  not isGuestAccount ( source ) then
executeSQLQuery( ' INSERT INTO `weaponAmmo` (account, weapon, ammo) VALUES(?, ?, ?) ', getPlayerAccount(source), ammoo, weaponn )
else 
executeSQLQuery( ' UPDATE`weaponAmmo` SET weapon = ? , ammo = ? WHERE account = ? ', getPlayerAccount(source), ammoo, weaponn  )
end 
end 
)


addEventHandler("onPlayerLogin", root,
  function()
  local weaponn1 = executeSQLQuery( ' SELECT * FROM `weaponAmmo` WHERE account = ? ', getPlayerAccount(source) ) 
  if ( type ( weaponn1 ) == 'table' and #weaponn1 == 0 or not weaponn1 ) then
  else 
  local wp = weaponn1[1]['weapon']
  local am = weaponn1[1]['ammo']
  local wpp = getWeaponIDFromName ( wp )
  giveWeapon ( source , wpp , am )   
  end 
  end 
  )
  

 

Link to comment
14 minutes ago, -Le[3]bA. said:

if ( type ( checkData ) == 'table' and #checkData == 0 or not checkData and not isGuestAccount ( source ) ) then

 

خخخخخخخخخخخخ بالله يا أخوي قول شي تفهمه مشان ما رح يفرق شي والمشكلة مو من التحقق ://

على كل حال شكرا لمحاولت المساعدة :)

Link to comment
14 minutes ago, WTF_ said:

خخخخخخخخخخخخ بالله يا أخوي قول شي تفهمه مشان ما رح يفرق شي والمشكلة مو من التحقق ://

على كل حال شكرا لمحاولت المساعدة :)

ي حبيبي

شوف كودك

if ( type ( checkData ) == 'table' and #checkData == 0 or not checkData ) and  not isGuestAccount ( source ) then

كيف قافل التحقق ؟

واطرح الدي بق عشان نعرف المشكله م راح نعرفها تلقائي

وعدل السطر ذا إلي

giveWeapon ( source , wpp , am ) -- to
giveWeapon ( source , wpp , am, true )   

 

Edited by -Le[3]bA.
Link to comment
2 hours ago, -Le[3]bA. said:

شوف كودك

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

لكن التحقق الخاص بك يا غالي راح يسبب مشاكل ليش

لانه لما يجي يتحقق ينفذ اول شي بالترتيب العمليات ما بين الاقواس فهمت علي؟

Link to comment
executeSQLQuery( 'CREATE TABLE IF NOT EXISTS `weaponAmmo` (account TEXT, weapon NUMERIC, ammo NUMERIC)' )

function onPlayerQuit( )
    local playerAccount = getPlayerAccount(source)
    if ( playerAccount ) and ( not isGuestAccount(playerAccount) ) then
        local accountName = getAccountName(playerAccount)
        local checkData = executeSQLQuery( 'SELECT * FROM `weaponAmmo` WHERE account=?', accountName )
        local ammoo = getPedTotalAmmo ( source )
        local weaponn = getPedWeapon ( source )
        if ( #checkData == 0 ) then
            executeSQLQuery( 'INSERT INTO `weaponAmmo` (account,weapon,ammo) VALUES(?,?,?)', accountName, weaponn, ammoo )
        else
            executeSQLQuery( 'UPDATE `weaponAmmo` SET weapon=?,ammo=? WHERE account=?', weaponn, ammoo, accountName )
        end
    end
end
addEventHandler ( "onPlayerQuit", root , onPlayerQuit )

function onPlayerLogin()
    local playerAccount = getPlayerAccount(source)
    local accountName = getAccountName(playerAccount)
    local weaponn1 = executeSQLQuery( 'SELECT * FROM `weaponAmmo` WHERE account=?', accountName )
    if ( #weaponn1 ~= 0 ) then
        local wp = weaponn1[1]['weapon']
        local am = weaponn1[1]['ammo']
        giveWeapon ( source, wp, am )   
    end
end
addEventHandler("onPlayerLogin", root, onPlayerLogin )

الكود غير مجرب، جربه ورد لنا خبر

Edited by Bssol
Link to comment
9 hours ago, Bssol said:

executeSQLQuery( 'CREATE TABLE IF NOT EXISTS `weaponAmmo` (account TEXT, weapon NUMERIC, ammo NUMERIC)' )

function onPlayerQuit( )
    local playerAccount = getPlayerAccount(source)
    if ( playerAccount ) and ( not isGuestAccount(playerAccount) ) then
        local accountName = getAccountName(playerAccount)
        local checkData = executeSQLQuery( 'SELECT * FROM `weaponAmmo` WHERE account=?', accountName )
        local ammoo = getPedTotalAmmo ( source )
        local weaponn = getPedWeapon ( source )
        if ( #checkData == 0 ) then
            executeSQLQuery( 'INSERT INTO `weaponAmmo` (account,weapon,ammo) VALUES(?,?,?)', accountName, weaponn, ammoo )
        else
            executeSQLQuery( 'UPDATE `weaponAmmo` SET weapon=?,ammo=? WHERE account=?', weaponn, ammoo, accountName )
        end
    end
end
addEventHandler ( "onPlayerQuit", root , onPlayerQuit )

function onPlayerLogin()
    local playerAccount = getPlayerAccount(source)
    local accountName = getAccountName(playerAccount)
    local weaponn1 = executeSQLQuery( 'SELECT * FROM `weaponAmmo` WHERE account=?', accountName )
    if ( #weaponn1 ~= 0 ) then
        local wp = weaponn1[1]['weapon']
        local am = weaponn1[1]['ammo']
        giveWeapon ( source, wp, am )   
    end
end
addEventHandler("onPlayerLogin", root, onPlayerLogin )

الكود غير مجرب، جربه ورد لنا خبر

أخوي جربته وضبط معي بس مو 100/100 يعني انا معي 10 أسلح بيعطيني سلاح واحد :'(

Link to comment
addEventHandler('onResourceStart', root, function()
    local createdTable = executeSQLQuery('CREATE TABLE IF NOT EXISTS `restoreWeapons` (playerAccount, weaponsTable)');
end)

function onPlayerQuit()
    local playerAccount = getPlayerAccount(source)
    if playerAccount and not isGuestAccount(playerAccount) then
        local accountName = getAccountName(playerAccount)
        local checkData = executeSQLQuery('SELECT * FROM `restoreWeapons` WHERE playerAccount = ?', accountName)
        local weps = getPedWeapons(source);
        if weps and type(weps) == 'table' then
        local weapons = toJSON(weps)
            if type(checkData) == 'table' then
                if #checkData == 0 then
                    executeSQLQuery('INSERT INTO `restoreWeapons` (playerAccount, weaponsTable) VALUES(?, ?)', accountName, weapons)
                else
                    executeSQLQuery('UPDATE `restoreWeapons` SET weaponsTable = ? WHERE playerAccount = ?', weapons, accountName)
                end
            end
        end
    end
end
addEventHandler('onPlayerQuit', root, onPlayerQuit)

function onPlayerLogin(_, acc)
        local accountName = getAccountName(acc)
        local checkData = executeSQLQuery('SELECT * FROM `restoreWeapons` WHERE playerAccount = ?', accountName)
        if type(checkData) == 'table' and #checkData > 0 then
        local weapons = fromJSON(checkData[1].weaponsTable)
            if weapons and type(weapons) == 'table' then
                for _, weaponz in ipairs(weapons) do
                if weaponz.weapon and weaponz.ammo then
                    giveWeapon(source, weaponz.weapon, weaponz.ammo);
                end
            end
        end
    end
end
addEventHandler('onPlayerLogin', root, onPlayerLogin)

function getPedWeapons(ped) 
    local playerWeapons = {} 
    if ped and isElement(ped) and getElementType(ped) == 'ped' or getElementType(ped) == 'player' then 
        for i=2,9 do 
            local wep = getPedWeapon(ped,i) 
            if wep and wep ~= 0 then 
                table.insert(playerWeapons, {weapon = wep, ammo = getPedTotalAmmo(ped, i)}) 
            end 
        end 
    else 
        return false 
    end 
    return playerWeapons 
end 

 

Edited by #,+( _xiRoc[K]; >
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...