AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help - SQL] Saving Timer vallue's (https://forums.alliedmods.net/showthread.php?t=194584)

striker07 08-29-2012 11:43

[Help - SQL] Saving Timer vallue's
 
1 Attachment(s)
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.

matsi 08-29-2012 12:13

Re: [Help - SQL] Saving Timer vallue's
 
I don't see you using MySql_Init() anywhere... :roll:

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.

striker07 08-29-2012 16:31

Re: [Help - SQL] Saving Timer vallue's
 
- 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

matsi 08-29-2012 16:48

Re: [Help - SQL] Saving Timer vallue's
 
Quote:

Originally Posted by striker07 (Post 1786401)
- 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

striker07 08-29-2012 18:25

Re: [Help - SQL] Saving Timer vallue's
 
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.

striker07 08-30-2012 11:32

Re: [Help - SQL] Saving Timer vallue's
 
1 Attachment(s)
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

Infernuz 08-30-2012 16:30

Re: [Help - SQL] Saving Timer vallue's
 
1 Attachment(s)
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.

matsi 08-30-2012 18:17

Re: [Help - SQL] Saving Timer vallue's
 
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. */

:)

striker07 08-31-2012 07:54

Re: [Help - SQL] Saving Timer vallue's
 
1 Attachment(s)
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);

Infernuz 08-31-2012 15:49

Re: [Help - SQL] Saving Timer vallue's
 
2 Attachment(s)
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.


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

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