Raised This Month: $ Target: $400
 0% 

[Help - SQL] Saving Timer vallue's


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-29-2012 , 11:43   [Help - SQL] Saving Timer vallue's
Reply With Quote #1

I made a Timer plugin and i now I added mysql saving to it but my table is not being created.
my sql database information and login are all correct, triple checked and the plugin is running and not set into bad load.

Could anyone pls take a look? I'm out of idea's


I used this tutorial for the mysql saving.
Attached Files
File Type: sma Get Plugin or Get Source (1MsTimer.sma - 156 views - 6.6 KB)
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 08-29-2012 , 12:13   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #2

I don't see you using MySql_Init() anywhere...

And why do you need all minutes, seconds, milliseconds in your table? You could only save seconds and turn them into minutes, seconds and milliseconds when you load them from SQL.
__________________

Accepting all kinds of requests via private message.

Last edited by matsi; 08-29-2012 at 12:13.
matsi is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-29-2012 , 16:31   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #3

- What are you talking about? mysql_init is placed right after plugin_init.

- Yes that's true but i'm not sure if it would work, didnt really tough about that at the time. but my milisecond timer (g_icounter) resets to 0 every 1000ms or 1second.
and seconds reset to 0 at 1 minute so saving only the seconds wouldnt work the way i coded the plugin like it is now
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 08-29-2012 , 16:48   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #4

Quote:
Originally Posted by striker07 View Post
- What are you talking about? mysql_init is placed right after plugin_init.

- Yes that's true but i'm not sure if it would work, didnt really tough about that at the time. but my milisecond timer (g_icounter) resets to 0 every 1000ms or 1second.
and seconds reset to 0 at 1 minute so saving only the seconds wouldnt work the way i coded the plugin like it is now
You've created MySql_Init() but you never use it... Its not part of the Sql module. You must call it like any other function.

What are you really trying to do? If you're just looking for a timer with milliseconds check this out:
http://forums.alliedmods.net/showpos...85&postcount=6
__________________

Accepting all kinds of requests via private message.
matsi is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-29-2012 , 18:25   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #5

Aha, i see i forgot to set the mysql_init taks in plugin_init and the public function IgnoreHandle.
I will update it when i got home and see what that gives.

what i am trying to do is save record roundtimes into sql, my endgoal is to proces that plugin into another plugin i made to extend the gameplay.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-30-2012 , 11:32   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #6

Ok so this is what i have now, the table is now created in my database but there are no values inside, when actually when a new map is loaded without records in it yet it should save these vallues: 99min 99 secs 999 ms but its not saving those vallues or even registering the map in the table

