Loop show all player job
#1

waaaaaa help me :P pls

Screen:



pawn Код:
CMD:pjobs(playerid, params[])
{
    new str[50], STR[512];
    strcat(STR, "Name(ID)\tJob\n");
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(pInfo[i][USER_LOGGED_IN] == true)
        format(str, sizeof(str),"%s(%i)\t\%s\n", GetPlayerName(i), i, GetClassName(i));
        if(strlen(str) < 1) strdel(str, 0, 50);
        strcat(STR, str);
    }
    ShowPlayerDialog(playerid, DIALOG_PJOBS, DIALOG_STYLE_TABLIST_HEADERS, ""COL_BLUE"Players Jobs", STR, "Exit", "");
    return 1;
}
Reply
#2

https://sampwiki.blast.hk/wiki/GetPlayerName

The function does not return the name but it is passed by reference.

https://sampwiki.blast.hk/wiki/GetPlayerPoolSize

Player pool is very useful to reduce the iterations. foreach/y_iterate is even better.

The problem is not using brackets to make it a block of code and strcat is called again and again.
Reply
#3

Here you go:

PHP код:
CMD:pjobs(playeridparams[])
{
    new 
str[512] = "Name(ID)\tJob";
    for(new 
i=GetPlayerPoolSize(),n[MAX_PLAYER_NAME]; != -1i--)
    {
        if(!
IsPlayerConnected(i) || !pInfo[i][USER_LOGGED_IN]) continue;
        
GetPlayerName(i,n,MAX_PLAYER_NAME);
        
format(strsizeof(str),"%s\n%s (%i)\t%s",str,niGetClassName(i));
    }
    
ShowPlayerDialog(playeridDIALOG_PJOBSDIALOG_STYLE_TABLIST_HEADERS""COL_BLUE"Players Jobs"str"Exit""");
    return 
1;

Show us your GetClassName
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/GetPlayerName

The function does not return the name but it is passed by reference.

https://sampwiki.blast.hk/wiki/GetPlayerPoolSize

Player pool is very useful to reduce the iterations. foreach/y_iterate is even better.

The problem is not using brackets to make it a block of code and strcat is called again and again.
Ohh ok, i redefined GetPlayeName

pawn Код:
stock GetPlayerNameEx(playerid)
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    return pname;
}
#define GetPlayerName(%0)   GetPlayerNameEx(%0)
I had time without scripting, I did not know that function(GetPlayerPoolSize), thanks!

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Here you go:

PHP код:
CMD:pjobs(playeridparams[])
{
    new 
str[512] = "Name(ID)\tJob";
    for(new 
i=GetPlayerPoolSize(),n[MAX_PLAYER_NAME]; != -1i--)
    {
        if(!
IsPlayerConnected(i) || !pInfo[i][USER_LOGGED_IN]) continue;
        
GetPlayerName(i,n,MAX_PLAYER_NAME);
        
format(strsizeof(str),"%s\n%s (%i)\t%s",str,niGetClassName(i));
    }
    
ShowPlayerDialog(playeridDIALOG_PJOBSDIALOG_STYLE_TABLIST_HEADERS""COL_BLUE"Players Jobs"str"Exit""");
    return 
1;

Show us your GetClassName
Thanks friend,

pawn Код:
stock GetClassName(playerid)
{
    new ClassName[MAX_PLAYERS];
   
    if(GetPlayerTeam(playerid) == TEAM_CIVILIAN)
    {
        if(pInfo[playerid][Job] == 0) SetPVarString(playerid, "JobName", "Terrorist");
        if(pInfo[playerid][Job] == 1) SetPVarString(playerid, "JobName", "Hitman");
        if(pInfo[playerid][Job] == 2) SetPVarString(playerid, "JobName", "Weapon Dealer");
        if(pInfo[playerid][Job] == 3) SetPVarString(playerid, "JobName", "Rapist");
    }
   
    if(GetPlayerTeam(playerid) == TEAM_POLICE) SetPVarString(playerid, "JobName", ""COL_POLICE"Police");
    if(GetPlayerTeam(playerid) == TEAM_SWAT) SetPVarString(playerid, "JobName", ""COL_FBI"S.W.A.T");
    if(GetPlayerTeam(playerid) == TEAM_FBI) SetPVarString(playerid, "JobName", ""COL_FBI"F.B.I");
    if(GetPlayerTeam(playerid) == TEAM_CIA) SetPVarString(playerid, "JobName", ""COL_CIA"C.I.A");
    if(GetPlayerTeam(playerid) == TEAM_ARMY) SetPVarString(playerid, "JobName", ""COL_ARMY"ARMY");

    GetPVarString(playerid, "JobName", ClassName, sizeof(ClassName));
    return ClassName;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)