labels doesnt load
#1

I'm using this filterscript but I want it in mysql
Firstly, I tried this :

pawn Code:
public OnGameModeInit()
{
    print("\n--------------------------------------");
    print("Ultimate Label Creator by -KillerThriller");
    print("--------------------------------------\n");
    for(new i = 0; i < MAX_LABELS;i++)
    {
        new Query[250];
        mysql_format(mysql, Query, sizeof Query,"SELECT * FROM `labels` WHERE `LID` = '%i'",i);
        mysql_tquery(mysql, Query, "LoadLabels1", "");
    }
    return 1;
}
pawn Code:
forward LoadLabels1();
public LoadLabels1()
{
    for(new i = 0; i < MAX_LABELS;i++)
    {
        new rows,fields;
        cache_get_data(rows, fields, mysql);
        if(rows) {
            new color[64],text[200];
            cache_get_field_content(0, "Color", color, mysql, 128);
            cache_get_field_content(0, "Text", text, mysql, 256);
            LInfo[i][POSX] = cache_get_field_content_float(0, "X");
            LInfo[i][POSY] = cache_get_field_content_float(0, "Y");
            LInfo[i][POSZ] = cache_get_field_content_float(0, "Z");
            LInfo[i][LDistance] = cache_get_field_content_float(0, "LDistance");
            LInfo[i][World] = cache_get_field_content_int(0, "World");
            format(LInfo[i][Text],200,"%s",text);
            if(strcmp(color,"Red") == 0)
            {
                LInfo[i][Color] = llred;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Green") == 0)
            {
                LInfo[i][Color] = llgreen;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Yellow") == 0)
            {
                LInfo[i][Color] = llyellow;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Blue") == 0)
            {
                LInfo[i][Color] = llblue;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Pink") == 0)
            {
                LInfo[i][Color] = llpink;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"White") == 0)
            {
                LInfo[i][Color] = llwhite;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            Labelcount++;
        }
    }
    printf("Labels loaded: %i",Labelcount);
    return 1;
}
There's no problem when i created the labels in game, and it's successfully saved in my table.



But when I restarted the server, the labels somehow didn't load.
Then I tried this :

pawn Code:
public OnGameModeInit()
{
    print("\n--------------------------------------");
    print("Ultimate Label Creator by -KillerThriller");
    print("--------------------------------------\n");
    LoadLabels();
    return 1;
}
pawn Code:
stock LoadLabels()
{
    for(new i = 0; i < MAX_LABELS;i++)
    {
        new Query[250];
        mysql_format(mysql, Query, sizeof Query,"SELECT * FROM `labels` WHERE `LID` = '%i'",i);
        mysql_tquery(mysql, Query, "LoadLabels1", "");
    }
}

forward LoadLabels1();
public LoadLabels1()
{
    for(new i = 0; i < MAX_LABELS;i++)
    {
        new rows,fields;
        cache_get_data(rows, fields, mysql);
        if(rows) {
            new color[64],text[200];
            cache_get_field_content(0, "Color", color, mysql, 128);
            cache_get_field_content(0, "Text", text, mysql, 256);
            LInfo[i][POSX] = cache_get_field_content_float(0, "X");
            LInfo[i][POSY] = cache_get_field_content_float(0, "Y");
            LInfo[i][POSZ] = cache_get_field_content_float(0, "Z");
            LInfo[i][LDistance] = cache_get_field_content_float(0, "LDistance");
            LInfo[i][World] = cache_get_field_content_int(0, "World");
            format(LInfo[i][Text],200,"%s",text);
            if(strcmp(color,"Red") == 0)
            {
                LInfo[i][Color] = llred;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Green") == 0)
            {
                LInfo[i][Color] = llgreen;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Yellow") == 0)
            {
                LInfo[i][Color] = llyellow;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Blue") == 0)
            {
                LInfo[i][Color] = llblue;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"Pink") == 0)
            {
                LInfo[i][Color] = llpink;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            if(strcmp(color,"White") == 0)
            {
                LInfo[i][Color] = llwhite;
                LabelID[i] = Create3DTextLabel(LInfo[i][Text],LInfo[i][Color],LInfo[i][POSX],LInfo[i][POSY],LInfo[i][POSZ],LInfo[i][LDistance],LInfo[i][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
            }
            Labelcount++;
        }
    }
    printf("Labels loaded: %i",Labelcount);
    return 1;
}
And something worse came, it loads ton of labels and the server is so slow.

Code:
...
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
[10:01:13] Labels loaded: 10000
...
EDIT: Here are some defines and variables..

pawn Code:
#define MAX_LABELS                                                             5000
#define MAIN_DIALOG                                                            2402
#define DEFAULT_LABEL_VIEW_THREW_OBJECTS                                       0
#define DEFAULT_LABEL_VIEW_DISTANCE                                            20.0

#define llgreen                                                         0x00FF28FF
#define lldarkgreen                                                     0x5FB700FF
#define lllightgreen                                                    0x23FF00FF
#define llred                                                           0xFF0000FF
#define llyellow                                                        0xF5FF00FF
#define llpink                                                          0xFF00FFC8
#define lldarkyellow                                                    0xF5DE00FF
#define llorange                                                        0xF5A300FF
#define lldarkblue                                                      0x0037FFFF
#define llblue                                                          0x1400FFFF
#define lllightblue                                                     0x00FFF0FF
#define llgrey                                                          0xB4B4B4FF
#define llwhite                                                         0xF0F0F0FF
#define llpurple                                                        0x9C00AFFF

#define lgreen1                                                         "{6EF83C}"
#define lwhite1                                                         "{FFFFFF}"
#define lyellow1                                                        "{FFFF22}"
#define lblue1                                                          "{2255FF}"
#define lpink1                                                          "{FF00FF}"
#define lorange1                                                        "{FF6622}"
#define lred1                                                           "{FF0000}"
#define lyellow12                                                       "{E1DE1C}"

enum labelsinfo
{
    Text[256],
    Color,
    Float:POSX,
    Float:POSY,
    Float:POSZ,
    Float:LDistance,
    World
}
new Text3D:LInfo[MAX_LABELS][labelsinfo];
new Labelcount;
new Text3D:LabelID[MAX_LABELS];
new EditingLabel[MAX_PLAYERS] = -1;
Reply
#2

This will work in MySQL plugin R41-4, also you need the library strlib for the function strcpy.

strlib.inc https://sampforum.blast.hk/showthread.php?tid=362764

So, in OnGameModeInit:

Code:
mysql_tquery(MySQL, "SELECT * FROM labels", "LoadLabels");
And the function LoadLabels more optimized.

Code:
forward LoadLabels();
public LoadLabels()
{
	new rows;

    cache_get_row_count(rows);

    if (!rows) 
    	return print("None label loaded.");

    for (new row = 0; row != rows; ++row)
    {
        new color[64], text[200];
        cache_get_value(row, "Color", color, 128);
        cache_get_value(row, "Text", text, 256);
        cache_get_value_float(row, "X", LInfo[row][POSX]);
        cache_get_value_float(row, "Y", LInfo[row][POSY]);
        cache_get_value_float(row, "Z", LInfo[row][POSZ]);
        cache_get_value_float(row, "LDistance", LInfo[row][LDistance]);
        cache_get_value_int(row, "World", LInfo[row][World]);

        strcpy(LInfo[row][Text], text);

        if(strcmp(color,"Red") == 0)
        {
            LInfo[row][Color] = llred;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Green") == 0)
        {
            LInfo[row][Color] = llgreen;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Yellow") == 0)
        {
            LInfo[row][Color] = llyellow;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Blue") == 0)
        {
            LInfo[row][Color] = llblue;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Pink") == 0)
        {
            LInfo[row][Color] = llpink;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"White") == 0)
        {
            LInfo[row][Color] = llwhite;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        Labelcount++;
    }
    printf("Labels loaded: %i/%i", rows, Labelcount);
    return 1;
}
Reply
#3

Quote:
Originally Posted by Unrea1
View Post
This will work in MySQL plugin R41-4, also you need the library strlib for the function strcpy.

strlib.inc https://sampforum.blast.hk/showthread.php?tid=362764

So, in OnGameModeInit:

Code:
mysql_tquery(MySQL, "SELECT * FROM labels", "LoadLabels");
And the function LoadLabels more optimized.

Code:
forward LoadLabels();
public LoadLabels()
{
	new rows;

    cache_get_row_count(rows);

    if (!rows) 
    	return print("None label loaded.");

    for (new row = 0; row != rows; ++row)
    {
        new color[64], text[200];
        cache_get_value(row, "Color", color, 128);
        cache_get_value(row, "Text", text, 256);
        cache_get_value_float(row, "X", LInfo[row][POSX]);
        cache_get_value_float(row, "Y", LInfo[row][POSY]);
        cache_get_value_float(row, "Z", LInfo[row][POSZ]);
        cache_get_value_float(row, "LDistance", LInfo[row][LDistance]);
        cache_get_value_int(row, "World", LInfo[row][World]);

        strcpy(LInfo[row][Text], text);

        if(strcmp(color,"Red") == 0)
        {
            LInfo[row][Color] = llred;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Green") == 0)
        {
            LInfo[row][Color] = llgreen;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Yellow") == 0)
        {
            LInfo[row][Color] = llyellow;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Blue") == 0)
        {
            LInfo[row][Color] = llblue;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"Pink") == 0)
        {
            LInfo[row][Color] = llpink;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        if(strcmp(color,"White") == 0)
        {
            LInfo[row][Color] = llwhite;
            LabelID[row] = Create3DTextLabel(LInfo[row][Text],LInfo[row][Color],LInfo[row][POSX],LInfo[row][POSY],LInfo[row][POSZ],LInfo[row][LDistance],LInfo[row][World],DEFAULT_LABEL_VIEW_THREW_OBJECTS);
        }
        Labelcount++;
    }
    printf("Labels loaded: %i/%i", rows, Labelcount);
    return 1;
}
Oh, i'm using R39-5, what should i do with that? Sorry, but it'll take too much time if i should update the whole gamemode to R41
Reply
#4

You can check this https://sampforum.blast.hk/showthread.php?tid=616103 then do it in reverse.
Reply
#5

Quote:
Originally Posted by Shadow0707
View Post
You can check this https://sampforum.blast.hk/showthread.php?tid=616103 then do it in reverse.
So there's no other way except updating the mysql plugin?
Reply
#6

You can actually fix the problem, only I gave it to you updated to the latest version
Reply
#7

Changing from R35+ to R41 is not hard, it has a minor changes to the functions.
Well there is a thread as well: https://sampforum.blast.hk/showthread.php?tid=616103
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)