Jump to content

event is not added serverside ERROR


Artisz

Recommended Posts

Hi guys!

I just want to practice the mysql save, and I downloaded a mod, where there is direct mistakes, and I can't fint they. In principle they are just erratums(or whatxD).

I written the whole server.lue file, because I don't know where is the error

And the Error messages:

http://kepfeltoltes.hu/160109/78780345N ... es.hu_.png

Sorry for bad English!

local mysql = exports.mysql 
local postable = {}
local regisztalhat = true
 
function playerRegister(player, username, password, password2)
    local md5password = md5(password)
    if(password~=password2)then
   
    triggerClientEvent("info",player,"A felhasználónév túl rövid!", "red")
        return
    end
    if(string.len(username)<5)then
        triggerClientEvent("info",player,"A felhasználónév túl rövid!", "red")
        return
    end
    if(string.len(password)<5)then
            triggerClientEvent("info", player, "A jelszó túl rövid!", "red")
        return
    end
        serial = getPlayerSerial(player)
        dbQuery(function(qh, player, username, md5password)
            local a, b, c = dbPoll(qh, 0)
            if b > 0 then
                outputChatBox("Neked már van accountod")
                regisztalhat = false
                return
            end        
        end, {player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0")
       
        dbQuery(function(qh, player, username, md5password)
            local result, rows, errorMsg = dbPoll(qh, 0)
            if not regisztalhat then return end
            if rows > 0 then
                exports.sg_box:addNotification("Ez a felhasználónév már foglalt!","red")
            else
                local _, id = mysql:query_free("INSERT INTO accounts SET serial = '".. serial .."', username = '"..tostring(username).."', password = '"..tostring(md5password).."'", true)
               
                exports.sg_box:addNotification("Sikeresen regisztráltál!","green")
            end
        end, {player,username,md5password}, mysql:getConnection(), "SELECT * FROM accounts WHERE username = ? LIMIT 1", username)
end)
addEvent("playerRegister", true)
addEventHandler("playerRegister", getRootElement(), playerRegister)
 
function playerLogin(player, username, password)
    password = md5(password)
 
       
        local query = mysql:singleQuery("SELECT * FROM accounts WHERE username = ? AND password = ? LIMIT 1", username, password)
        if query then   
 
            --local querys = mysql:singleQuery("SELECT serial FROM accounts WHERE username = ? LIMIT 1", username)
                        outputChatBox("[socialGaming] #FFFFFFSikeres bejelentkezés!",player,169,139,101,true)
                        setElementData(player, "accountID", query.id)
                        acc = getElementData(player, "accountID")
                        CharSelect(acc, player)
                        setElementData(player, "adminlevel", query.admin)
    else
        outputChatBox("[socialGaming] #FFFFFFSikertelen bejelentkezés!",player,177,9,45,true)
    end 
end
addEvent("playerLogin", true)
addEventHandler("playerLogin", getRootElement(), playerLogin)
 
addEvent("createCharacter", true)
addEventHandler("createCharacter", getRootElement(), function(p, nev, kor, suly, magassag, leiras, gender, color)
 
    acc = getElementData(p, "accountID")   
    local qh = dbQuery( mysql:getConnection(), "SELECT `charactername` FROM `karakterek` WHERE `charactername` = ?", tostring(a))
    local result = dbPoll ( qh, -1 )
    local count = 0
    local pw
    u = nil
    if result then
        for _, row in ipairs ( result ) do
            u = string.lower(row["charactername"])
        end
        if u ~= nil then
            exports.sg_box:createSmallNotification(client,"Már van ilyen karakter név, kérlek válassz másikat!", 1)
            return
        end
    end
    dbFree( qh )
    local user = getElementData(client, "username")
    qhh = dbExec( mysql:getConnection(), "INSERT INTO `karakterek` SET `charactername` = ?, `id` = ?, `skin` = 1, `kor` = ?, `suly` = ?, `magassag` = ?, `leiras` = ?, `gender` = ?,`color` = ? ", nev, acc, kor, suly, magassag, leiras, gender, color)
    if qhh then
        CharSelect(acc, p)
    end
end)
 
local postable = {}
 
function CharSelect(acc, source)
    local accid = getElementData(source,"accountID")
    local qh = dbQuery(mysql:getConnection(),"SELECT * FROM karakterek WHERE id = ? LIMIT 1", accid)
    local result, lineNumber = dbPoll ( qh, -1 )
    if(result) then
        if(lineNumber > 0) then
            for _, rows in ipairs( result ) do
                postable = {}
                level = rows["level"]
                xp = rows["xp"]
                jatszottpercek = rows["spentTime"]
                nev = rows["charactername"]
                anev = rows["adminnick"]               
                fraki = rows["faction"]
                frakir = rows["factionrank"]
                factionleader = rows["factionleader"]              
                skin = rows["skin"]
                dutyskin = rows["dutyskin"]            
                induty = rows["inDuty"] 
                kor = rows["kor"]          
                suly = rows["suly"]
                mag = rows["magassag"]
                job = rows["job"]              
                desc = rows["leiras"]
                gender = rows["gender"] 
                health = rows["health"]
                bankmoney = rows["bankmoney"]              
                keszpenz = rows["keszpenz"]            
                money = rows["money"]                  
                color = rows["color"]   
                pajzs = rows["pajzs"]                  
                ehesseg = rows["ehesseg"]                  
                maxvehicles = rows["maxvehicles"]              
                hasznaltkocsislot = rows["hasznaltkocsislot"]              
                premiumPont = rows["premiumPont"]              
                adminduty = rows["adminduty"]                  
                adminlevel = rows["adminlevel"]                
                pozicio = fromJSON(rows["pozicio"])
                postable = {pozicio[1],pozicio[2],pozicio[3],pozicio[4]}
                halal = rows["isDead"]
            end
                setPlayerName(source, string.gsub(nev, " ", "_"))
                setElementData(source, "charactername", nev)
                setElementData(source, "adminduty", 0)
                setElementData(source, "adminnick", anev)              
                spawnPlayer(source, postable[1], postable[2], postable[3], postable[4])
                setElementData(source, "logedin", true)
                setElementData(source, "jatszottpercek", jatszottpercek)
                setElementData(source, "faction", fraki)
                setElementData(source, "factionrank", frakir)   
                setElementData(source, "factionleader", factionleader)                 
                setElementData(source, "age", kor)
                setElementData(source, "gender", gender)
                setElementData(source, "bankmoney", bankmoney)
                setElementData(source, "keszpenz", keszpenz)
                setElementData(source, "adminduty", adminduty)
                setElementData(source, "adminlevel", adminlevel)
                setElementData(source, "premiumPont", premiumPont)
                setElementData(source, "xp", xp)
                setElementData(source, "level", level)
                if halal == 1 then
                    setElementHealth(source, 0)
                else
                    setElementHealth(source, health)
                end
                setElementData(source, "money", money)
                setElementData(source, "color", color)
                setPedArmor(source, pajzs)
                setElementData(source, "weight", suly)
                setElementData(source, "height", mag)
                setElementData(source, "desc", desc)
                setElementData(source, "job:id", job)
                setElementData(source, "ehesseg", ehesseg)                 
                setElementData(source, "maxvehicles", maxvehicles)                 
                setElementData(source, "hasznaltkocsislot", hasznaltkocsislot)                 
                setElementData(source, "normalskin", skin)
                setElementData(source, "dutyskin", dutyskin)
                setElementData(source, "inDuty", induty)
                if getElementData(source, "inDuty") then
                    actualskin =  getElementData(source, "dutyskin")
                else
                    actualskin = getElementData(source, "normalskin")
                end
                setElementModel(source, actualskin)            
--color health  ehesseg pajzs   spentTime   faction factionrank factionleader   maxVeh  maxInt             
                setCameraTarget(source)
                triggerClientEvent(source,"succes", source)
    else
            triggerClientEvent(source,"characterCreation", source)
        end
    end
end
 
 
addEventHandler("onPlayerQuit", getRootElement(), function()
    if getElementData(source, "logedin") then
        savePlayer(source)
    end
end)
 
function savePlayer(p)
    if isElement(p) then
        local x,y,z = getElementPosition(p)
        local rot = getPedRotation(p)
        local dbid = tonumber(getElementData(p, "accountID")) or 0
        local admin = tonumber(getElementData(p, "adminlevel")) or 0
        local position = toJSON({x,y,z,rot})
        local orak = getElementData(p, "jatszottpercek") or 0
        local faction = getElementData(p, "faction") or 0
        local hp = getElementHealth(p)
        local bankmoney = getElementData(p, "bankmoney")
        local keszpenz = getElementData(p, "keszpenz")
        local money = getElementData(p, "money")
        local armor = getPedArmor(p)
        local ehesseg = getElementData(p, "ehesseg")
        local skin = getElementData(p, "normalskin")
        local duty = getElementData(p, "inDuty")
        local dutyskin = getElementData(p, "dutyskin")
        local job = getElementData(p, "job:id")
        local maxvehicles = getElementData(p, "maxvehicles") or 4
        local hasznaltkocsislot = getElementData(p, "hasznaltkocsislot") or 0
        local premiumPont = getElementData(p, "premiumPont") or 0
        local xp = getElementData(p, "xp") or 0
        local level = getElementData(p, "level") or 0
       
        dbExec(mysql:getConnection(), "UPDATE karakterek SET pozicio = ?, spentTime = ?, faction = ?, health = ?, bankmoney = ?, money = ?, pajzs = ?, ehesseg = ?, skin = ?, job = ? WHERE ID = ?", position,  spentTime, faction, hp, bankmoney, money, armor, ehesseg, skin, job,  dbid)
        dbExec(mysql:getConnection(), "UPDATE karakterek SET maxvehicles = ?,hasznaltkocsislot = ?,premiumPont = ?, inDuty = ?, dutyskin = ?, keszpenz = ? WHERE ID = ?", maxvehicles,hasznaltkocsislot,premiumPont, duty, dutyskin,keszpenz,dbid)
        dbExec(mysql:getConnection(), "UPDATE accounts SET admin = ? WHERE ID = ?",admin,xp,level,dbid)
        dbExec(mysql:getConnection(), "UPDATE karakterek SET xp=?,level=? WHERE ID = ?",xp,level,dbid)
       
    end
end
addEvent("savePlayer", true)
addEventHandler("savePlayer", getRootElement(), savePlayer)
 
function saveAllPlayer()
    local count = 0
    for i, p in ipairs(getElementsByType("player")) do
        if (getElementData(p, "logedin") or false) then
            savePlayer(p)
            count = count + 1
        end
    end
    outputDebugString("Ellett mentve "..count.." jatekos adata!")
end
saveAllPlayer()
setTimer(saveAllPlayer, 1000*60*10, 0)
addCommandHandler("saveall",saveAllPlayer)
 
addEvent("checkPlayerBanState", true)
addEventHandler("checkPlayerBanState", getRootElement(),
    function(player)
        local serial = getPlayerSerial(player)
        local query = dbQuery(mysql:getConnection(),"SELECT * FROM banlist WHERE serial=?",serial)
        local qh = dbPoll(query, -1)
        local playerSerial, timeStamp, bannedBy, reason
        if #qh > 0 then
            for k, data in ipairs (qh) do
               
Link to comment

You've opened parenthesis and closed them in the end but didn't close the dbQuery parenthesis.

{player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0")

So change it too:

{player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0") 

Link to comment

I don't think so that I know what you saidxD Sorry

I try to close the dbQuery parenthesis like this:

dbQuery(function(qh, player, username, md5password) 
            local a, b, c = dbPoll(qh, 0) 
            if b > 0 then 
                outputChatBox("Neked már van accountod") 
                regisztalhat = false 
                return 
            end          
        end, {player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0") 
        ) 

And now I get this Error: sg_login\server.lua:1: exports: Call to non-running server resource (mysql) [string "?"]

And if I delete this changing, I get this error again, don't matter, what I am doing.

So I did something wrong, I guess.

And what am I doing with this line?

{player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0") 

I don't understand.

Link to comment

I found the "sg_functions" folder, there is a mysql.lua with the mysql connection.

The login script server.lua(there is the problem), start with this line:

  
local mysql = exports.mysql 

No i changed it:

local mysql = exports.sg_functions 

And now I get this Error:

ERROR: sg_login\server.lua:28: attempt to concatenate a boolean value 

The 28th line:

end, {player,username,md5password}, mysql:getConnection(), ("SELECT * FROM characters WHERE charactername='" .. safecharname .. "' AND account='" .. mysql:escape_string(id) .. "' AND cked = 0") 

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