How to store strings? Player Accent...
#1

pawn Код:
public OnPlayerText(playerid, text[])
{
    new string[256];
    if(UsingAccent[playerid] == 1 && BeingCalled[playerid] == 0 && Calling[playerid] == 0)
    {
        format(string, sizeof(string), "%s says [%s Accent]: %s", GetNameEx(playerid), GetPlayerAccent(playerid), text);
        ProxDetector(15.0, playerid, string, COLOUR_FADE1,COLOUR_FADE2,COLOUR_FADE3,COLOUR_FADE4,COLOUR_FADE5);
    }
I just realised I'm using this ridiculous system.

The reason for it being ridiculous is because of GetPlayerAccent, which is this:

pawn Код:
stock GetPlayerAccent(playerid)
{
    new szQuery[300], result[50];
    format(szQuery, sizeof(szQuery), "SELECT `Accent` FROM `accounts` WHERE `id` = %d", PlayerSQLID[playerid]);
    mysql_query(szQuery);

    mysql_store_result();

    while(mysql_retrieve_row())
    {
        mysql_fetch_field_row(result, "Accent");
    }
    mysql_free_result();
    return result;
}


How can I store the string locally without checking mysql everytime someone speaks, I know how ridiculous that is, I wrote that ages ago!!
Reply
#2

Add this to OnPlayerConnect/Spawn and save it as player variable.
Reply
#3

You can load the accent in to a string array instead, once the player has logged in or connected.

Variable declaration:
pawn Код:
new g_szPlayerAccent[MAX_PLAYERS][32];
Setting the player's accent value:
pawn Код:
strcat(g_szPlayerAccent[playerid], "Accent", 32); // Replace "Accent" with the string or accent text once the player connects
Getting the player's accent (in context):
pawn Код:
format(szMessage, sizeof(szMessage), "(%s accent) %s says: %s", g_szPlayerAccent[playerid], szPlayerName, szText);
So ultimately, based on the code you've shown us, this code can be added and called when the player logs in: (and should work)
pawn Код:
stock LoadPlayerAccent(playerid) {
    new
        szResult[32],
        szQuery[64];

    format(szQuery, sizeof(szQuery), "SELECT `Accent` FROM `accounts` WHERE `id` = %d", PlayerSQLID[playerid]);
    mysql_query(szQuery);

    mysql_store_result();

    while(mysql_retrieve_row()) {
        mysql_fetch_field_row(szResult, "Accent");
    }
    mysql_free_result();

    strcat(g_szPlayerAccent[playerid], szResult, 32);
    return 1;
}
Reply
#4

pawn Код:
// global:
new Player_Accent[MAX_PLAYERS][50];

// A definition so you don't need to change everytime you use it:
#define GetPlayerAccent(%0) Player_Accent[%0]

// OnPlayerConnect:
Player_Accent[playerid][0] = EOS;

// When loading the player's data
mysql_fetch_field_row(Player_Accent[playerid], "Accent");
Reply
#5

Just a quick question can the player set their own accent string? Or is the accent stored in array? If it is stored in an array you have no need to save the accent as a string all you need to save is the array index reference.
Reply
#6

Thanks guys, sorry about delay response. Yeah players can! I understand now guys, thank you!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)