should return a value
#1

~fixed~
Reply
#2

PHP код:
GetAdminName(playerid)
{
    new 
adminname[32];
    switch(
pInfo[playerid][pAdminLevel])
    {
        case 
0adminname "Test";
        case 
1adminname "Test";
        case 
2adminname "Test";
        case 
3adminname "Test";
        case 
4adminname "Test";
        case 
5adminname "Test";
    }
    return 
adminname;

If you want from admin levels >= 1, remove the "case 0: ..." line.
Reply
#3

~fixed~
Reply
#4

Hello!

If you take this function, like this:
PHP код:
printf("playerid: %d - Adminlevel: %s",playerid,GetAdminName(playerid)); 
You will get your admin name also if your admin level is higher than 0, for that is the switch-loop.
PHP код:
switch(pInfo[playerid][pAdminLevel]) 
Reply
#5

pawn Код:
GetAdminName(playerid) // Use plain function instead of stock if you aren't making an include
{
    new adminname[128];
    switch(pInfo[playerid][pAdminLevel])
    {
        case 0: strpack(adminname, "Test"); // Right method and more faster.
        case 1: strpack(adminname, "Test");
        case 2: strpack(adminname, "Test");
        case 3: strpack(adminname, "Test");
        case 4: strpack(adminname, "Test");
        case 5: strpack(adminname, "Test");
                default: return 0;
    }
    return adminname;
}

// Example
public OnPlayerConnect(playerid)
{
    new string[128], name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s %s has connected to the server!", GetAdminName(playerid), name);

    for(new i = 0; i <= GetPlayerPoolSize(); ++i) // This send message like "Founder J4Rr3x has connected to the server!" to all online admins
        if(IsPlayerConnected(i) && pInfo[playerid][pAdminLevel] > 0)
            SendClientMessage(i, -1, string);

    return 1;
}
Reply
#6

@J4Rr3x:

You should write it like this:
PHP код:
stock GetAdminName(playerid)
{
    new 
adminname[64];
    switch(
pInfo[playerid][pAdminLevel])
    {
        case 
1:adminname "Test";
        case 
2:adminname "Test";
        case 
3:adminname "Test";
        case 
4:adminname "Test";
        case 
5:adminname "Test";
    }
    return 
adminname;

If the player is admin level 0, it return nothing.
Reply
#7

Quote:
Originally Posted by Mencent
Посмотреть сообщение
@J4Rr3x:

You should write it like this:
PHP код:
stock GetAdminName(playerid)
{
    new 
adminname[64];
    switch(
pInfo[playerid][pAdminLevel])
    {
        case 
1:adminname "Test";
        case 
2:adminname "Test";
        case 
3:adminname "Test";
        case 
4:adminname "Test";
        case 
5:adminname "Test";
        default:return 
0;
    }
    return 
adminname;

If the player is admin level 0, it return nothing.
Yes, i've fixed my code. Thanks you!

pawn Код:
GetAdminName(playerid) // Use plain function instead of stock if you aren't making an include
{
    new adminname[128];
    switch(pInfo[playerid][pAdminLevel])
    {
        case 0: strpack(adminname, "Test"); // Right method and more faster.
        case 1: strpack(adminname, "Test");
        case 2: strpack(adminname, "Test");
        case 3: strpack(adminname, "Test");
        case 4: strpack(adminname, "Test");
        case 5: strpack(adminname, "Test");
                default: return 0;
    }
    return adminname;
}

// Example
public OnPlayerConnect(playerid)
{
    new string[128], name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "%s %s has connected to the server!", GetAdminName(playerid), name);

    for(new i = 0; i <= GetPlayerPoolSize(); ++i) // This send message like "Founder J4Rr3x has connected to the server!" to all online admins
        if(IsPlayerConnected(i) && pInfo[playerid][pAdminLevel] > 0)
            SendClientMessage(i, -1, string);

    return 1;
}
Reply
#8

You should write the may Mencent wrote and then show the connecting message in OnPlayerConnect.
Reply
#9

@J4Rr3x: I know it was example but it will confuse him more if you don't mention that he must load the player's data and assign them to variables FIRST before using that function.

@Mencent: You cannot return either string or integer value depending on the condition. It will give error 079: inconsistent return types (array & non-array).
Reply
#10

I did what i want myself and fixed it but thanks nevertheless.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)