Jump to content

SQLite


Recommended Posts

شباب أنا مبتدأ بالبرمجة وشفت شروحات يقولو ان SQLite مهم في كل سيرفر المهم ..

ابغي احد يعطيني رابط التحميل والتركيب

ويعطيني الفنكنشات

اللازمة حقته يعني مثلا : addEventHandler . getElementModel

لاني جربت House_system

ما اشتغل بسبب قاعدة البيانات

وكذا فياليت محد يبخل علي

ويعطيكم الف عافية

وشكراا....

Link to comment
مثال تسوي نظام حفظ الاحداثيات بـ 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
مل شيئ عندي وسويت زي الفيدي بس المشكلة اي احد يدخل السيرفر الدمنيشن 0 وكله 0

كلأمك مهو واضحح

بس اللي فهمته منك انه اي احد يدخل او كل السيرفر بـ دمنيشن 0

طيب ؟ , شي أكيد يكون بـ 0 لأنه في فنكشن تحط اللاعب بـ دمنيشن ويمديك تحط كل اللاعب بـ دمنيشين محدد هو بكون 0 بـ العالم الحقيقي اككيد .

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