PHP Code:
        format(szTemp,charsmax(szTemp),"INSERT INTO `AM_recordtimes` ( `mapid` , `minutes`, 'seconds', 'miliseconds')VALUES ('%s','99', '99', '999');",szMapId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp
Spoiler
Attached Files
File Type: sma Get Plugin or Get Source (1MsTimer.sma - 177 views - 6.8 KB)
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 08-30-2012 at 11:36.
striker07 is offline
Infernuz
Member
Join Date: May 2011
Old 08-30-2012 , 16:30   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #7

1. That's because you have an error in your Insert query. Find 5 differences, lol.
PHP Code:
INSERT INTO `AM_recordtimes` ( `mapid` , `minutes`, 'seconds''miliseconds')VALUES ('%s','99''99''999'); 
Instead of
PHP Code:
INSERT INTO `AM_recordtimes` (mapidminutessecondsmilisecondsVALUES('%s','99','99','999'
2. Why are you using hours/minutes/seconds when you can only use seconds and store it into 1 variable in amx and 1 column in db? Just as matsi recommends. 60000 seconds can be easily converted into anything else.

3. Btw, this part code is useless if you have created the table. Unless nobody else will delete your table, you'll be fine.

In MySQL_Init(), delete.
PHP Code:
    // ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
// stop the plugin with an error message
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS AM_recordtimes (mapid varchar(32), minutes INT(11), seconds INT(11), miliseconds INT(11))")

    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems the plugin will set itself to bad load.
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
       
    }
    
    
// Free the querie
    
SQL_FreeHandle(Queries)
   
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection
4. I recommend you to use another kind of text editor, because you had to many "lose identification" errors.
Here's one cool from Arkshine http://forums.alliedmods.net/showthread.php?t=172128

I have modified your code a bit since I got bored. Read the comments inside of it. Enjoy.
Attached Files
File Type: sma Get Plugin or Get Source (1MsTimer.sma - 577 views - 7.6 KB)

Last edited by Infernuz; 08-30-2012 at 16:31.
Infernuz is offline
Send a message via ICQ to Infernuz
matsi
Thinkosaur
Join Date: Sep 2006
Old 08-30-2012 , 18:17   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #8

Code:
/* new szTemp[512] - You don't need that kind of huge temp of 512 characters, * unless you are not storing elephants. * * I have decreased it to 150 characters since you don't use more than that. */

__________________

Accepting all kinds of requests via private message.
matsi is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 08-31-2012 , 07:54   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #9

thanks alot Infernuz ,
but there are still a couple mistakes in:
in check_times() the game has to check if the new time is a new record so when the if statement is 1 the new time has to be saved as the new record, as how you did it, it saved the vallue's 99m 99s999ms so i changed that to Run_query(3);

but now i think that when a new map without data is loaded it doesnt automaticly set the times to 99,99,999 and also when a map is correctly loaded i think it will also store 99.99.999 becous when you load querry(1) in plugin_init it will run querry(2) in the public query_handler.

I'm not sure how to check if there is data in the table for a new map so that only then the times 99m99s999ms are stored by performing Run_query(2);
Attached Files
File Type: sma Get Plugin or Get Source (1MsTimer.sma - 539 views - 7.6 KB)
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 08-31-2012 at 07:55.
striker07 is offline
Infernuz
Member
Join Date: May 2011
Old 08-31-2012 , 15:49   Re: [Help - SQL] Saving Timer vallue's
Reply With Quote #10

Quote:
but now i think that when a new map without data is loaded it doesnt automaticly set the times to 99,99,999 and also when a map is correctly loaded i think it will also store 99.99.999 becous when you load querry(1) in plugin_init it will run querry(2) in the public query_handler.
I think it didn't work right just. I have modified query_handler a bit so it should ONLY insert data if old one it's not found.

Quote:
I'm not sure how to check if there is data in the table for a new map so that only then the times 99m99s999ms are stored by performing Run_query(2);
You check if data is in database by executing Run_query(1) and perform this check.

PHP Code:
if(SQL_NumResults(Query) > 0) {
//action here

If query returns more than 1 row, your action will be executed.

============================================
I remade your plugin completly and the saving to db. Tested, saves and gets the data with no problems.

Before you use it uncomment these.

PHP Code:
//#include <dhudmessage> 
In fw_CounterEntThink( iEntity ). You can delete server_cmd aswell.
PHP Code:
    /*
        if( !g_bHideTimer ) {
        set_hudmessage(255, 204, 0, 0.62, 0.96, 0, _, 0.2, 0.1, 0.1); // creates the hud message
        show_hudmessage( 0 , "Time: %i:%.2i:%.3i ^nRecord: %i:%.2i:%.3i" , g_iTimer/60, g_iTimer/60*2, g_iTimer, g_iRecTimer/60, g_iRecTimer/60*2, g_iRecTimer ); // show the counter in hudmessage
        
        server_cmd("TIMER NOW - min: %d s: %d, i: %d -- SQL TIMER - min: %d sec: %d i: %d", g_iTimer/60, g_iTimer/60*2, g_iTimer, g_iRecTimer/60, g_iRecTimer/60*2, g_iRecTimer);
    }*/ 
PHP Code:
//SQL_QueryAndIgnore(SqlConnection,"DROP TABLE IF EXISTS `AM_recordtimes`") 
Compile and.. run this code only ONCE on your server.

After delete the line and recompile the plugin.
PHP Code:
//SQL_QueryAndIgnore(SqlConnection,"DROP TABLE IF EXISTS `AM_recordtimes`") 
Now you should have a new table with only 3 colums. Check if it does in your phpmyadmin.

If you get errors, post them here. If you don't understand something in this plugin, ask.

1MsTimer - is with old code commented.
SaveRecord - without.

Cheers.
Attached Files
File Type: sma Get Plugin or Get Source (1MsTimer.sma - 540 views - 8.3 KB)
File Type: sma Get Plugin or Get Source (SaveRecord.sma - 550 views - 6.1 KB)
Infernuz is offline
Send a message via ICQ to Infernuz
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:47.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode