Jump to content

Where to save top hunter data


drk

Recommended Posts

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

https://wiki.multitheftauto.com/wiki/Ser ... _functions or https://wiki.multitheftauto.com/wiki/Mysql

Structure:

Map_Name:time

1.If map finished insert to table ( if not one passing .Just you )

getResourceName( mapName )..':'..time

Example:Map_Name:time

dm_SomeMap:10000

if map have time and time now < time map just update table

2.Get time for dx or something

Example:Map_Name:time

dm_SomeMap:100

function getTimeFromMap( name ) 
    if name then 
        return tonumber( name:sub( name:find( ':' ) + 1,utfLen( name ) ) ) 
    end 
    return false 
end 
  
getTimeFromMap( 'dm_SomeMap:100' ) -- 100 
  

P.S I think this is very hardcore for you.

Edited by Guest
Link to comment

Hey, to update a row in MySQL using mysql_query is like this

    executeSQLQuery("UPDATE tableName SET column1 = ?,column2 = ?,column3 = ?,column4 = ? WHERE column1 = 'text1'", "text1", 1, "text2", 2) 

?

local query = mysql_query( connect, "UPDATE table SET column = ? WHERE column = 'Example'" ) 
  

Link to comment

It isn't creating tables :S Im doing something wrong?

connect = mysql_connect('%%%%%%', '%%%%%%', '%%%%%%', 'mtasa') 
aNewTable = mysql_query( connect, "CREATE TABLE IF NOT EXISTS `Top` ( map STRING, player STRING, time NUMBER ) " ) 
  
addEventHandler('onGamemodeMapStart',root, 
 function(mapname) 
    mapName = getResourceName(mapname) 
    if (aNewTable) then 
      local query = mysql_query( connect, "INSERT INTO `Top` SET map='"..mapName..", player='No Top', time='' " ) 
    end 
end) 
  
function addTop(thePlayer) 
 --settings 
 local player = mysql_escape_string(connect,getPlayerName(thePlayer)) 
 local time = exports.race:getTimePassed() 
  
 --update top 
   local query = mysql_query(connect, "UPDATE `Top` SET player='"..player.."', time='" .. time .. "' WHERE map='"..mapName.."'") 
   local result = mysql_query(connect, "SELECT player, time FROM `Top` WHERE map='"..mapName.."'") 
    outputChatBox('Top: ' .. result[1].player .. ' | Time: ' .. result[2].time,thePlayer) 
end 

I tried without `` but don't work too

Link to comment

I'm trying with SQL but it don't work anyway. It creates the table now, but don't do anything more and don't output nothing ( I put to output in the chat box the top and time but it don't output nothing )

table = executeSQLCreateTable( "Top", "map TEXT, player TEXT, time NUM" ) 
  
addEventHandler('onGamemodeMapStart',root, 
 function(mapname) 
    mapName = getResourceName(mapname) 
     result = executeSQLSelect ( "Top", "map", "map = '" ..mapName.. "'" ) 
     if result == false then 
      local query = executeSQLInsert( "Top", "'"..mapName.."', 'No one', ''" ) 
      local result = executeSQLSelect( "Top", "player, time", "map = '"..mapName.."'" ) 
      outputChatBox('Top: ' .. result[1][1] .. ' | Time: ' .. result[1][2],thePlayer) -- tried with source too but don't work  
    end 
end) 

Link to comment

Try

request = executeSQLQuery [[CREATE TABLE IF NOT EXISTS Top ( map TEXT, player TEXT, time TEXT )]] 
  
addEventHandler( 'onGamemodeMapStart',root, 
    function( mapname ) 
        local mapName = getResourceName( mapname ) 
        local result = executeSQLQuery ( "SELECT * Top WHERE map = '" ..mapName.. "'" ) 
        if not result or #result == 0 then -- not use result == false just use operator not you check ( if value nil or false )  
            executeSQLQuery( "INSERT INTO Top VALUES ('"..mapName.."','No one', '')" ) 
            local result = executeSQLQuery ( "SELECT * Top WHERE map = '" ..mapName.. "'" ) 
            outputChatBox( 'Top: ' .. tostring( result['map'] ).. ' | Time: ' ..tostring( result['time'] ) ) 
        else 
             
        end 
    end 
) 

Updated.

Link to comment

I tried this too:

request = executeSQLQuery ('CREATE TABLE IF NOT EXISTS Top ( map TEXT, player TEXT, time NUMBER )') 
  
addEventHandler( 'onGamemodeMapStart',root, 
    function( mapname ) 
        mapName = getResourceName( mapname ) 
        local result = executeSQLQuery ( "SELECT player, time FROM Top WHERE map = ?", mapName ) 
         if not result or #result == 0 then -- not use result == false just use operator not you check ( if value nil or false ) 
            executeSQLQuery( "INSERT INTO Top (map,player,time) VALUES('"..mapName.."','No one','')" ) 
            local result = executeSQLQuery ( "SELECT * FROM Top WHERE map = '"..mapName.."'" ) 
            outputChatBox( 'Top: ' ..result[1].player.. ' | Time: ' ..result[1].time,root,255,255,255,false) 
            outputChatBox('No top!',root,255,255,255,false) 
         end 
    end 
) 

Don't output nothing

Link to comment

My bad :/

Tested:

request = executeSQLQuery [[CREATE TABLE IF NOT EXISTS Top ( map TEXT, player TEXT, time TEXT )]] 
  
addEventHandler( 'onGamemodeMapStart',root, 
    function( mapname ) 
        local mapName = getResourceName( mapname ) 
        if mapName then 
            outputChatBox '1' 
            local result = executeSQLQuery ( "SELECT * FROM Top WHERE map = '" ..mapName.. "'" ) 
            if not result or #result == 0 then -- not use result == false just use operator not you check ( if value nil or false )  
                outputChatBox '2' 
                executeSQLQuery( "INSERT INTO Top VALUES ('"..mapName.."','No one', '')" ) 
                local resultt = executeSQLQuery ( "SELECT * FROM Top WHERE map = '" ..mapName.. "'" ) 
                outputChatBox( 'Top: ' .. tostring( resultt[1]['map'] ).. ' | Time: ' ..tostring( resultt[1]['time'] ) ) 
            else 
                outputChatBox '3' 
            end 
        end  
    end 
) 

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