Jump to content

again problem with db


Recommended Posts

Hi all,

I have an question and pls help me

-- I have an toptimes ...other tt ... and this tt need to have database .. is with name,time,flag,and date.

Problems:

-- Not save TT when close server ...

-- Not start automatically when player join

-- Not see when start an map

Look at console :

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:36: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:37: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:45: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:46: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:51: Bad argument @ 'dbFree' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:21: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:31: Bad argument @ 'dbFree' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:21: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:31: Bad argument @ 'dbFree' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:21: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:31: Bad argument @ 'dbFree' [Expected db-query at argument 1, got boolean]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:21: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got nil]

[2013-06-05 16:02:34] WARNING: [gamemodes]\[race]\[addons]\toptimy\toptime\t_server.lua:31: Bad argument @ 'dbFree' [Expected db-query at argument 1, got boolean]

TopTime image (toptimy) :

47191229.png

-- and in t_server.lua exists this line:

  
function startConnection() 
    ttHandler = dbConnect("mysql","dbname=;host=","","") 

pls help me in this last problem

Link to comment

-- t_server.lua

(Need to create an xampp database . phpmyadmin ? )

--[[ 
    Developer: Jake 
    Resource: Toptimes 
]]-- 
  
function startConnection() 
    ttHandler = dbConnect("mysql","dbname=;host=","","") 
    if ttHandler then 
        outputDebugString("Toptimes Connection to database successfull") 
    else 
        ttHandler = nil 
        outputDebugString("Toptimes can't connect to database") 
    end 
end 
  
startConnection() 
g_MapName = "-" 
  
function loadTimes(map) 
    local tts = {} 
    local query = dbQuery(ttHandler,"SELECT * FROM `toptimes` WHERE `mapname` = '"..tostring(map).."' LIMIT 0,1;") 
    if query then 
        local result, row = dbPoll(query,-1) 
        if result and row > 0 then 
            for id, res in ipairs(result) do 
                --outputChatBox("Works till here") 
                tts = fromJSON(res['toptimes']) 
            end 
        end 
    end 
    dbFree(query) 
    return tts 
end 
  
function saveTimes(time,map) 
    local query = dbQuery(ttHandler,"SELECT * FROM `toptimes` WHERE `mapname` = '"..tostring(map).."'") 
    local result = dbPoll( query, 10 )      
    if query and #result > 0 then 
        outputDebugString("Succesfully Loaded TopTime") 
        local exec = dbQuery(ttHandler,"UPDATE `toptimes` SET `toptimes` = '"..toJSON(time).."' WHERE `mapname` = '"..tostring(map).."'") 
        if exec ~= false then 
            outputDebugString("Updating Toptimes for '"..tostring(map)) 
        end 
    else 
        local querryb = dbQuery(ttHandler, "INSERT INTO toptimes (mapname,toptimes) VALUES (?,?)", tostring(map),toJSON(time)) 
        local resulbt = dbPoll( querryb, 10 )      
        if resulbt ~= false then 
            outputDebugString("Added Toptimes for '"..tostring(map)) 
        end 
    end 
    dbFree(query) 
end 
  
  
function sortToptimes(tabl) 
    local oldT = tabl[12] 
    table.sort(tabl, function(a,b) 
        return a.time < b.time 
    end) 
    local newT = tabl[12] 
    triggerClientEvent(root,"updateToptimesTable",root,tabl) 
    return tabl 
