Sha[D]ow Posted August 16, 2015 Share Posted August 16, 2015 السلام عليكم لو سمحت بدى شرح لل SQL الشرح عبارة عن ما وظيفته طريقة الاستحدام اعرف ان الطلب صعب لاكن ان شاء الله لا تبخلون Link to comment
Mr.R Posted August 16, 2015 Share Posted August 16, 2015 https://forum.multitheftauto.com/viewtopic.php?f=164&t=56729 + مثال تسوي نظام حفظ الاحداثيات بـ 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 ) بـ التوفيق .. اي شيء تفضل أسأل عنة .. Link to comment
iMr.SFA7 Posted August 16, 2015 Share Posted August 16, 2015 فيه نوعين لل SQL وانت ما حددت اي واحد الانواع. SQLite يستخدم للحفظ في قاعدة البيانات الداخلية MySQL يستخدم للحفظ في قاعدة البيانات الخارجية اذا كنت تبي تسوي نظام صغير ف مثلا شات للاعبين فأستخدم SQLite اما اذا كنت تبي تسوي نظام كبير وتبي تحفظ بيانات كبيرة فأستخدم MySQL Link to comment
Sha[D]ow Posted August 16, 2015 Author Share Posted August 16, 2015 اظن نبدآ ب sql light Link to comment
Sha[D]ow Posted August 16, 2015 Author Share Posted August 16, 2015 شكرآ على الشرح اخ mr.r Link to comment
iMr.SFA7 Posted August 16, 2015 Share Posted August 16, 2015 اظن نبدآ ب sql light شف شرح الاخ برستيج فوق هذا لل SQLite عندك اي استفسار اسأل Link to comment
#Wizard Posted August 16, 2015 Share Posted August 16, 2015 اظن نبدآ ب sql light *lite Link to comment
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