Jump to content

مساعدة في الـ sqlite


XboxMS

Recommended Posts

ابي كود او طريقة معينة تتحقق ان الرو موجود او لا في الكوليمن

متلا لوكان عندي كوليمن اسمه 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

الغلط هنا لانك اذ لقيت اسم الاعب ترجع قيمة false

يعني كاذبة او خاطئة

if value == getPlayerName(thePlayer) then 
    return false 
else 
    return true 
end 

والتصحيح

return value == getPlayerName(thePlayer) 

استبدل التصحيح بالخاطئ

Link to comment

الله يبارك فيك اخي الكود اللي عطتهلي ما اشتغل بشكل كامل لكن استفدت من المثال في

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

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