drk Posted February 10, 2012 Posted February 10, 2012 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
Kenix Posted February 10, 2012 Posted February 10, 2012 (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 February 10, 2012 by Guest http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted February 10, 2012 Author Posted February 10, 2012 I know that isn't easy but I want to try EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 10, 2012 Posted February 10, 2012 I know that isn't easy but I want to try Good luck! http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted February 10, 2012 Author Posted February 10, 2012 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
Castillo Posted February 10, 2012 Posted February 10, 2012 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. Education is the most powerful weapon which you can use to change the world.
drk Posted February 10, 2012 Author Posted February 10, 2012 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
Castillo Posted February 10, 2012 Posted February 10, 2012 Example: local query = mysql_query( connect, "UPDATE `myTable` SET `money` = '5000' WHERE `accountName` = 'Castillo'" ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
drk Posted February 10, 2012 Author Posted February 10, 2012 Ah, thank's dude But I need ' ' before and after myTable? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Castillo Posted February 10, 2012 Posted February 10, 2012 "`" not "'". I'm not sure, but I think you must. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
drk Posted February 10, 2012 Author Posted February 10, 2012 Thanks Kenix and Solidsnake14. EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted February 10, 2012 Author Posted February 10, 2012 It isn't creating tables 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
Castillo Posted February 10, 2012 Posted February 10, 2012 Just wondering: Why don't you use the DB functions? https://wiki.multitheftauto.com/wiki/DbConnect San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
drk Posted February 10, 2012 Author Posted February 10, 2012 I don't know why I will use these functions .. Edit: executeSQL.. work with dbConnect or use internal.db? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Castillo Posted February 10, 2012 Posted February 10, 2012 No, use dbQuery, dbExec and so on. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
drk Posted February 11, 2012 Author Posted February 11, 2012 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
Kenix Posted February 11, 2012 Posted February 11, 2012 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.
drk Posted February 11, 2012 Author Posted February 11, 2012 Wrong code EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted February 11, 2012 Author Posted February 11, 2012 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
Kenix Posted February 11, 2012 Posted February 11, 2012 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.
drk Posted February 11, 2012 Author Posted February 11, 2012 Thanks very much. It worked! The wors part of the script is done EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted February 11, 2012 Author Posted February 11, 2012 Only more one thing, race getTimePassed function return a string or number? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 11, 2012 Posted February 11, 2012 Thanks very much. It worked! No problem race getTimePassed function return a string or number? Number https://wiki.multitheftauto.com/wiki/RU/Resource:Race http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted February 11, 2012 Author Posted February 11, 2012 Thanks EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 11, 2012 Posted February 11, 2012 No problem http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now