Raised This Month: $248 Target: $400
 62% 

Problem from SQL to MOTD


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
msbeden
Member
Join Date: Jan 2020
Location: Turkey, Eskisehir
Old 01-28-2020 , 02:50   Problem from SQL to MOTD
Reply With Quote #1

Hello. I pull data from SQL. I managed to print. But the lines are missing. I cannot change the "1023-iLen" section in the while loop. This time the plug-in is broken. Can you help me?

Caps:



My codes:

Code:
/*
    * This plugin has been written to the "OciXCrom's Rank System" plugin than by msbeden.
	* Required: OciXCrom's Rank System
    * Download: https://forums.alliedmods.net/showthread.php?t=308540
*/

#include <amxmodx>  
#include <amxmisc>  
#include <sqlx>  

#define PLUGIN "Top15 OciXCrom's Rank"  
#define VERSION "1.0"  
#define AUTHOR "msbeden"  

#define host "127.0.0.1"  
#define user "root"  
#define pass ""  
#define db "amx"  
#define MAX_BUFFER_LENGTH       4095

new Handle:sql, g_query[512]

public plugin_init()   
{  
    register_plugin(PLUGIN, VERSION, AUTHOR );  
    register_clcmd("say", "handle_say");    
}  

public plugin_cfg()
{  
    sql = SQL_MakeDbTuple(host, user, pass, db)
}  

public handle_say(id)   
{  
    static said[12]  
    read_argv(1, said, 11)  
    
    if(equal(said,"/top15") || equal(said,"!top15") || equal(said,".top15") || equal(said,"top15")) {  
        new data[1];data[0]=id  
        
        formatex(g_query,511,"SELECT Player, XP, Level FROM HGRutbe ORDER BY XP DESC LIMIT 15")  
        SQL_ThreadQuery(sql,"top15rank",g_query,data,1)  
    }  
    return PLUGIN_CONTINUE;  
}

public plugin_end()
{  
    SQL_FreeHandle(sql)  
}

