using strmid I get blank string?
#1

hi, I made 2 commands, (ycmd + yini), changing the string values:
pEmail (e-mail)
pLook (players IC look)

but, it's ok when i player open his File, (by the command), and it Saves to a "Email", or "Look"..
But then I've to re-log to save my stats, and load it again,
Thats really anoying so i decided to make,

/email [e-mail] and it with strmid should extract my string to my Email variable, right?

Using code below, when I perform command /email (or /look),
etc. /email [samp@forum.sa-mp.com] //

it saves to my variable this " ", a.k.a. blank string,

Help please [rep+]

pawn Код:
enum pInfo
{
      pEmail[128],
      pLook[128]
}

// now commands

YCMD:email(playerid, params[], help)
{
    #pragma unused help
    new email[46], emailstring[128], string[128];
    if(sscanf(params, "s[128]", email))
        return SCM(playerid, COLOR_GRAY, "Usage: /email [your new email]");
    else if(strlen(email) < 6 || strlen(email) > 64)
        return SCM(playerid, COLOR_GRAY, "*Your email shouldn't containt less than 6 or above 64 chars!");

    format(emailstring, sizeof(emailstring), "%s", email);
    strmid(PlayerInfo[playerid][pEmail], emailstring, 0, strlen(emailstring));
    format(string, sizeof(string), "Success, your new email: %s", email);
    SCM(playerid, COLOR_YELLOW, string);
    return 1;
}

YCMD:setlook(playerid, params[], help)
{
    #pragma unused help
    new string[128], text[128], lookstring[128];
    if(sscanf(params, "s", text))
        return SCM(playerid, COLOR_GRAY, "Usage: /setlook [your new look]");
    format(lookstring, sizeof(lookstring), "%s", text);
    strmid(PlayerInfo[playerid][pLook], lookstring, 0, strlen(lookstring));
    SCM(playerid, SBLUE, "Success, your new look:");
    format(string, sizeof(string), "%s %s", PlayerName(playerid), text);
    SCM(playerid, SBLUE, string);
    return 1;
}
pawn Код:
YCMD:myemail(playerid, params[], help)
{
      #pragma unused help
      new string[128];
      format(string, sizeof(string), "Your email: %s", PlayerInfo[playerid][pEmail]);
      SCM(playerid, COLOR_YELLOW, string);
      return 1;
}

YCMD:showyourself(playerid, params[], help)
{
    #pragma unused help
    new string[128];
    format(string, sizeof(string), "**%s %s.", PlayerName(playerid), PlayerInfo[playerid][pLook]);
    ProxDetector(30.0, playerid, string, SBLUE, SBLUE, SBLUE, SBLUE, SBLUE);
    return 1;
}
Reply
#2

So you want to just copy a string to another, right?
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
pawn Код:
strcpy(PlayerInfo[playerid][pEmail], emailstring, 128);
pawn Код:
strcpy(PlayerInfo[playerid][pLook], lookstring, 128);
Reply
#3

And furthermore, for standard variable you could do
pawn Код:
strcpy(somevariable, lookstring);
Because in fact it is
pawn Код:
strcpy(somevariable, lookstring, sizeof(somevariable));
But pawn has problems with determining size of third dimension, so this code won't work:
pawn Код:
strcpy(PlayerInfo[playerid][pEmail], emailstring);
//in reality
strcpy(PlayerInfo[playerid][pEmail], emailstring, sizeof(PlayerInfo[playerid][pEmail]));
And you have to specify the size yourself:
pawn Код:
strcpy(PlayerInfo[playerid][pEmail], emailstring, 128);
Cheers
Reply
#4

thank you both guys (rep+)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)