Jump to content

Where to save top hunter data


drk

Recommended Posts

Posted

Im making a new top hunter and I don't know where I will save the top data to the map.

Can anyone helps me :?:

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Posted (edited)

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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'" ) 
  

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

I don't know if you can use the "?" in Ryden's MySQL.

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

What I don't know is what I put in column = 'Teste' and column = 'Example'

I don't know what is each one.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

Example:

local query = mysql_query( connect, "UPDATE `myTable` SET `money` = '5000' WHERE `accountName` = 'Castillo'" ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Ah, thank's dude :)

But I need ' ' before and after myTable?

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

"`" not "'".

I'm not sure, but I think you must.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

I don't know why xD

I will use these functions ..

Edit: executeSQL.. work with dbConnect or use internal.db?

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

No, use dbQuery, dbExec and so on.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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) 

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

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.

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

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 
) 

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

Thanks very much. It worked!

The wors part of the script is done xD

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

Only more one thing, race getTimePassed function return a string or number?

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

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