/admins problem...
#1

PHP код:
CMD:admins(playerid,params[])
{
    if(
IsPlayerConnected(playerid))
    {
        new 
string[10000];
        new 
j;
        
GetPlayerPoolSize();
        for(new 
id=0;id<=j;id++)
        {
            if(
IsPlayerConnected(id))
            {
                new 
sendername[MAX_PLAYER_NAME];
                
GetPlayerName(idsendernamesizeof(sendername));
                
format(iname,sizeof(iname),"%s.ini",sendername);
                if(
dini_Int(iname,"Admin")!=0)
                {
                        new 
admin[100];
                        if(
dini_Int(iname,"Admin")== 1) { admin "Админ ниво [ 1 ]"; }
                        else if(
dini_Int(iname,"Admin")== 2) { admin "Админ ниво [ 2 ]"; }
                        else if(
dini_Int(iname,"Admin")== 3) { admin "Админ ниво [ 3 ]"; }
                        else if(
dini_Int(iname,"Admin")== 4) { admin "Админ ниво [ 4 ]"; }
                        else if(
dini_Int(iname,"Admin")== 5) { admin "[ Гл.Администратор ]"; }
                        else if(
dini_Int(iname,"Admin")== 6) { admin "[ Заместник-началник ]"; }
                        else if(
dini_Int(iname,"Admin")== 7) { admin "[ Собственик ]"; }
                        new 
strpart[256];
                        
format(strpart256"{FFFFFF}%s {FF0000}%s (ID: %d)\n"adminsendernameid);
                        
strins(string,strpart,strlen(string));
                        
                }
            }
        }
        
ShowPlayerDialog(playerid21323123DIALOG_STYLE_MSGBOX"Онлайн Администратори"string,
"ОК","");
    }
    return 
1;

The problem is that,when i type /admins, it shows me [MY SERVERNAME] The specified command was not found!
Reply
#2

dini_Int keeps opening the file to read the value. Do you realize if a player is owner, it will open their file 8 times just for that player? Now count the rest of the players they are online and think how slow and bad way it is.

Admin status is something that needs to be stored in a global array. A switch or an constant array for the description/title is better than multiple else if statements.

Why do you check if the player who typed the command is connected? That was a very, very, very old exploit which has been fixed over 10 years ago.

A dialog can show approximately 4300 characters, 10000 is overkill.

The unknown command is given because of the run time error 10: "Native function failed" and the function that fails is `strins`. There is `strcat` function if you want to concatenate two strings together.
Reply
#3

explain what this cmd is supposed to do?
is it supposed to check offline admins? then you are doing alot of things wrong there!
why are u using 10,000 value? it eats your space nothing else.

EDIT: too late
Reply
#4

PHP код:
UserName(p){
    new 
s[24];
    
GetPlayerName(pid,s,24);
    return 
s;
}
UserFile(p){
    new 
s[90];
    
format(s,90,"users/%s.ini",UserName(p));
    return 
s;
}
new 
AdminRank[][]={"","Админ ниво [ 1 ]","Админ ниво [ 2 ]","Админ ниво [ 3 ]","Админ ниво [ 4 ]","[ Гл.Администратор ]","[ Заместник-началник ]",
    
"[ Собственик ]"};
enum {
    
dialog_admins
};
CMD:admins(pid) {  
    new 
bs[1024],
        
adminlvl;
    foreach(new 
Player){ 
        
adminlvl=dini_Int(UserFile(i),"Admin");
        if(!
adminlvl)continue;
        
format(bs,1024,"%s%s / %s / %d\n",bs,AdminRank[adminlvl],UserName(i),i);
    } 
    
ShowPlayerDialog(piddialog_adminsDIALOG_STYLE_MSGBOX"Онлайн Администратори"bs"ОК",""); 
    return 
1

don't create new variables inside loop
when you use admin ranks, its samrter to create array of rank names
when character connects with server, load their admin ranks and other things into array
you dont need to check on cmd is player connected
use ysi foreach for looping throw players, because its the fastest and smartest way to do it.
and use this include https://sampforum.blast.hk/showthread.php?tid=481257 what can save memory
Reply
#5

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
PHP код:
UserName(p){
    new 
s[24];
    
GetPlayerName(pid,s,24);
    return 
s;
}
UserFile(p){
    new 
s[90];
    
format(s,90,"users/%s.ini",UserName(p));
    return 
s;
}
new 
AdminRank[][]={"","Админ ниво [ 1 ]","Админ ниво [ 2 ]","Админ ниво [ 3 ]","Админ ниво [ 4 ]","[ Гл.Администратор ]","[ Заместник-началник ]",
    
"[ Собственик ]"};
enum {
    
dialog_admins
};
CMD:admins(pid) {  
    new 
bs[1024],
        
adminlvl;
    foreach(new 
Player){ 
        
adminlvl=dini_Int(UserFile(i),"Admin");
        if(!
adminlvl)continue;
        
format(bs,1024,"%s%s / %s / %d\n",bs,AdminRank[adminlvl],UserName(i),i);
    } 
    
ShowPlayerDialog(piddialog_adminsDIALOG_STYLE_MSGBOX"Онлайн Администратори"bs"ОК",""); 
    return 
1

don't create new variables inside loop
when you use admin ranks, its samrter to create array of rank names
when character connects with server, load their admin ranks and other things into array
you dont need to check on cmd is player connected
use ysi foreach for looping throw players, because its the fastest and smartest way to do it.
and use this include https://sampforum.blast.hk/showthread.php?tid=481257 what can save memory
Don't return arrays
Reply
#6

thanks everyone!
Reply
#7

Try..

Код:
CMD:admins(playerid,params[]) 
{ 
    new estr[200], levelname[24], pname[24], posfile[50], jval, adminids=0; 
    for(new i=0, q=GetPlayerPoolSize( ); i<=q; i++)
    { 
        if(!IsPlayerConnected(i))
        	continue;
        GetPlayerName(i, pname, sizeof(pname)); 
        format(posfile, sizeof(posfile),"%s.ini",pname);
        jval=dini_Int(iname,"Admin");
        switch(jval)
        {
         	case 1:levelname = "Админ ниво [ 1 ]";
         	case 2:levelname = "Админ ниво [ 2 ]";
         	case 3:levelname = "Админ ниво [ 3 ]";
         	case 4:levelname = "Админ ниво [ 4 ]";
         	case 5:levelname = "[ Гл.Администратор ]";
         	case 6:levelname = "[ Заместник-началник ]";
         	case 7:levelname = "[ Собственик ]";
         	default: continue;
	}
	adminids++;

	new strpart[69]; 
        format(strpart, 69, "{FFFFFF}%s {FF0000}%s (ID: %d)\n\r", levelname, pname, i); 
        strcat(estr, strpart, sizeof estr); 
    }         
    if(adminids)
    {               
        ShowPlayerDialog(playerid, 21323123, DIALOG_STYLE_MSGBOX, "Онлайн Администратори", estr,"ОК",#); 
    }
    else
    {
    	//admins not found
    }
    return 1; 
}
Reply
#8

Yes, use a switch instead of else if all the way...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)