AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help :) calculanting maps + sql (https://forums.alliedmods.net/showthread.php?t=108412)

Metanabol 11-05-2009 03:38

Need help :) calculanting maps + sql
 
Hello, i'm thinkink about making plugin, who calculates maps.
e.g. if map is de_dust2_2x2 plugin write name de_dust2_2x2 to sql table like that:
Code:

de_dust2_2x2 10
de_assault 21
de_dust2 61

i want to make top 5 favourite maps in server :) and show this in my website based on php-fusion...


So, from that i must start making plugin... because never worked with sql..


sry for bad english.

Exolent[jNr] 11-05-2009 11:17

Re: Need help :) calculanting maps + sql
 
Code:
#include < amxmodx > #include < sqlx > new const TABLE_NAME[ ] = ""; new const KEY_MAPNAME[ ] = ""; new const KEY_MAPCOUNT[ ] = ""; new Handle:g_hSqlTuple; new g_szQuery[ 128 ]; new g_szMap[ 64 ]; public plugin_init( ) {     g_hSqlTuple = SQL_MakeStdTuple( );         formatex( g_szQuery, 127, "CREATE TABLE IF NOT EXISTS `%s` ( `%s` VARCHAR(64) NOT NULL, `%s` INT(10) NOT NULL );",         TABLE_NAME, KEY_MAPNAME, KEY_MAPCOUNT );         SQL_ThreadQuery( g_hSqlTuple, "QueryCreateTable", szQuery ); } public QueryCreateTable( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) {     if( iFailState == TQUERY_CONNECT_FAILED     || iFailState == TQUERY_QUERY_FAILED ) {         log_amx( "Query failed on create table." );     } else {         get_mapname( g_szMap, 63 );         strtolower( g_szMap, 63 );                 formatex( g_szQuery, 127, "SELECT `%s` FROM `%s` WHERE `%s` = '%s';",             KEY_MAPCOUNT, TABLE_NAME, KEY_MAPNAME, g_szMap );                 SQL_ThreadQuery( g_hSqlTuple, "QuerySelectMapCount", szQuery );     } } public QuerySelectMapCount( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) {     if( iFailState == TQUERY_CONNECT_FAILED     || iFailState == TQUERY_QUERY_FAILED ) {         log_amx( "Query failed on select map count." );     } else {         if( SQL_NumResults( hQuery ) ) {             new iCount = SQL_ReadResult( hQuery, 0 ) + 1;                         formatex( g_szQuery, 127, "UPDATE `%s` SET `%s` = `%s` + 1 WHERE `%s` = '%s';",                 TABLE_NAME, KEY_MAPCOUNT, KEY_MAPCOUNT, KEY_MAPNAME, g_szMap );         } else {             formatex( g_szQuery, 127, "INSERT INTO `%s` ( `%s`, `%s` ) VALUES ( '%s', 1 );",                 TABLE_NAME, KEY_MAPNAME, KEY_MAPCOUNT, g_szMap );         }                 SQL_ThreadQuery( g_hSqlTuple, "QuerySetMapCount", g_szQuery );     } } public QuerySelectMapCount( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) {     if( iFailState == TQUERY_CONNECT_FAILED     || iFailState == TQUERY_QUERY_FAILED ) {         log_amx( "Query failed on set map count." );     } }


All times are GMT -4. The time now is 17:35.

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