SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 16/02/2019, 09:19 AM   #1
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 66
Reputation: 0
Default /admins - command problem

pawn Code:
CMD:admins(playerid)
{
     new count=0, PlayerName[MAX_PLAYER_NAME], rankname[32],color[100];
     new list1[900];
     strcat(list1, "{FFFFFF}NO\t{FFFFFF}Name(ID)\t{FFFFFF}Level\n");
     foreach(Player, i)
     {
           if(playerData[i][playerLevel] > 0)
           {
              GetPlayerName(i, PlayerName, sizeof(PlayerName));
              switch(playerData[i][playerLevel])
              {
                 case 1: { rankname = "{FFFFFF}LEVEL 1"; }
                 case 2: { rankname = "{FFFFFF}LEVEL 2"; }
                 case 3: { rankname = "{FFFFFF}LEVEL 3"; }
                 case 4: { rankname = "{FFFFFF}LEVEL 4"; }
                 case 5: { rankname = "{FFFFFF}LEVEL 5"; }
                 case 6: { rankname = "{FFFFFF}LEVEL 6"; }
                 case 7: { rankname = "{FFFFFF}LEVEL 7"; }
                 case 8: { rankname = "{FFFFFF}LEVEL 8"; }
              }
              if(playerData[i][playerAdminDuty] == true)
              {
                 color = "{FF0770}"; // pink
              }
              else color = "{C0C0C0}"; //grey
              format(list1, sizeof(list1), "%s\n%d\t%s%s(%d)\t%s\n", list1, count + 1,color, PlayerName, i, rankname);
              count++;
           }
           if(count == 0)
           {
             SendClientMessage(playerid, -1, "There are no administrators online.");
             return true;
           }
           ShowPlayerDialog(playerid, 555, DIALOG_STYLE_TABLIST_HEADERS, "Online Admins",list1, "Close", "");
     }
     return 1;
}

The problem in this script is that sometimes it is only outputing "There are no administrators online" from time to time even where is are administrators online.

Please help.
Hammad123 is offline   Reply With Quote
Old 16/02/2019, 05:43 PM   #2
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 66
Reputation: 0
Default Re: /admins - command problem

bump help me please. I will +rep whoever helps me
Hammad123 is offline   Reply With Quote
Old 16/02/2019, 06:21 PM   #3
DarkBr
Huge Clucker
 
Join Date: Feb 2017
Location: ∫ f(x) dx
Posts: 373
Reputation: 11
Default Re: /admins - command problem

TRY, compile

