orcun99 Posted February 14, 2018 Share Posted February 14, 2018 (edited) banking script server side function getPlayerBankBalance(player) if not player or not isElement(player) or getElementType(player) ~= "player" then return 0 end local account = getPlayerAccount(player) if not account then return 0 end return tonumber(getAccountData(account, "money")) or 0 end function getAccountBankBalance(player) if not player then return 0 end local account = getAccount(player) if not account then return 0 end return tonumber(getAccountData(account, "money")) or 0 end addEvent("getPlayerBankBalance",true) addEventHandler("getPlayerBankBalance",root,getPlayerBankBalance) I want to data transfer in my sql database my code addEventHandler("onResourceStart", resourceRoot, function() executeSQLQuery("CREATE TABLE IF NOT EXISTS `hesaplar`(ip TEXT, serial TEXT, id TEXT, sifre TEXT, banka TEXT)") setTimer(echoMsg, 240000, 0) end) function PlayerLogin(username,password,checksave) if not (username == "") then if not (password == "") then local account = getAccount ( username, password ) local ip = getPlayerIP(source) local serial = getPlayerSerial(source) local banka = exports.banking:getPlayerBankBalance(source) if ( account ~= false ) then logIn(source, account, password) executeSQLQuery("INSERT INTO `hesaplar` VALUES(?,?,?,?,?,?)", ip, serial, username, password,banka) this code is working but wrong bank balance alwasy balance : 0 but its not true myingame bank balance: 100.000 database>hesaplar>banka = 0 Edited February 14, 2018 by orcun99 Link to comment
LLCoolJ Posted February 14, 2018 Share Posted February 14, 2018 (edited) function isAccountExists(serialToCheck) local data = executeSQLQuery("SELECT * FROM hesaplar") if type(data) == "table" and #data ~= 0 then for k,v in ipairs(data) do if v.serial == serialToCheck then return true end end end return false end function PlayerLogin(username,password,checksave) if not (username == "") then if not (password == "") then local account = getAccount ( username, password ) local ip = getPlayerIP(source) local serial = getPlayerSerial(source) if ( account ~= false ) then logIn(source, account, password) local banka = exports.banking:getPlayerBankBalance(source) if not isAccountExists(serial) then executeSQLQuery("INSERT INTO hesaplar(ip,serial,id,sifre,banka) VALUES(?,?,?,?,?)", ip, serial, username, password,banka) else executeSQLQuery("UPDATE hesaplar SET id=?,sifre=?,banka=? WHERE serial=?",username,password,banka,serial) end triggerClientEvent (source,"hideLoginWindow",getRootElement()) triggerEvent("onPlayerLogIn", source) triggerClientEvent(source,"onPlayerLoginSuccess", source) setElementData(source,"loggedIn", true) setElementData(source,"username", getAccountName(account)) setElementData(source, "gang", getAccountData(account, "gang")) local realTime = getRealTime() local month = tostring(realTime.month + 1) local monthday = tostring(realTime.monthday) if #month == 1 then month = "0" .. month end if #monthday == 1 then monthday = "0" .. monthday end local timestamp = realTime.year + 1900 .. "-" .. month .. "-" .. monthday setAccountData(account, "lastlogin", timestamp) if checksave == true then triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password) else triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password) end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Hatalı Kullanıcı adı / şifre!") end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Şifreni Gir!") end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Kullanıcı Adını Gir!") end end addEvent("onRequestLogin",true) addEventHandler("onRequestLogin",getRootElement(),PlayerLogin) Try this Edited February 14, 2018 by IRBIS 1 Link to comment
orcun99 Posted February 14, 2018 Author Share Posted February 14, 2018 thank u very much worksss 2 hours ago, IRBIS said: function isAccountExists(serialToCheck) local data = executeSQLQuery("SELECT * FROM hesaplar") if type(data) == "table" and #data ~= 0 then for k,v in ipairs(data) do if v.serial == serialToCheck then return true end end end return false end function PlayerLogin(username,password,checksave) if not (username == "") then if not (password == "") then local account = getAccount ( username, password ) local ip = getPlayerIP(source) local serial = getPlayerSerial(source) if ( account ~= false ) then logIn(source, account, password) local banka = exports.banking:getPlayerBankBalance(source) if not isAccountExists(serial) then executeSQLQuery("INSERT INTO hesaplar(ip,serial,id,sifre,banka) VALUES(?,?,?,?,?)", ip, serial, username, password,banka) else executeSQLQuery("UPDATE hesaplar SET id=?,sifre=?,banka=? WHERE serial=?",username,password,banka,serial) end triggerClientEvent (source,"hideLoginWindow",getRootElement()) triggerEvent("onPlayerLogIn", source) triggerClientEvent(source,"onPlayerLoginSuccess", source) setElementData(source,"loggedIn", true) setElementData(source,"username", getAccountName(account)) setElementData(source, "gang", getAccountData(account, "gang")) local realTime = getRealTime() local month = tostring(realTime.month + 1) local monthday = tostring(realTime.monthday) if #month == 1 then month = "0" .. month end if #monthday == 1 then monthday = "0" .. monthday end local timestamp = realTime.year + 1900 .. "-" .. month .. "-" .. monthday setAccountData(account, "lastlogin", timestamp) if checksave == true then triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password) else triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password) end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Hatalı Kullanıcı adı / şifre!") end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Şifreni Gir!") end else triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Lütfen Kullanıcı Adını Gir!") end end addEvent("onRequestLogin",true) addEventHandler("onRequestLogin",getRootElement(),PlayerLogin) Try this 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