#Al-Ha[J]aRii Posted June 16, 2013 Posted June 16, 2013 ليش بعض SQL Lite executeSQLQuery("INSERT INTO `players`(`name`,`color`,`sound`) VALUES(?,?,?)", playerName, colorName, soundName ) اشوف حاط playerName , colorName , soundName أنا فهمت شرح تيتي لاكن هذه الي مافهمتها في الاسكل لايت
PaiN^ Posted June 16, 2013 Posted June 16, 2013 هذا مجرد مثال على انك تحفظ لون ولاعب وصوت وكذا يعني مجرد مثال + إذا فهمت الجداول راح تلقاها تمشي معاك زي الحلاوة ذذ SQL
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 هذا مجرد مثال على انك تحفظ لون ولاعب وصوت وكذايعني مجرد مثال + إذا فهمت الجداول راح تلقاها تمشي معاك زي الحلاوة ذذ SQL شرط اسويهم لان لين اسوي جدول في السكل لايت مايطلب هذه الاشياء
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 (edited) اجل كيف بتحفظ ؟ ذذ قصدي لين اسوي جدول في السكل executeSQLQuery("CREATE TABLE IF NOT EXISTS Alhajarii (Column1 TEXT, Column2 TEXT,Column3 TEXT)") مايقول يبي playerName + يحتاج اسوي فوقها كذا ذذ { { colname1=value1, colname2=value2, ... }, { colname1=value3, colname2=value4, ... }, ... } Edited June 16, 2013 by Guest
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 لا بس توضيح من الويكي طيب صح اسوي كذا لحفظ حساب executeSQLQuery("INSERT INTO `Alhajarii`(`Account`,`Password`,`Serial`) VALUES(?,?,?)", AlhajariiAccount, AlhajariiPassword, AlhajariiSerial )
PaiN^ Posted June 16, 2013 Posted June 16, 2013 executeSQLQuery( "CREATE TABLE IF NOT EXISTS TableName ( 1, 2, 3 )" ) شايف الأرقام هذي هي الأشياء اللي تخزن فيها, يعني لو تبي تحفظ فلوس لاعب بالسيريال حقه تسوي عمودين executeSQLQuery( "CREATE TABLE IF NOT EXISTS TableName ( serial, money )" ) وكذا على حسب اللي تبي تحفظه + كودك صح اذا المتغيرات معرفة
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 executeSQLQuery( "CREATE TABLE IF NOT EXISTS TableName ( 1, 2, 3 )" ) شايف الأرقام هذي هي الأشياء اللي تخزن فيها, يعني لو تبي تحفظ فلوس لاعب بالسيريال حقه تسوي عمودين executeSQLQuery( "CREATE TABLE IF NOT EXISTS TableName ( serial, money )" ) وكذا على حسب اللي تبي تحفظه + كودك صح اذا المتغيرات معرفة قصدك function(playerAccount,playerPassword,playerSerial) executeSQLQuery("CREATE TABLE IF NOT EXISTS Alhajarii (Column1 TEXT, Column2 TEXT, Column3 TEXT)") executeSQLQuery("INSERT INTO Alhajarii(acc,pass,serial) VALUES(?,?,?)", playerAccount, playerPassword, playerSerial )
iPrestege Posted June 16, 2013 Posted June 16, 2013 addEventHandler('onResourceStart',resourceRoot, function ( ) executeSQLQuery("CREATE TABLE IF NOT EXISTS Alhajarii ( Column,Column,Column )") -- Table = Alhajarii end )
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 addEventHandler('onResourceStart',resourceRoot, function ( ) executeSQLQuery("CREATE TABLE IF NOT EXISTS Alhajarii ( Column,Column,Column )") -- Table = Alhajarii end ) طيب بعدين شلون بسوي هذلين كود ممكن مثال
iPrestege Posted June 16, 2013 Posted June 16, 2013 مثال تسوي نظام حفظ الاحداثيات بـ SQL ( Serial ) .. اول شيء نسوية نظيفة للقاعدة نسوي جدول بالقاعدة registry.db لانه الفنكشن حق SQL يستخدم قاعدهـ ( registry ) .. اول شيء نسوي جدول داخل قاعدة : addEventHandler('onResourceStart',resourceRoot, function ( ) local CreateNewTable = executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') if ( CreateNewTable ) then outputDebugString('Create [ Save Position System ] Table done .') end end ) اللي سويتة انا : executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') بس سويت متغير او مسمى للتيبل اللي بيتخزن بقاعدتنا الاولى و سويت الكولومن اللي احتاجهم على حسب اللي تسوية انا سويت هذولا : PlayerSerial = بخزنة عالسريال PlayerX = احداثي X PlayerY = احداثي Y PlayerZ = احداثي Z وسميت الجدول حق القاعدة : Save Position System = نظام حفظ الاحداثيات الحين سوينا القاعدة عشان بـ استخدم : executeSQLQuery ( 'CREATE TABLE IF NOT EXISTS MyTable or `MY TABLE` or 'My Table' ( column,... )' ) الحين ودكـ تخزن الاشياء صح ؟ انا بخزنها يوم يطلع الاعب من الروم . . : addEventHandler('onPlayerQuit',root, function ( ) local x,y,z = getElementPosition ( source ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) else executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) end end ) الاشياء و الوظائف الثانية معروفة .. بس بوضح لك الـ ( SQL ) : اول شيء نجيب النتائج عشان قبل لانخزن نتحقق اذا فية شيء مخزن نسوي لة تحديث مانخزن من جديد ~ : local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) و الـ Results يعتبر جدول لانة جدول اصلا .. الحين جبنا نتائج نتحقق : if ( type ( Results ) == "table" and #Results == 0 or not Results ) then اذا ماكان فية شيء مخزن او او او التيبل = 0 نسوي ادخال للبيانات على سريال الاعب بالترتيب من الـ Column اللي مسوية ! executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) اذا اول مرة تسوية ولا اذا كان مخزن تسوي تحديث بس ~ طبعا واضحة الاشياء من قبل PlayerSerial = بخزنة عالسريال PlayerX = احداثي X PlayerY = احداثي Y PlayerZ = احداثي Z و اسم التيبل حق القاعدة واضح ~ و الـ VALUES ( ?,?,? ) تكون على حسب اللي انت تحتاجها اصلا .. امم الحين نفرض انة مخزن من قبل ! ومسوي ادخال للبيانات وحصلها بالقاعدة وش المفترض تخزن ثانية ؟ لآ ~ : نسوي تحديث للبيانات : executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) SET = ? Wiki WHERE = ? Wiki UPDATE = ? Wiki انت تحدث على مين ؟ على سريال الاعب WHERE PlayerSerial =? -- التحديث بيكون عالسريال الخاص بالاعب # الحين حفظنآ يوم خرج الاعب بنحمل البيانات يوم يسجل دخولة الاعب : addEventHandler('onPlayerLogin',root, function ( ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) end ) انت اللي عليك بس تبي تجيب بيانات من اللي مخزنة ؟ بيانات السريال ! صح ؟ زين سويناها : local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) مع اسم التيبل حق القاعدة بـ التأكيد .. الحين نتحقق فية بيانات عندي ولالا ؟ : if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end اذا مافية خلاص مايسوي شيء ويكنسل .. اذا فية بيكمل وبيسوي لك setElementPosition : setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] = ? هذي من وين جبتها ؟ هذي الاشياء اللي انت سويتها Column فية طريقة ثانية استخرج فيها اطول شوي شوف : for _,v in ipairs ( Results ) do setElementPosition ( source,v.PlayerX,v.PlayerY,v.PlayerZ ) end و بكذآ سوينا نظام حفظ للاحداثيات عن طريق : SQL أتمنى وصلتكـ المعلومة بكل وضوح وهذا السكربت بشكل كامل يطلع : addEventHandler('onResourceStart',resourceRoot, function ( ) local CreateNewTable = executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') if ( CreateNewTable ) then outputDebugString('Create [ Save Position System ] Table done .') end end ) addEventHandler('onPlayerQuit',root, function ( ) local x,y,z = getElementPosition ( source ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) else executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) end end ) addEventHandler('onPlayerLogin',root, function ( ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) end ) بـ التوفيق .. اي شيء تفضل أسأل عنة ..
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 مثال تسوي نظام حفظ الاحداثيات بـ SQL ( Serial ) .. اول شيء نسوية نظيفة للقاعدة نسوي جدول بالقاعدة registry.db لانه الفنكشن حق SQL يستخدم قاعدهـ ( registry ) .. اول شيء نسوي جدول داخل قاعدة : addEventHandler('onResourceStart',resourceRoot, function ( ) local CreateNewTable = executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') if ( CreateNewTable ) then outputDebugString('Create [ Save Position System ] Table done .') end end ) اللي سويتة انا : executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') بس سويت متغير او مسمى للتيبل اللي بيتخزن بقاعدتنا الاولى و سويت الكولومن اللي احتاجهم على حسب اللي تسوية انا سويت هذولا : PlayerSerial = بخزنة عالسريال PlayerX = احداثي X PlayerY = احداثي Y PlayerZ = احداثي Z وسميت الجدول حق القاعدة : Save Position System = نظام حفظ الاحداثيات الحين سوينا القاعدة عشان بـ استخدم : executeSQLQuery ( 'CREATE TABLE IF NOT EXISTS MyTable or `MY TABLE` or 'My Table' ( column,... )' ) الحين ودكـ تخزن الاشياء صح ؟ انا بخزنها يوم يطلع الاعب من الروم . . : addEventHandler('onPlayerQuit',root, function ( ) local x,y,z = getElementPosition ( source ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) else executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) end end ) الاشياء و الوظائف الثانية معروفة .. بس بوضح لك الـ ( SQL ) : اول شيء نجيب النتائج عشان قبل لانخزن نتحقق اذا فية شيء مخزن نسوي لة تحديث مانخزن من جديد ~ : local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) و الـ Results يعتبر جدول لانة جدول اصلا .. الحين جبنا نتائج نتحقق : if ( type ( Results ) == "table" and #Results == 0 or not Results ) then اذا ماكان فية شيء مخزن او او او التيبل = 0 نسوي ادخال للبيانات على سريال الاعب بالترتيب من الـ Column اللي مسوية ! executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) اذا اول مرة تسوية ولا اذا كان مخزن تسوي تحديث بس ~ طبعا واضحة الاشياء من قبل PlayerSerial = بخزنة عالسريال PlayerX = احداثي X PlayerY = احداثي Y PlayerZ = احداثي Z و اسم التيبل حق القاعدة واضح ~ و الـ VALUES ( ?,?,? ) تكون على حسب اللي انت تحتاجها اصلا .. امم الحين نفرض انة مخزن من قبل ! ومسوي ادخال للبيانات وحصلها بالقاعدة وش المفترض تخزن ثانية ؟ لآ ~ : نسوي تحديث للبيانات : executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) SET = ? Wiki WHERE = ? Wiki UPDATE = ? Wiki انت تحدث على مين ؟ على سريال الاعب WHERE PlayerSerial =? -- التحديث بيكون عالسريال الخاص بالاعب # الحين حفظنآ يوم خرج الاعب بنحمل البيانات يوم يسجل دخولة الاعب : addEventHandler('onPlayerLogin',root, function ( ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) end ) انت اللي عليك بس تبي تجيب بيانات من اللي مخزنة ؟ بيانات السريال ! صح ؟ زين سويناها : local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) مع اسم التيبل حق القاعدة بـ التأكيد .. الحين نتحقق فية بيانات عندي ولالا ؟ : if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end اذا مافية خلاص مايسوي شيء ويكنسل .. اذا فية بيكمل وبيسوي لك setElementPosition : setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] = ? هذي من وين جبتها ؟ هذي الاشياء اللي انت سويتها Column فية طريقة ثانية استخرج فيها اطول شوي شوف : for _,v in ipairs ( Results ) do setElementPosition ( source,v.PlayerX,v.PlayerY,v.PlayerZ ) end و بكذآ سوينا نظام حفظ للاحداثيات عن طريق : SQL أتمنى وصلتكـ المعلومة بكل وضوح وهذا السكربت بشكل كامل يطلع : addEventHandler('onResourceStart',resourceRoot, function ( ) local CreateNewTable = executeSQLQuery ('CREATE TABLE IF NOT EXISTS `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) ') if ( CreateNewTable ) then outputDebugString('Create [ Save Position System ] Table done .') end end ) addEventHandler('onPlayerQuit',root, function ( ) local x,y,z = getElementPosition ( source ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then executeSQLQuery ( "INSERT INTO `Save Position System` ( PlayerSerial,PlayerX,PlayerY,PlayerZ ) VALUES(?,?,?,?)",getPlayerSerial ( source ),x,y,z ) else executeSQLQuery('UPDATE `Save Position System` SET PlayerX =?, PlayerY =?, PlayerZ =? WHERE PlayerSerial =?',x,y,z,getPlayerSerial ( source ) ) end end ) addEventHandler('onPlayerLogin',root, function ( ) local Results = executeSQLQuery("SELECT * FROM `Save Position System` WHERE PlayerSerial=?",getPlayerSerial ( source ) ) if ( type ( Results ) == "table" and #Results == 0 or not Results ) then return end setTimer( setElementPosition,2000,1,source,Results[1]['PlayerX'],Results[1]['PlayerY'],Results[1]['PlayerZ'] ) end ) بـ التوفيق .. اي شيء تفضل أسأل عنة .. يسلمو شرح وافي وكافي ~ بس ويش كل وحده من هذلين MY SQL يسوون dbConnect dbExec dbQuery dbPoll dbFree
iPrestege Posted June 16, 2013 Posted June 16, 2013 dbConnect -- يتصل dbExec -- ادخل - تحديث dbQuery -- استخراج نتائج dbPoll -- استخراج مع اللي قبله فوق اجباري dbFree -- او هذا مع dbQuery
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 dbConnect -- يتصل dbExec -- ادخل - تحديث dbQuery -- استخراج نتائج dbPoll -- استخراج مع اللي قبله فوق اجباري dbFree -- او هذا مع dbQuery اوكي تسلم
iPrestege Posted June 16, 2013 Posted June 16, 2013 addEventHandler('onResourceStart', getResourceRootElement(getThisResource()), function( ) PrestegeDB = dbConnect( "sqlite", ":aResource/PrestegeDB.db" ) for k, v in pairs( getElementsByType( "player" ) ) do local Name = getPlayerName(v) local Serial = getPlayerSerial(v) local result = dbQuery( PrestegeDB, "SELECT * FROM Seriallist WHERE serial=?", Serial) local result_ = dbPoll( result, -1 ) if ( type ( result_ ) == "table" and #result_ == 0 ) or not result_ then outputChatBox(' INSERT ', root, 255, 0, 0) dbExec( PrestegeDB, 'INSERT INTO Seriallist(serial, Name) VALUES( ?, ? )', Serial, Name) else outputChatBox(' UPDATE ', root, 255, 0, 0) dbExec( PrestegeDB, 'UPDATE Seriallist SET Name =? WHERE serial =?', Name, Serial) end end end ) addEventHandler('onResourceStop', getResourceRootElement(getThisResource()), function( ) destroyElement(PrestegeDB) end )
#Al-Ha[J]aRii Posted June 16, 2013 Author Posted June 16, 2013 addEventHandler('onResourceStart', getResourceRootElement(getThisResource()), function( ) PrestegeDB = dbConnect( "sqlite", ":aResource/PrestegeDB.db" ) for k, v in pairs( getElementsByType( "player" ) ) do local Name = getPlayerName(v) local Serial = getPlayerSerial(v) local result = dbQuery( PrestegeDB, "SELECT * FROM Seriallist WHERE serial=?", Serial) local result_ = dbPoll( result, -1 ) if ( type ( result_ ) == "table" and #result_ == 0 ) or not result_ then outputChatBox(' INSERT ', root, 255, 0, 0) dbExec( PrestegeDB, 'INSERT INTO Seriallist(serial, Name) VALUES( ?, ? )', Serial, Name) else outputChatBox(' UPDATE ', root, 255, 0, 0) dbExec( PrestegeDB, 'UPDATE Seriallist SET Name =? WHERE serial =?', Name, Serial) end end end ) addEventHandler('onResourceStop', getResourceRootElement(getThisResource()), function( ) destroyElement(PrestegeDB) end ) PrestegeDB = dbConnect( "sqlite", ":aResource/PrestegeDB.db" ) انشاء ملف اسمه PrestegeDB.db ?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now