SA-MP Forums Archive
Integer convert to String - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Integer convert to String (/showthread.php?tid=569759)



Integer convert to String - Genmetal - 02.04.2015

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 ...


Re: Integer convert to String - Vince - 02.04.2015

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]]);



Re: Integer convert to String - Jimmy0wns - 02.04.2015

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])



Re: Integer convert to String - CalvinC - 02.04.2015

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.


Re: Integer convert to String - Genmetal - 02.04.2015

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??


Re: Integer convert to String - Genmetal - 02.04.2015

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


Re: Integer convert to String - PT - 02.04.2015

Yes you need put the name for all ranks