SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/05/2020, 03:24 AM   #1
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default labels doesnt load

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;
Filbert is offline   Reply With Quote
Old 23/05/2020, 03:48 AM   #2
Unrea1
Gangsta
 
Unrea1's Avatar
 
Join Date: Oct 2013
Location: Venezuela
Posts: 822
Reputation: 129
Default Re: labels doesnt load

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

strlib.inc https://forum.sa-mp.com/showthread.php?t=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;
}
__________________
Unrea1 is online now   Reply With Quote
Old 23/05/2020, 04:17 AM   #3
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: labels doesnt load

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://forum.sa-mp.com/showthread.php?t=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
Filbert is offline   Reply With Quote
Old 23/05/2020, 05:14 AM   #4
Shadow0707
Big Clucker
 
Join Date: Sep 2016
Posts: 92
Reputation: 7
Default Re: labels doesnt load

You can check this https://forum.sa-mp.com/showthread.php?t=616103 then do it in reverse.
Shadow0707 is online now   Reply With Quote
Old 23/05/2020, 06:26 AM   #5
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: labels doesnt load

Quote:
Originally Posted by Shadow0707 View Post
You can check this https://forum.sa-mp.com/showthread.php?t=616103 then do it in reverse.
So there's no other way except updating the mysql plugin?
Filbert is offline   Reply With Quote
Old 25/05/2020, 02:57 AM   #6
Unrea1
Gangsta
 
Unrea1's Avatar
 
Join Date: Oct 2013
Location: Venezuela
Posts: 822
Reputation: 129
Default Re: labels doesnt load

You can actually fix the problem, only I gave it to you updated to the latest version
__________________
Unrea1 is online now   Reply With Quote
Old 25/05/2020, 04:47 AM   #7
StevenLV
Big Clucker
 
StevenLV's Avatar
 
Join Date: Apr 2017
Location: Pakistan
Posts: 144
Reputation: 11
Default Re: labels doesnt load

Changing from R35+ to R41 is not hard, it has a minor changes to the functions.
Well there is a thread as well: https://forum.sa-mp.com/showthread.php?t=616103
__________________
Quote:
Eternal Life Roleplay - An upcoming unique RP server based in Palomino Creek
https://discord.gg/JWzE78r
Quote:
Originally Posted by !damo!spiderman View Post
You're pathetic. Stand for something that's going to help the world rather than fill it with more hate. Give someone a hug, tell someone you care... Do something, do anything but do it with love not hate.
StevenLV is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vehicle labels don't load on OnGameModeInit ElMaestro123 Scripting Help 3 11/07/2017 11:52 AM
Dynamic Labels doesnt show Dziugsas Scripting Help 7 11/12/2014 07:53 PM
Dynamic labels refuses to load BizzyD Scripting Help 3 18/11/2013 04:19 PM
[FilterScript] 3d Labels Creator In Game! (Save & Load .txt) [Nikk] Filterscripts 16 08/02/2012 08:47 PM
Labels load with bad pos. [Nikk] Scripting Help 3 04/02/2012 04:21 AM


All times are GMT. The time now is 05:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.