Integer convert to String
#1

how can i change integer to string?
Код:
CMD:mylevel(playerid, params[])
{
if(pInfo[playerid][Admin] == 5)
{
SendClientMessage(playerid, -1, "Server: Your Level is %d", pInfo[playerid][Admin]); // This integer to String
}
return 1;
}
i want the output is
Код:
Server: Your Level is Server Owner
not
Код:
Server: Your level is 5
please help ...
Reply
#2

Create a constant array with level names and then use the variable as an index.
pawn Код:
new const gAdminLevels[][] = { "None", "Junior", "Senior" };

format(string, sizeof(string), "Your level is %s", gAdminLevels[pInfo[playerid][Admin]]);
Reply
#3

I use this, just modify it to your needs:
pawn Код:
stock GetLevel(levelid)
{
    new rankname[32];
    switch(levelid)
    {
        case 1: rankname = "Junior Moderator";
        case 2: rankname = "Moderator";
        case 3: rankname = "Junior Administrator";
        case 4: rankname = "Administrator";
        case 5: rankname = "Head Administrator";
        case 6: rankname = "Project Lead";
        default: rankname = "User";
    }
    return rankname;
}
You could use it in this way:
pawn Код:
GetLevel(pInfo[playerid][Admin])
Reply
#4

pawn Код:
CMD:mylevel(playerid, params[])
{
    new level[128];
    switch(pInfo[playerid][Admin]) // Checks the value of pInfo[playerid][Admin]
    {
        case 1: level = "level 1"; // If it's 1, the level-array contains "level 1"
        case 2: level = "level 2"; // If it's 2, the level-array contains "level 2"
        // And so on
    }
    new string[128];
    format(string, sizeof(string), "Server: Your level is %s", level); // You need to use format to have other formats in your message, etc. %s, %d and so on
    SendClientMessage(playerid, -1, string);
    return 1;
}
Or just put the switch in a function instead.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Create a constant array with level names and then use the variable as an index.
pawn Код:
new const gAdminLevels[][] = { "None", "Junior", "Senior" };

format(string, sizeof(string), "Your level is %s", gAdminLevels[pInfo[playerid][Admin]]);
wait,
if the level admin is 0 the output is None? and when The admin level is 1 the output will show Junior??
Reply
#6

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
pawn Код:
CMD:mylevel(playerid, params[])
{
    new level[128];
    switch(pInfo[playerid][Admin]) // Checks the value of pInfo[playerid][Admin]
    {
        case 1: level = "level 1"; // If it's 1, the level-array contains "level 1"
        case 2: level = "level 2"; // If it's 2, the level-array contains "level 2"
        // And so on
    }
    new string[128];
    format(string, sizeof(string), "Server: Your level is %s", level); // You need to use format to have other formats in your message, etc. %s, %d and so on
    SendClientMessage(playerid, -1, string);
    return 1;
}
Or just put the switch in a function instead.
thx for help me

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
I use this, just modify it to your needs:
pawn Код:
stock GetLevel(levelid)
{
    new rankname[32];
    switch(levelid)
    {
        case 1: rankname = "Junior Moderator";
        case 2: rankname = "Moderator";
        case 3: rankname = "Junior Administrator";
        case 4: rankname = "Administrator";
        case 5: rankname = "Head Administrator";
        case 6: rankname = "Project Lead";
        default: rankname = "User";
    }
    return rankname;
}
Thanks

You could use it in this way:
pawn Код:
GetLevel(pInfo[playerid][Admin])
Quote:
Originally Posted by Genmetal
Посмотреть сообщение
wait,
if the level admin is 0 the output is None? and when The admin level is 1 the output will show Junior??
Quote:
Originally Posted by Vince
Посмотреть сообщение
Create a constant array with level names and then use the variable as an index.
pawn Код:
new const gAdminLevels[][] = { "None", "Junior", "Senior" };

format(string, sizeof(string), "Your level is %s", gAdminLevels[pInfo[playerid][Admin]]);
Thanks
Reply
#7

Yes you need put the name for all ranks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)