MA[S]RIY Posted June 22, 2017 Share Posted June 22, 2017 السلام عليكم ذا كود حفظ فلوس م زبط معي بالرغم من م يطلع اخطاء بالدي بق addEventHandler ("onResourceStart",root, function () executeSQLQuery("CREATE TABLE IF NOT EXISTS datanamee ( money, account )") end ) ------------- addEventHandler("onPlayerLogin", getRootElement(), function ( source ) Pmoney = getPlayerMoney ( source ) Paccount = getAccountName( getPlayerAccount( source ) ) executeSQLQuery("INSERT INTO datanamee( money, account ) VALUES(?, ?)",Pmoney, Paccount ) end ) ----------- addEventHandler("onPlayerQuit", getRootElement(), function ( source ) Pmoney = getPlayerMoney ( source ) Paccount = getAccountName( getPlayerAccount( source ) ) if Paccount and not isGuestAccount ( account ) then executeSQLQuery("UPDATE datanamee SET money=? WHERE account=?", Pmoney, Paccount ) end end ) -------- addEventHandler("onPlayerLogin", getRootElement(), function ( source ) Pmoney = getPlayerMoney ( source ) Paccount = getAccountName( getPlayerAccount( source ) ) executeSQLQuery("SELECT money FROM datanamee WHERE account = ?", Paccount ) setPlayerMoney(source,Pmoney) end ) Link to comment
` Allawi Posted June 22, 2017 Share Posted June 22, 2017 أستخدم الوظائف بالطريقة الصحيحة Link to comment
Dr.Marco Posted June 22, 2017 Share Posted June 22, 2017 ما يحتاج sql استخدم getAccountData setAccountData Link to comment
MA[S]RIY Posted June 22, 2017 Author Share Posted June 22, 2017 ابي احد يعدلي ع كودي علشان اتعلم واعرف بغلط ف ايه ؟ Link to comment
Mhmd.z Posted June 22, 2017 Share Posted June 22, 2017 onPlayerLogin ليش حاط حدثين ؟ اتوقع مشكلتك منه لآنه في اول حدث رح يضيف انه فلوس الاعب هي 0 بعدها الحدث الثاني رح يجيب الفلوس يلي هي 0 ويعطيك ياها , شيل الحدث الاول : هذا addEventHandler("onPlayerLogin", getRootElement(), function ( source ) Pmoney = getPlayerMoney ( source ) Paccount = getAccountName( getPlayerAccount( source ) ) executeSQLQuery("INSERT INTO datanamee( money, account ) VALUES(?, ?)",Pmoney, Paccount ) end ) Link to comment
#BrosS Posted June 23, 2017 Share Posted June 23, 2017 (edited) local save = dbConnect( "sqlite", "save.db" ) dbExec(save, "CREATE TABLE IF NOT EXISTS saveData ( AccountName, Money)") function saveMoney (player) local Account = getPlayerAccount(player) if Account and not isGuestAccount (Account) then local Money = getPlayerMoney(player) dbExec(save, "UPDATE saveData SET Money = ? WHERE AccountName = ?",Money, getAccountName(Account) ) end end function loadMoney( player ) local account = getPlayerAccount(player) if account and not isGuestAccount(account) then local result = dbPoll(dbQuery(save, "SELECT * FROM saveData WHERE AccountName = ? ", getAccountName(account)), -1) if #result > 0 then givePlayerMoney(player,result[1]["Money"]) end end end addEventHandler("onPlayerQuit",root, function() saveMoney(source) end) addEventHandler("onPlayerLogin",root, function() loadMoney(source) end) addEventHandler("onResourceStop", root, function(res) if res == getThisResource() then for i , v in pairs (getElementsByType("player") ) do saveMoney(v) end end end) غير مجرب Edited June 23, 2017 by #BrosS Link to comment
` Allawi Posted June 23, 2017 Share Posted June 23, 2017 (edited) addEventHandler ( "onResourceStart", resourceRoot, function ( ) executeSQLQuery ( "CREATE TABLE IF NOT EXISTS datanamee ( money, account )" ) end ) addEventHandler("onPlayerLogin", root, function ( _, playeraccount ) local result = executeSQLQuery ( "SELECT money FROM datanamee WHERE account=?", getAccountName ( playeraccount ) ) if ( #result ~= 0 ) then setPlayerMoney ( source, result[1].money ) end end ) addEventHandler ( "onPlayerQuit", root, function ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local playermoney = getPlayerMoney ( source ) local result = executeSQLQuery ( "SELECT money FROM datanamee WHERE account=?", getAccountName ( playeraccount ) ) if ( #result == 0 ) then executeSQLQuery ( "INSERT INTO datanamee ( account, money ) VALUES ( ?, ? )", getAccountName ( playeraccount ), playermoney ) else executeSQLQuery ( "UPDATE datanamee SET money=? WHERE account=?", playermoney, getAccountName ( playeraccount ) ) end end end ) جرب .. Edited June 23, 2017 by ` Allawi Link to comment
MA[S]RIY Posted June 23, 2017 Author Share Posted June 23, 2017 شكرا اخي تمت الافاده شكرا للجميع Link to comment
#kAsR Posted June 23, 2017 Share Posted June 23, 2017 لـ ألافأدة احسن تستخدم حدث onResourceStop + onResourceStart عشان لو طفيت المود يحفظ الفلوس ويوم تشغل المود ترجع الفلوس Link to comment
` Allawi Posted June 23, 2017 Share Posted June 23, 2017 3 hours ago, MARIY said: شكرا اخي تمت الافاده شكرا للجميع عفواً حياك الله .. Link to comment
A7M8D Posted June 24, 2017 Share Posted June 24, 2017 function onPlayerQuit ( ) -- when a player leaves, store his current money amount in his account data local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in local playermoney = getPlayerMoney ( source ) -- get the player money setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account end end function onPlayerLogin (_, playeraccount ) -- when a player logins, retrieve his money amount from his account data and set it if ( playeraccount ) then local playermoney = getAccountData ( playeraccount, "piraterpg.money" ) -- make sure there was actually a value saved under this key (check if playermoney is not false). -- this will for example not be the case when a player plays the gametype for the first time if ( playermoney ) then setPlayerMoney ( source, playermoney ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) مثال بسيط من الويكي Link to comment
Dr.Marco Posted June 24, 2017 Share Posted June 24, 2017 (edited) 1 hour ago, #MR.NaiF said: function onPlayerQuit ( ) -- when a player leaves, store his current money amount in his account data local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in local playermoney = getPlayerMoney ( source ) -- get the player money setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account end end function onPlayerLogin (_, playeraccount ) -- when a player logins, retrieve his money amount from his account data and set it if ( playeraccount ) then local playermoney = getAccountData ( playeraccount, "piraterpg.money" ) -- make sure there was actually a value saved under this key (check if playermoney is not false). -- this will for example not be the case when a player plays the gametype for the first time if ( playermoney ) then setPlayerMoney ( source, playermoney ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) مثال بسيط من الويكي هوي يبي ب SQL وليس بالفنكشات لي عطيته + شبااب ساعدوه Edited June 24, 2017 by Dr.Marco 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