public top15rank(FailState, Handle:Query, Error[], Errcode,Data[], DataSize)
{  
    new motd[1024];
    new iMax = 1; 
	new iLen = 0;

	if (iMax > 10)
		iMax = 10
	new lNick[40], lRanks[40], lXps[40], lAcc[40]
	format(lNick, 25, "Nick")
	format(lRanks, 25, "Rank")
	format(lXps, 25, "XP")

	ucfirst(lAcc)

	iLen = format( motd, MAX_BUFFER_LENGTH,
                  "<head><META http-equiv=Content-Type content='text/html ;charset=UTF-8'></head><style>body{background:#191818;background-image: url(^"http://i.hizliresim.com/d59r4p.jpg^");margin:5pt;padding:2pt;font-family:Tahoma;color:#ccc}.A{background-color:#262626;opacity:0.6;filter:alpha(opacity=60);}.B{background-color:#0b0b0b;opacity:0.6;filter:alpha(opacity=60);}td{font-size:15px}</style><center><table width=700>" )
	iLen += format( motd[iLen], MAX_BUFFER_LENGTH - iLen,
                  "<tr><td><br/> <td></tr><tr><td><br/> <b><td></tr><tr><td>%s<td>%s<td>%s<td>%s</b>",
                  "#", lNick, lRanks, lXps)

    static name[32];
    new point, line;

    while(SQL_MoreResults(Query)){  
        line++
        
        SQL_ReadResult(Query,0,name, 32)
        point = SQL_ReadResult(Query,1)
    
        iLen += format(motd[iLen], 1023-iLen,"<tr><td>%d <td>%s <td>%s <td>%i ^n", line, name, levelTranslate(point), point, point == 1 ? "" : "") 
        SQL_NextRow(Query)
    }

    copy(motd[iLen],MAX_BUFFER_LENGTH - iLen,"</table></center>");
    show_motd(0, motd,"Rank top15")
}  

public query(FailState, Handle:Query, Error[], Errcode)
{  
    
}

public levelTranslate(point)
{
    static name[300];
    if(point >= 1075000) {
        name = "Maresal";
    } else if(point >= 525000) {
        name = "GenelKurmay Baskani";
    } else if(point >= 525000) {
        name = "GenelKurmay";
    } else if(point >= 422500) {
        name = "Orgeneral";
    } else if(point >= 270000) {
        name = "Korgeneral";
    } else if(point >= 167500) {
        name = "Tumgeneral";
    } else if(point >= 125000) {
        name = "Tuggeneral";
    } else if(point >= 100000) {
        name = "Albay";
    } else if(point >= 87500) {
        name = "Yarbay";
    } else if(point >= 50000) {
        name = "Binbasi";
    } else if(point >= 36250) {
        name = "Yuzbasi";
    } else if(point >= 25000) {
        name = "Ustegmen";
    } else if(point >= 15000) {
        name = "Tegmen";
    } else if(point >= 7500) {
        name = "Astegmen";
    } else if(point >= 4000) {
        name = "Astsubay";
    } else if(point >= 2500) {
        name = "Uzman";
    } else if(point >= 500) {
        name = "Cavus";
    } else if(point >= 0) {
        name = "Onbasi";
    } else {
        name = "error";
    }

    return name;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/

Last edited by msbeden; 01-28-2020 at 07:49.
msbeden is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-28-2020 , 09:16   Re: Problem from SQL to MOTD
Reply With Quote #2

A MOTD window can't display more than 1536 characters.
Why are you using a function to translate the names? You can directly retrieve the rank name from the "Rank" column in SQL.
__________________

Last edited by OciXCrom; 01-28-2020 at 09:17.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
msbeden
Member
Join Date: Jan 2020
Location: Turkey, Eskisehir
Old 01-28-2020 , 09:42   Re: Problem from SQL to MOTD
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
A MOTD window can't display more than 1536 characters.
Why are you using a function to translate the names? You can directly retrieve the rank name from the "Rank" column in SQL.
I wrote their Turkish equivalents in the file "RankSystem.ini". Does it also save to SQL?
msbeden is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-28-2020 , 09:49   Re: Problem from SQL to MOTD
Reply With Quote #4

Yes, the ranks from the "RankSystem.ini" file are saved in SQL, in the "Rank" field, so you don't have to manually add them in your .sma file.

The columns saved in SQL are the following: `Player`,`XP`,`Level`,`Next XP`,`Rank`,`Next Rank`
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
msbeden
Member
Join Date: Jan 2020
Location: Turkey, Eskisehir
Old 01-28-2020 , 10:02   Re: Problem from SQL to MOTD
Reply With Quote #5

But I can't print from SQL. It says "0" or as a number. Is there an error in the variable definitions?

Code:
// SQL query: SELECT Player, Rank, XP FROM HGRank ORDER BY XP DESC LIMIT 10

new rank;

rank= SQL_ReadResult(Query,1)

..

iLen += format(motd[iLen], 1535-iLen,"<tr><td>%d <td>%s <td>%i <td>%i ^n", line, name, rank, point, point == 1 ? "" : "") 
..
iLen += format(motd[iLen], 1535-iLen,"<tr><td>%d <td>%s <td>%i <td>%i ^n", line, name, rank, point, point == 1 ? "" : "")

I used it. But rank comes 0.

which %s, %d, %i ?

Last edited by msbeden; 01-28-2020 at 10:21.
msbeden is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 01-28-2020 , 11:31   Re: Problem from SQL to MOTD
Reply With Quote #6

after solving rank number, i think you will get the same problem again in the motd (cuz limit of max chars in there)

if you are using VPS, you can continue with SQLite module for saving and loading stats, but make .php code to show stats (top100 for example)...combine it with xampp with opened port and i think thats it
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...)
JocAnis is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-28-2020 , 14:15   Re: Problem from SQL to MOTD
Reply With Quote #7

Quote:
// SQL query: SELECT Player, Rank, XP FROM HGRank ORDER BY XP DESC LIMIT 10

new rank;

rank= SQL_ReadResult(Query,1)
The first result is player, not rank. Rank is the second one, plus it's a string, so do this:

Code:
new szRank[CRXRANKS_MAX_RANK_LENGTH] SQL_ReadResult(Query, 2, szRank, charsmax(szRank))
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-28-2020 , 16:55   Re: Problem from SQL to MOTD
Reply With Quote #8

make a webpage that display top15 using data from mysql, and then use the url to show the motd.

for example

show_motd(0, "http://www.myurl.com/top15.php","Rank top15")

requires knowledge of php and html.
__________________
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Last edited by Natsheh; 01-28-2020 at 16:56.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
nomi1492
New Member
Join Date: Sep 2020
Old 09-09-2020 , 02:59   Re: Problem from SQL to MOTD
Reply With Quote #9

how to add it in the first place!!
plz help me i am a new modder
nomi1492 is offline
Reply


Thread Tools
Display Modes

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 09:19.


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