AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem from SQL to MOTD (https://forums.alliedmods.net/showthread.php?t=321167)

msbeden 01-28-2020 02:50

Problem from SQL to MOTD
 
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:
https://i.hizliresim.com/kM47QW.jpg


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 }
*/


OciXCrom 01-28-2020 09:16

Re: Problem from SQL to MOTD
 
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.

msbeden 01-28-2020 09:42

Re: Problem from SQL to MOTD
 
Quote:

Originally Posted by OciXCrom (Post 2681953)
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?

OciXCrom 01-28-2020 09:49

Re: Problem from SQL to MOTD
 
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`

msbeden 01-28-2020 10:02

Re: Problem from SQL to MOTD
 
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 ?

JocAnis 01-28-2020 11:31

Re: Problem from SQL to MOTD
 
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

OciXCrom 01-28-2020 14:15

Re: Problem from SQL to MOTD
 
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))

Natsheh 01-28-2020 16:55

Re: Problem from SQL to MOTD
 
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.

nomi1492 09-09-2020 02:59

Re: Problem from SQL to MOTD
 
how to add it in the first place!!
plz help me i am a new modder


All times are GMT -4. The time now is 02:53.

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