XboxMS Posted November 26, 2015 Share Posted November 26, 2015 ابي كود او طريقة معينة تتحقق ان الرو موجود او لا في الكوليمن متلا لوكان عندي كوليمن اسمه playerName وابي اتاكد ان اسم اللاعب موجود او لا في الكولمين حتى ارسله رسالة في الشات تقوله ان اسمه موجود جربت الكود هدا : local database = dbConnect("sqlite","Player.db") function createTables() dbQuery(database,"CREATE TABLE IF NOT EXISTS players (playerName TEXT) ") end addEventHandler("onResourceStart",resourceRoot,createTables) function isPlayerNameExists(thePlayer) local isExists = dbQuery(database,"SELECT playerName FROM players") local result = dbPoll(isExists,-1) if result then for _,row in pairs(result) do for column, value in pairs ( row ) do if value == getPlayerName(thePlayer) then return false else return true end end end end end function addPlayerToDatabase () if isPlayerNameExists(source) == true then dbQuery(database,"INSERT INTO players (playerName) VALUES(?)",getPlayerName(source)) outputChatBox("You have added to the players database",source) elseif isPlayerNameExists(source) == false then outputChatBox("You're already in the column",source,255,0,0) else outputChatBox("another issues") end end Link to comment
</Mr.Tn6eL> Posted November 26, 2015 Share Posted November 26, 2015 الغلط هنا لانك اذ لقيت اسم الاعب ترجع قيمة false يعني كاذبة او خاطئة if value == getPlayerName(thePlayer) then return false else return true end والتصحيح return value == getPlayerName(thePlayer) استبدل التصحيح بالخاطئ Link to comment
</Mr.Tn6eL> Posted November 26, 2015 Share Posted November 26, 2015 او تفضل اختصرت عليك الاسطر function isPlayerNameExists(thePlayer) local isExists = dbQuery(database,"SELECT playerName FROM players WHERE playerName=?", getPlayerName(thePlayer)) local result = dbPoll(isExists,-1) return result["playerName"][1] end Link to comment
XboxMS Posted November 27, 2015 Author Share Posted November 27, 2015 الله يبارك فيك اخي الكود اللي عطتهلي ما اشتغل بشكل كامل لكن استفدت من المثال في function showPlayerMoney(thePlayer, command, playerName) local result = executeSQLQuery("SELECT money FROM players WHERE name=?", playerName) if(#result == 0) then outputConsole("No player named " .. playerName .. " is registered.", thePlayer) else outputConsole("Money amount of player " .. playerName .. " is " .. result[1].money, thePlayer) end end addCommandHandler("playermoney", showPlayerMoney) في executeSQLQuery Link to comment
</Mr.Tn6eL> Posted November 27, 2015 Share Posted November 27, 2015 اكتب باف 8 debugscript 3 وشوف الاخطاء Link to comment
ALw7sH Posted November 27, 2015 Share Posted November 27, 2015 function isPlayerNameExists(thePlayer) local isExists = dbQuery(database,"SELECT * FROM players WHERE playerName="..getPlayerName(thePlayer).."") local result = dbPoll(isExists,-1) return (result == "table" and #result > 0) and true or false end 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