PHP Code:
CMD:admins(playerid)
{
     new 
count=0PlayerName[MAX_PLAYER_NAME], rankname[32],color[100];
     new 
list1[256];
     
strcat(list1"{FFFFFF}NO\t{FFFFFF}Name(ID)\t{FFFFFF}Level\n");
     foreach(
Playeri)
     {
        if(!
playerData[i][playerLevel])
            continue;
        
count++;
        
GetPlayerName(iPlayerNamesizeof(PlayerName));
        
color = ((playerData[i][playerAdminDuty])?("{FF0770}"):("{C0C0C0}"));
        
format(list1sizeof(list1), "%s\n%d\t%s%s(%d)\t{FFFFFF}LEVEL %i\n"list1count 1,colorPlayerNameiplayerData[i][playerLevel]);
     }
    if(!
count)
    {
        
SendClientMessage(playerid, -1"There are no administrators online.");
    }
    else
    {
        
ShowPlayerDialog(playerid555DIALOG_STYLE_TABLIST_HEADERS"Online Admins",list1"Close""");
    }
       return 
1;

DarkBr is offline   Reply With Quote
Old 16/02/2019, 10:07 PM   #4
d3ll
Big Clucker
 
Join Date: May 2014
Location: England
Posts: 97
Reputation: 17
Default Re: /admins - command problem

Problem is mate you've put the 'no admin' handler inside the loop - example, when the loop starts from player 0 if he isn't administrator it terminates because of the return. Always let the loop finish, unless you've found what you have looked for i guess?

pawn Code:
CMD:admins(playerid)
{
    new count, PlayerName[MAX_PLAYER_NAME], rankname[32], color[100];
    new list1[900];
    strcat(list1, "{FFFFFF}NO\t{FFFFFF}Name(ID)\t{FFFFFF}Level\n");
    foreach(Player, i)
    {
        if(playerData[i][playerLevel] > 0)
        {
            GetPlayerName(i, PlayerName, sizeof(PlayerName));
            switch(playerData[i][playerLevel])
            {
                case 1: { rankname = "{FFFFFF}LEVEL 1"; }
                case 2: { rankname = "{FFFFFF}LEVEL 2"; }
                case 3: { rankname = "{FFFFFF}LEVEL 3"; }
                case 4: { rankname = "{FFFFFF}LEVEL 4"; }
                case 5: { rankname = "{FFFFFF}LEVEL 5"; }
                case 6: { rankname = "{FFFFFF}LEVEL 6"; }
                case 7: { rankname = "{FFFFFF}LEVEL 7"; }
                case 8: { rankname = "{FFFFFF}LEVEL 8"; }
            }
            if(playerData[i][playerAdminDuty] == true)
            {
                color = "{FF0770}"; // pink
            }
            else color = "{C0C0C0}"; //grey
            format(list1, sizeof(list1), "%s\n%d\t%s%s(%d)\t%s\n", list1, count + 1,color, PlayerName, i, rankname);
            count++;
        }
    }
    if(count == 0)
    {
        SendClientMessage(playerid, -1, "There are no administrators online.");
        return true;
    }
    ShowPlayerDialog(playerid, 555, DIALOG_STYLE_TABLIST_HEADERS, "Online Admins",list1, "Close", "");
    return 1;
}
__________________
Hi, if your reading this I love you.
d3ll is offline   Reply With Quote
Old 16/02/2019, 11:57 PM   #5
ConnorW
Huge Clucker
 
ConnorW's Avatar
 
Join Date: Apr 2012
Location: Los Santos
Posts: 224
Reputation: 71
Default Re: /admins - command problem

What...

pawn Code:
color[100];
pawn Code:
if(playerData[i][playerAdminDuty] == true)
            {
                color = "{FF0770}"; // pink
            }
            else color = "{C0C0C0}"; //grey
can easy be done
pawn Code:
new color, string[12];
color = 0xFF0770AA >>> 8;
format(string, 12, "{%06x}", color);
__________________
retired
ConnorW is offline   Reply With Quote
Old 17/02/2019, 10:08 AM   #6
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 66
Reputation: 0
Default Re: /admins - command problem

Thank you all! how to give rep?
Hammad123 is offline   Reply With Quote
Old 17/02/2019, 10:57 AM   #7
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 515
Reputation: 52
Default Re: /admins - command problem

Press the star near the user's post at the left
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Old 18/02/2019, 01:27 PM   #8
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 66
Reputation: 0
Default Re: /admins - command problem

thanks sir
Hammad123 is offline   Reply With Quote
Old 19/02/2019, 01:15 PM   #9
Hammad123
Big Clucker
 
Join Date: Jan 2017
Location: Locating...
Posts: 66
Reputation: 0
Default Re: /admins - command problem

Quote:
Originally Posted by d3ll View Post
Problem is mate you've put the 'no admin' handler inside the loop - example, when the loop starts from player 0 if he isn't administrator it terminates because of the return. Always let the loop finish, unless you've found what you have looked for i guess?

pawn Code:
CMD:admins(playerid)
{
    new count, PlayerName[MAX_PLAYER_NAME], rankname[32], color[100];
    new list1[900];
    strcat(list1, "{FFFFFF}NO\t{FFFFFF}Name(ID)\t{FFFFFF}Level\n");
    foreach(Player, i)
    {
        if(playerData[i][playerLevel] > 0)
        {
            GetPlayerName(i, PlayerName, sizeof(PlayerName));
            switch(playerData[i][playerLevel])
            {
                case 1: { rankname = "{FFFFFF}LEVEL 1"; }
                case 2: { rankname = "{FFFFFF}LEVEL 2"; }
                case 3: { rankname = "{FFFFFF}LEVEL 3"; }
                case 4: { rankname = "{FFFFFF}LEVEL 4"; }
                case 5: { rankname = "{FFFFFF}LEVEL 5"; }
                case 6: { rankname = "{FFFFFF}LEVEL 6"; }
                case 7: { rankname = "{FFFFFF}LEVEL 7"; }
                case 8: { rankname = "{FFFFFF}LEVEL 8"; }
            }
            if(playerData[i][playerAdminDuty] == true)
            {
                color = "{FF0770}"; // pink
            }
            else color = "{C0C0C0}"; //grey
            format(list1, sizeof(list1), "%s\n%d\t%s%s(%d)\t%s\n", list1, count + 1,color, PlayerName, i, rankname);
            count++;
        }
    }
    if(count == 0)
    {
        SendClientMessage(playerid, -1, "There are no administrators online.");
        return true;
    }
    ShowPlayerDialog(playerid, 555, DIALOG_STYLE_TABLIST_HEADERS, "Online Admins",list1, "Close", "");
    return 1;
}
Can't compile this script
Hammad123 is offline   Reply With Quote
Old 19/02/2019, 01:20 PM   #10
RenanMsV
Big Clucker
 
Join Date: May 2016
Posts: 146
Reputation: 6
Default Re: /admins - command problem

you dont need this switch

pawn Code:
// do this
format(rankname, sizeof(rankname), "{FFFFFF}LEVEL %d", playerData[i][playerLevel]);

//instead of this
switch(playerData[i][playerLevel])
{
    case 1: { rankname = "{FFFFFF}LEVEL 1"; }
    case 2: { rankname = "{FFFFFF}LEVEL 2"; }
    case 3: { rankname = "{FFFFFF}LEVEL 3"; }
    case 4: { rankname = "{FFFFFF}LEVEL 4"; }
    case 5: { rankname = "{FFFFFF}LEVEL 5"; }
    case 6: { rankname = "{FFFFFF}LEVEL 6"; }
    case 7: { rankname = "{FFFFFF}LEVEL 7"; }
    case 8: { rankname = "{FFFFFF}LEVEL 8"; }
}
__________________


Free SAMP Server Hosting (20 slots): http://ultra-h.com
RenanMsV 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
Help /admins command unknown command alekschowee Scripting Help 18 30/06/2016 11:44 PM
/admins Command Help Filbert Scripting Help 1 27/05/2016 10:41 AM
[Help] problem with /admins command GunZ75 Scripting Help 2 16/09/2014 10:22 PM
/admins Command Problem Youssef214 Scripting Help 9 21/06/2014 10:16 AM
[Question]: Problem with admins command. GBLTeam Scripting Help 0 03/05/2012 12:23 PM


All times are GMT. The time now is 08:23 AM.


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