SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/09/2018, 10:06 AM   #1
TaligaroW
Little Clucker
 
Join Date: Jun 2018
Posts: 24
Reputation: 0
Default /admins problem...

PHP Code:
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!
TaligaroW is offline   Reply With Quote
Old 30/09/2018, 10:19 AM   #2
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,228
Reputation: 205
Default Re: /admins problem...

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.
Calisthenics is offline   Reply With Quote
Old 30/09/2018, 10:20 AM   #3
ReD_HunTeR
Gangsta
 
ReD_HunTeR's Avatar
 
Join Date: Nov 2012
Posts: 572
Reputation: 54
Default Re: /admins problem...

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
ReD_HunTeR is offline   Reply With Quote
Old 30/09/2018, 10:58 AM   #4
CodeStyle175
Banned
 
Join Date: Apr 2014
Posts: 455
Reputation: 35
Default Re: /admins problem...

PHP Code:
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://forum.sa-mp.com/showthread.php?t=481257 what can save memory
CodeStyle175 is offline   Reply With Quote
Old 30/09/2018, 11:20 AM   #5
GhostHacker9
Big Clucker
 
GhostHacker9's Avatar
 
Join Date: Jan 2017
Location: New Zealand
Posts: 105
Reputation: 109
Default Re: /admins problem...

Quote:
Originally Posted by CodeStyle175 View Post
PHP Code:
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://forum.sa-mp.com/showthread.php?t=481257 what can save memory
Don't return arrays
GhostHacker9 is offline   Reply With Quote
Old 30/09/2018, 08:25 PM   #6
TaligaroW
Little Clucker
 
Join Date: Jun 2018
Posts: 24
Reputation: 0
Default Re: /admins problem...

thanks everyone!
TaligaroW is offline   Reply With Quote
Old 01/10/2018, 12:47 AM   #7
DarkBr
Huge Clucker
 
Join Date: Feb 2017
Location: ∫ f(x) dx
Posts: 362
Reputation: 12
Default Re: /admins problem...

Try..

Code:
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; 
}

Last edited by DarkBr; 01/10/2018 at 05:45 PM.
DarkBr is offline   Reply With Quote
Old 01/10/2018, 11:59 AM   #8
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 585
Reputation: 66
Default Re: /admins problem...

Yes, use a switch instead of else if all the way...
TheToretto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/admins problem nor15 Scripting Help 1 14/06/2013 06:45 PM
/admins some what problem CBCandyBoy Scripting Help 6 31/01/2013 11:14 AM
Admins problem SkL_MD Scripting Help 19 15/06/2012 10:07 PM
/admins problem James Coral Scripting Help 14 27/01/2012 12:10 PM
Problem with /admins cmd spider_bobi Help Archive 1 09/02/2010 11:22 PM


All times are GMT. The time now is 03:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.