Jump to content

Problem sql to server


Recommended Posts

el topic 3andou 4 jours .. w7atta 7ad la3awnék : p

nans7ék témchi ll bord : scripting ..

médém l7kéya fiha sql :wink:

ena nji lil honi ken ki yabda 3andi problem moch moham barcha wala 3andi script masro9 :lol::lol::lol::lol:

hhhh, ena adhoukom man5dmch behom jemla, mana3rch ech ynaykou asl xD

hadhokma kima executeSQLQuery ma yalzmek tast3ml il dbConnect wa hadhi yast3mlouha chi iconncti 3ala file sqlite wala server mysql a3awka tawa ar9a il exmple :D

balahi tnajam trigli hadhi ? a3ika mafihach db

Datebase query failed: no such table: user_data

attempt to index local 'gangresult' (a boolean value)

function firstTime() 
    executeSQLQuery("CREATE TABLE IF NOT EXISTS newgangdb (gangname TEXT, money NUMERIC, hometext TEXT, inviteperm NUMERIC, motdperm NUMERIC, kickperm NUMERIC, levelperm NUMERIC, warnperm NUMERIC, depositperm NUMERIC, withdrawperm NUMERIC, deleteperm NUMERIC);")
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), firstTime)
 
function gangCreate(player, commandname, gangname, ...)
    if arg.n == 0 and gangname then
        local playeraccount = getPlayerAccount(player)
        local gangresult = executeSQLQuery ( "SELECT `gang` FROM `user_data` WHERE `username` = ?", playeraccount )
        local isingang = gangresult[1].gang
        if ( isingang == "false" ) then
            local existingGangsWithName = executeSQLQuery("SELECT * FROM `newgangdb` WHERE `gangname` = ?", gangname)
            if not existingGangsWithName[1] then
                executeSQLQuery("INSERT INTO newgangdb VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", gangname, 0, "Default home screen text, change me using the button below!", 5, 5, 5, 5, 5, 0, 5, 5)
               
                executeSQLQuery("UPDATE `user_data` SET `gang`=? WHERE `username`=?", gangname, playeraccount )
               
                local dbName = "newgang_" .. gangname .. "_members"
                executeSQLQuery("CREATE TABLE ? (accountname TEXT, lastname TEXT, lastlogin NUMERIC, warnings NUMERIC, level NUMERIC)", dbName )
               
                local realTime = getRealTime()
                local timestamp = realTime.year + 1900 .. "-" .. realTime.month + 1 .. "-" .. realTime.monthday
 
                executeSQLQuery("INSERT INTO ? VALUES(?, ?, ?, ?, ?)", dbName, getAccountName(playerAccount), getPlayerName(player), timestamp, 0, 5)
                setAccountData(playerAccount, "gang", gangname)
               
           
                outputChatBox("**INFO: "..getPlayerName(player).." is now in "..gangname.." **")
 
                outputChatBox("Gang successfully created. Use /gang for gangpanel.", player, 0, 255, 0)
            else
                outputChatBox("A gang with this name already exists.", player, 255, 0, 0)
            end
        else
            outputChatBox("You must leave your current gang to create a new one.", player, 255, 0, 0)
        end
    else
        outputChatBox("Invalid arguments. Gang name can't contain spaces.", player, 255, 0, 0)
    end
end
addCommandHandler("create", gangCreate)
 
function gangPanel(player)
    local playeraccount = getPlayerAccount(player)
    local gangresult = executeSQLQuery ( "SELECT `gang` FROM `user_data` WHERE `username` = ?", playeraccount )
    local isingang = gangresult[1].gang
    if isingang then
        triggerClientEvent(player, "displayPanel", player)
        populateGangPanel(player)
    else
   
        outputChatBox("* INFO: You are not in a Gang type /create to create a gang *",player,255,0,0)
       
    end
end
addCommandHandler("gang", gangPanel)
addCommandHandler("squad", gangPanel)
addCommandHandler("company", gangPanel)
 
function populateGangPanel(player)
    --local playerAccount = getPlayerAccount(player)
    --local gangname = getAccountData(playerAccount, "gang")
    local playeraccount = getPlayerAccount(player)
    local gangnameresult = executeSQLQuery ( "SELECT `gang` FROM `user_data` WHERE `username` = ?", playeraccount )
    local gangname = gangnameresult[1].gang
       
    local dbName = "newgang_" .. gangname .. "_members"
       
    local ganginfo = executeSQLQuery("SELECT * FROM `newgangdb` WHERE `gangname` = ?", gangname)
    local memberinfo = executeSQLQuery("SELECT * FROM ?", dbName)
 
    triggerClientEvent(player, "populatePanel", player, ganginfo[1], memberinfo, getAccountName(getPlayerAccount(player)))