end 
  
  
function addNewToptime(ttable, accname, ttime, date, country) 
    for i,v in ipairs(ttable) do 
        if v.name == accname then 
            if v.time > ttime then 
                if v.date and v.country then 
                    v.time = ttime 
                    v.date = date 
                    v.country = country 
                    sortToptimes(ttable) 
                    return true 
                end 
            end 
            return false 
        end 
    end 
    local playertable = {} 
    playertable.name = accname 
    playertable.time = ttime 
    playertable.date = date 
    playertable.country = country 
    ttable[#ttable+1] = playertable 
    sortToptimes(ttable) 
    return true 
end 
  
function getPlayerTopTime(tts, player) 
    for id, v in ipairs(tts) do 
        if v.name == getPlayerName(player) then 
            local rtts = {} 
            rtts.name = v.name 
            rtts.i = id 
            rtts.time = msToTimeStr(v.time) 
            return rtts 
        end 
    end 
end 
  
gToptimes = false 
     
addEvent("onMapStarting") 
addEventHandler("onMapStarting", root, function(mapInfo) 
    local OldMap = g_MapName 
     
    if OldMap ~= mapInfo.name then 
        if gToptimes ~= false then 
            --outputChatBox(#gToptimes) 
            saveTimes(gToptimes,g_MapName) 
        end 
        gToptimes = false 
    end 
    g_MapName = mapInfo.name 
     
    if string.find(mapInfo.name,"[DM]") or string.find(mapInfo.name,"race-[DM]") then 
        for id, player in ipairs(getElementsByType("player")) do 
            if OldMap ~= mapInfo.name then 
                gToptimes = loadTimes(g_MapName) 
                triggerClientEvent(player,"doSendClientToptimes",root,player,gToptimes,g_MapName) 
            end 
        end 
    end 
end) 
  
addEvent("onPlayerPickUpRacePickup") 
addEventHandler("onPlayerPickUpRacePickup",root,function(id,sort,model) 
    if sort == "vehiclechange" then 
        if (model == 425) then 
            --if (getElementModel(getPedOccupiedVehicle(source))~= 425 ) then 
                local time = exports['race']:getTimePassed() 
                local name = getPlayerNametagText(source) 
                local t = getRealTime() 
                local ct 
                --outputChatBox(time) 
                local date = t.monthday.."."..(t.month+1).."."..(t.year+1900) 
                local country = exports['admin']:getPlayerCountry(source) 
                if country then 
                    ct = ':admin/client/images/flags/'..country..'.png' 
                else 
                    ct = "N/A" 
                end 
                addNewToptime(gToptimes,name,time,date,ct)  
                local t = getPlayerTopTime(gToptimes,source) 
                outputChatBox("#0087FF[HUNTER] #ffffff"..getPlayerName(source).." #ffffffmade a new toptime #0087FF"..t.time.." #ffffffand got position #0087FF"..t.i, getRootElement(), 255, 255, 255, true)  
            --end 
        end 
    end 
end) 
  
function removeToptime(player, cmd, i) 
    if tonumber(getElementData(player,"team")) >= 3 then 
        if not tonumber(i) or i == nil then outputChatBox("#0087FF[HUNTER] #ffffffThis was not a valid number", player, 255, 255, 255, true) return end 
        i = tonumber(i) 
        if gToptimes[i] then 
            table.remove(gToptimes,i) 
            sortToptimes(gToptimes) 
            outputChatBox("#0087FF[HUNTER] #ffffffYou deleted Toptime 0087FF#"..i, player, 255, 255, 255, true) 
        end 
    end 
end 
addCommandHandler("deletetime", removeToptime) 
     
function msToTimeStr(ms) 
    if not ms then 
        return '' 
    end 
    local centiseconds = tostring(math.floor(math.fmod(ms, 1000)/10)) 
    if #centiseconds == 1 then 
        centiseconds = '0' .. centiseconds 
    end 
    local s = math.floor(ms / 1000) 
    local seconds = tostring(math.fmod(s, 60)) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
    local minutes = tostring(math.floor(s / 60)) 
    return minutes .. ':' .. seconds .. ':' .. centiseconds 
end 

Link to comment
function startConnection() 
    ttHandler = dbConnect("mysql","dbname=(DB Name);host=localhost","root","(password)") 
    if ttHandler then 
        outputDebugString("Toptimes Connection to database successfull") 
    else 
        ttHandler = nil 
        outputDebugString("Toptimes can't connect to database") 
    end 
end 
  

Link to comment

replaced :

--[[ 
    Developer: Jake 
    Resource: Toptimes 
]]-- 
  
function startConnection() 
    ttHandler = dbConnect("mysql","dbname=(DB Name);host=localhost","root","(password)") 
    if ttHandler then 
        outputDebugString("Toptimes Connection to database successfull") 
    else 
        ttHandler = nil 
        outputDebugString("Toptimes can't connect to database") 
    end 
end 
  
startConnection() 
g_MapName = "-" 
  
function loadTimes(map) 
    local tts = {} 
    local query = dbQuery(ttHandler,"SELECT * FROM `toptimes` WHERE `mapname` = '"..tostring(map).."' LIMIT 0,1;") 
    if query then 
        local result, row = dbPoll(query,-1) 
        if result and row > 0 then 
            for id, res in ipairs(result) do 
                --outputChatBox("Works till here") 
                tts = fromJSON(res['toptimes']) 
            end 
        end 
    end 
    dbFree(query) 
    return tts 
end 
  
function saveTimes(time,map) 
    local query = dbQuery(ttHandler,"SELECT * FROM `toptimes` WHERE `mapname` = '"..tostring(map).."'") 
    local result = dbPoll( query, 10 )      
    if query and #result > 0 then 
        outputDebugString("Succesfully Loaded TopTime") 
        local exec = dbQuery(ttHandler,"UPDATE `toptimes` SET `toptimes` = '"..toJSON(time).."' WHERE `mapname` = '"..tostring(map).."'") 
        if exec ~= false then 
            outputDebugString("Updating Toptimes for '"..tostring(map)) 
        end 
    else 
        local querryb = dbQuery(ttHandler, "INSERT INTO toptimes (mapname,toptimes) VALUES (?,?)", tostring(map),toJSON(time)) 
        local resulbt = dbPoll( querryb, 10 )      
        if resulbt ~= false then 
            outputDebugString("Added Toptimes for '"..tostring(map)) 
        end 
    end 
    dbFree(query) 
end 
  
  
function sortToptimes(tabl) 
    local oldT = tabl[12] 
    table.sort(tabl, function(a,b) 
        return a.time < b.time 
    end) 
    local newT = tabl[12] 
    triggerClientEvent(root,"updateToptimesTable",root,tabl) 
    return tabl 
end 
  
  
function addNewToptime(ttable, accname, ttime, date, country) 
    for i,v in ipairs(ttable) do 
        if v.name == accname then 
            if v.time > ttime then 
                if v.date and v.country then 
                    v.time = ttime 
                    v.date = date 
                    v.country = country 
                    sortToptimes(ttable) 
                    return true 
                end 
            end 
            return false 
        end 
    end 
    local playertable = {} 
    playertable.name = accname 
    playertable.time = ttime 
    playertable.date = date 
    playertable.country = country 
    ttable[#ttable+1] = playertable 
    sortToptimes(ttable) 
    return true 
end 
  
function getPlayerTopTime(tts, player) 
    for id, v in ipairs(tts) do 
        if v.name == getPlayerName(player) then 
            local rtts = {} 
            rtts.name = v.name 
            rtts.i = id 
            rtts.time = msToTimeStr(v.time) 
            return rtts 
        end 
    end 
end 
  
gToptimes = false 
     
addEvent("onMapStarting") 
addEventHandler("onMapStarting", root, function(mapInfo) 
    local OldMap = g_MapName 
     
    if OldMap ~= mapInfo.name then 
        if gToptimes ~= false then 
            --outputChatBox(#gToptimes) 
            saveTimes(gToptimes,g_MapName) 
        end 
        gToptimes = false 
    end 
    g_MapName = mapInfo.name 
     
    if string.find(mapInfo.name,"[DM]") or string.find(mapInfo.name,"race-[DM]") then 
        for id, player in ipairs(getElementsByType("player")) do 
            if OldMap ~= mapInfo.name then 
                gToptimes = loadTimes(g_MapName) 
                triggerClientEvent(player,"doSendClientToptimes",root,player,gToptimes,g_MapName) 
            end 
        end 
    end 
end) 
  
addEvent("onPlayerPickUpRacePickup") 
addEventHandler("onPlayerPickUpRacePickup",root,function(id,sort,model) 
    if sort == "vehiclechange" then 
        if (model == 425) then 
            --if (getElementModel(getPedOccupiedVehicle(source))~= 425 ) then 
                local time = exports['race']:getTimePassed() 
                local name = getPlayerNametagText(source) 
                local t = getRealTime() 
                local ct 
                --outputChatBox(time) 
                local date = t.monthday.."."..(t.month+1).."."..(t.year+1900) 
                local country = exports['admin']:getPlayerCountry(source) 
                if country then 
                    ct = ':admin/client/images/flags/'..country..'.png' 
                else 
                    ct = "N/A" 
                end 
                addNewToptime(gToptimes,name,time,date,ct)  
                local t = getPlayerTopTime(gToptimes,source) 
                outputChatBox("#0087FF[HUNTER] #ffffff"..getPlayerName(source).." #ffffffmade a new toptime #0087FF"..t.time.." #ffffffand got position #0087FF"..t.i, getRootElement(), 255, 255, 255, true)  
            --end 
        end 
    end 
end) 
  
function removeToptime(player, cmd, i) 
    if tonumber(getElementData(player,"team")) >= 3 then 
        if not tonumber(i) or i == nil then outputChatBox("#0087FF[HUNTER] #ffffffThis was not a valid number", player, 255, 255, 255, true) return end 
        i = tonumber(i) 
        if gToptimes[i] then 
            table.remove(gToptimes,i) 
            sortToptimes(gToptimes) 
            outputChatBox("#0087FF[HUNTER] #ffffffYou deleted Toptime 0087FF#"..i, player, 255, 255, 255, true) 
        end 
    end 
end 
addCommandHandler("deletetime", removeToptime) 
     
function msToTimeStr(ms) 
    if not ms then 
        return '' 
    end 
    local centiseconds = tostring(math.floor(math.fmod(ms, 1000)/10)) 
    if #centiseconds == 1 then 
        centiseconds = '0' .. centiseconds 
    end 
    local s = math.floor(ms / 1000) 
    local seconds = tostring(math.fmod(s, 60)) 
    if #seconds == 1 then 
        seconds = '0' .. seconds 
    end 
    local minutes = tostring(math.floor(s / 60)) 
    return minutes .. ':' .. seconds .. ':' .. centiseconds 
end 

Edited by Guest
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...