end
 
function getPlayerLevel(player)
    local playeraccount = getPlayerAccount(player)
    local gangnameresult = executeSQLQuery ( "SELECT `gang` FROM `user_data` WHERE `username` = ?", playeraccount )
    local gangname = gangnameresult[1].gang
    if gangname then
        local dbName = "newgang_" .. gangname .. "_members"
        local playerinfo = executeSQLQuery("SELECT * FROM ? WHERE `accountname` = ?", dbName, playerAccountName)
        return playerinfo[1]["level"]
    else
        return false
    end
end
 
function getPlayerGang(player)
    local playeraccount = getPlayerAccount(player)
    local gangnameresult = executeSQLQuery ( "SELECT `gang` FROM `user_data` WHERE `username` = ?", playeraccount )
    local gangname = gangnameresult[1].gang
    return gangname
end
 
function getGangInfo(gangname)
    local ganginfo = executeSQLQuery("SELECT * FROM `newgangdb` WHERE `gangname` = ?", gangname)
    if ganginfo[1] then
        return ganginfo[1]
    else
        return false
    end
end
 
-- ALL THE HANDLER FUNCTIONS ARE HERE!
 
function saveMOTD(motd)
    if getPlayerGang(source) then
        local ganginfo = getGangInfo(getPlayerGang(source))
        local playerlevel = getPlayerLevel(source)
        if playerlevel >= tonumber(ganginfo['motdperm']) then
            executeSQLQuery("UPDATE `newgangdb` SET `hometext` = ? WHERE `gangname` = ?",motd, getPlayerGang(source))
            populateGangPanel(source)
        end
    end
end
addEvent("_saveMOTD", true)
addEventHandler("_saveMOTD", getRootElement(), saveMOTD)
 
function levelPlayer(accountname)
    if getPlayerGang(source) then
        local ganginfo = getGangInfo(getPlayerGang(source))
        local playerlevel = getPlayerLevel(source)
        if playerlevel >= tonumber(ganginfo['levelperm']) then
            local dbName = "newgang_" .. ganginfo['gangname'] .. "_members"
            local playerTo = executeSQLQuery("SELECT * FROM ? WHERE `accountname`=?", dbName, accountname)
            if playerTo[1] then
                if playerlevel > (tonumber(playerTo[1]['level']) + 1) and tonumber(playerTo[1]['level']) < 5 then
                    local newlevel = tonumber(playerTo[1]['level']) + 1
                    executeSQLQuery("UPDATE ? SET `level` = ? WHERE `accountname` = ?", dbName, newlevel, accountname)
                    populateGangPanel(source)
                else
                    triggerClientEvent(source, "errorDisplay", source, "Error: You can't touch players equal to/over your level.")
                end
            else
                triggerClientEvent(source, "errorDisplay", source, "Error: Can not find player.")
                populateGangPanel(source)
            end
        end
    end
end
addEvent("_levelPlayer", true)
addEventHandler("_levelPlayer", getRootElement(), levelPlayer)
 
function unlevelPlayer(accountname)
    if getPlayerGang(source) then
        local ganginfo = getGangInfo(getPlayerGang(source))
        local playerlevel = getPlayerLevel(source)
        if playerlevel >= tonumber(ganginfo['levelperm']) then
            local dbName = "newgang_" .. ganginfo['gangname'] .. "_members"
            local playerTo = executeSQLQuery("SELECT * FROM ? WHERE `accountname`=?", dbName, accountname)
            if playerTo[1] then
                if playerlevel > tonumber(playerTo[1]['level']) and tonumber(playerTo[1]['level']) > 0 then
                    local newlevel = tonumber(playerTo[1]['level']) - 1
                    executeSQLQuery("UPDATE ? SET `level` = ? WHERE `accountname` = ?", dbName, newlevel, accountname)
                    populateGangPanel(source)
                else
                    triggerClientEvent(source, "errorDisplay", source, "Error: You can't touch players equal to/over your level.")
                end
            else
                triggerClientEvent(source, "errorDisplay", source, "Error: Can not find player.")
                populateGangPanel(source)
            end
        end
    end
end
addEvent("_unlevelPlayer", true)
addEventHandler("_unlevelPlayer", getRootElement(), unlevelPlayer)
 
function warnPlayer(accountname)
    if getPlayerGang(source) then
        local ganginfo = getGangInfo(getPlayerGang(source))
        local playerlevel = getPlayerLevel(source)
        if playerlevel >= tonumber(ganginfo['levelperm']) then
            local dbName = "newgang_" .. ganginfo['gangname'] .. "_members"
            local playerTo = executeSQLQuery("SELECT * FROM ? WHERE `accountname`=?", dbName, accountname)
            if playerTo[1] then
                if playerlevel > tonumber(playerTo[1]['level']) and tonumber(playerTo[1]['warnings']) < 5 then
                    local newwarn = tonumber(playerTo[1]['warnings']) + 1
                    executeSQLQuery("UPDATE ? SET `warnings` = ? WHERE `accountname` = ?", dbName, newwarn, accountname)
                    populateGangPanel(source)
                else
                    triggerClientEvent(source, "errorDisplay", source, "Error: You can't touch players equal to/over your level.")
                end
            else
                triggerClientEvent(source, "errorDisplay", source, "Error: Can not find player.")
                populateGangPanel(source)
            end
        end
    end
end
addEvent("_warnPlayer", true)
addEventHandler("_warnPlayer", getRootElement(), warnPlayer)
 
function unwarnPlayer(accountname)
    if getPlayerGang(source) then
        local ganginfo = getGangInfo(getPlayerGang(source))
        local playerlevel = getPlayerLevel(source)
        if playerlevel >= tonumber(ganginfo['levelperm']) then
            local dbName = "newgang_" .. ganginfo['gangname'] .. "_members"
            local playerTo = executeSQLQuery("SELECT * FROM ? WHERE `accountname`=?", dbName, accountname)
            if playerTo[1] then
                if playerlevel > (tonumber(playerTo[1]['level'])) and tonumber(playerTo[1]['warnings']) > 0 then
                    local newwarn = tonumber(playerTo[1]['warnings']) - 1
                    executeSQLQuery("UPDATE ? SET `warnings` = ? WHERE `accountname` = ?", dbName, newwarn, accountname)
                    populateGangPanel(source)
                else
                    triggerClientEvent(source, "errorDisplay", source, "Error: You can't touch players equal to/over your level.")
                end
            else
                triggerClientEvent(source, "errorDisplay", source, "Error: Can not find player.")
                populateGangPanel(source)
            end
        end
    end
end
addEvent("_unwarnPlayer", true)
addEventHandler("_unwarnPlayer", getRootElement(), unwarnPlayer)
 
function depositMoney(money)
    if tonumber(money) > 0 then
        if getPlayerGang(source) then
            local ganginfo = getGangInfo(getPlayerGang(source))
            local playerlevel = getPlayerLevel(source)
            if playerlevel >= tonumber(ganginfo['depositperm']) then
                local newmoney = tonumber(ganginfo['money']) + tonumber(money)
                if getPlayerMoney(source) >= tonumber(money) then
                    executeSQLQuery("UPDATE `newgangdb` SET `money` = ? WHERE `gangname` = ?", newmoney, getPlayerGang(source))
                    takePlayerMoney(source, tonumber(money))
                    populateGangPanel(source)
                else
                    triggerClientEvent(source, "errorDisplay", source, "Error: You don't have enough money.")
                    populateGangPanel(source)
                end
            end
        end
    end
end
addEvent("_depositMoney", true)
addEventHandler("_depositMoney", getRootElement(), depositMoney)
 
function withdrawMoney(money)
    if tonumber(money) > 0 then
        if getPlayerGang(source) then
            local ganginfo = getGangInfo(getPlayerGang(source))
            local playerlevel = getPlayerLevel(source)
            if playerlevel >= tonumber(ganginfo['withdrawperm']) then
                local newmoney = tonumber(ganginfo['money']) - tonumber(money)
                if tonumber(ganginfo['money']) >= tonumber(money) then
                    executeSQLQuery("UPDATE `newgangdb` SET `money` = ? WHERE `gangname` = ?", newmoney, getPlayerGang(source))
                    givePlayerMoney(source, tonumber(money))
                    populateGangPanel(source)
               
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...