Need some help with three options +rep
#1

Hey, so I have an admin system and I thought it'd be great to have "admin status"
such as

Usage: /status [1,2,3]
Hint: Available (1), Busy (2), Away (3)

now, I wanna show it on my admins list, here is my admin list from South Central Roleplay -

PHP код:

CMD
:admins(playeridparams[])
{
    new 
count 0;
    
SendClientMessage(playeridCOLOR_YELLOW"Online Administrators:");
    foreach (new 
Player) if (PlayerData[i][pAdmin] > && PlayerData[i][pAdminHide] < 1)
    {
        if (
PlayerData[i][pAdminDuty])
            
SendClientMessageEx(playeridCOLOR_NICEBLUE"* %s (Level: %d) - (Status)"ReturnName(i0), PlayerData[i][pAdmin]);
        else
            
SendClientMessageEx(playeridCOLOR_NICEBLUE"* %s (Level: %d) - (Status)"ReturnName(i0), PlayerData[i][pAdmin]);
        
count++;
    }
    if (!
count) {
        
SendClientMessage(playeridCOLOR_WHITE"There is no admins currently online");
    }
    return 
1;

And I want the admin status to be "Available" as default everytime, how I do this? I'm kinda new at this and I need some help around :P
Reply
#2

Код:
CMD:admins(playerid, params[]) 
{ 
    new count = 0; 

    SendClientMessage(playerid, COLOR_YELLOW, "Online Administrators:"); 

    foreach (new i : Player) if (PlayerData[i][pAdmin] > 0 && PlayerData[i][pAdminHide] < 1) 
    { 
        if (PlayerData[i][pAdminDuty]) 
            SendClientMessageEx(playerid, COLOR_NICEBLUE, "* %s (Level: %d) - (Status)", ReturnName(i, 0), PlayerData[i][pAdmin]); 

        else 
            SendClientMessageEx(playerid, COLOR_NICEBLUE, "* %s (Level: %d) - (Status)", ReturnName(i, 0), PlayerData[i][pAdmin]); 

        count++; 
    } 
    if (!count) { 
        SendClientMessage(playerid, COLOR_WHITE, "There is no admins currently online"); 
    } 
    return 1; 
}
You've not made it optional, you've stated this for each player, you need a 'switch' variable which allows the player to chose which one he wants.

I'll overlook this code later on today and I will make you a new one which will be better and functional.
Reply
#3

Quote:
Originally Posted by Scottylad
Посмотреть сообщение
Код:
CMD:admins(playerid, params[]) 
{ 
    new count = 0; 

    SendClientMessage(playerid, COLOR_YELLOW, "Online Administrators:"); 

    foreach (new i : Player) if (PlayerData[i][pAdmin] > 0 && PlayerData[i][pAdminHide] < 1) 
    { 
        if (PlayerData[i][pAdminDuty]) 
            SendClientMessageEx(playerid, COLOR_NICEBLUE, "* %s (Level: %d) - (Status)", ReturnName(i, 0), PlayerData[i][pAdmin]); 

        else 
            SendClientMessageEx(playerid, COLOR_NICEBLUE, "* %s (Level: %d) - (Status)", ReturnName(i, 0), PlayerData[i][pAdmin]); 

        count++; 
    } 
    if (!count) { 
        SendClientMessage(playerid, COLOR_WHITE, "There is no admins currently online"); 
    } 
    return 1; 
}
You've not made it optional, you've stated this for each player, you need a 'switch' variable which allows the player to chose which one he wants.

I'll overlook this code later on today and I will make you a new one which will be better and functional.
Thanks mate, I really apprcieate your help.
Reply
#4

Here's a brief example, please adapt it to your script as it won't do you any good to just copy and paste it in to your gamemode.

pawn Код:
// DEVELOPMENT SCRIPT

// ** INCLUDES

#include <a_samp>
#include <sscanf>
#include <zcmd>

// ** DEFINES

// *** GENERAL

#define MAX_ADMIN_LEVELS 5

// *** FUNCTIONS

#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

// *** DIALOGS

#define DIALOG_OK 0

// ** VARIABLES

// *** PER-PLAYER VARIABLES

new pAdminLevel[MAX_PLAYERS],
pStatus[MAX_PLAYERS];

// ** MAIN

main()
{
    print("Loaded \"admin_statuses.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    pAdminLevel[playerid] = RandomBetween(1, MAX_ADMIN_LEVELS);
    return 1;
}

// ** COMMANDS

CMD:admins(playerid, params[])
{
    ShowAdminsListDialog(playerid);
    return 1;
}

CMD:status(playerid, params[])
{
    if(isnull(params) || !IsNumeric(params)) return SendClientMessage(playerid, -1, "Usage: /status (1, 2, 3).");

    new value = strval(params);
    if(value <= 0 || value >= 4) return SendClientMessage(playerid, -1, "You have entered an invalid status value.");

    pStatus[playerid] = value - 1;

    new string[144];
    format(string, sizeof(string), "You have changed your status to %s.", GetPlayerStatus(playerid));
    SendClientMessage(playerid, -1, string);
    return 1;
}

// ** FUNCTIONS

stock IsNumeric(const string[]) return !sscanf(string, "{d}");

stock GetPlayerStatus(playerid)
{
    new string[10];
    switch(pStatus[playerid])
    {
        case 0: strcat(string, "Available");
        case 1: strcat(string, "Busy");
        case 2: strcat(string, "Away");
        default: strcat(string, "Unknown");
    }
    return string;
}

stock ShowAdminsListDialog(playerid)
{
    new string[256], temp[128], name[MAX_PLAYER_NAME], admins_online;
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!pAdminLevel[i]) continue;

        GetPlayerName(i, name, MAX_PLAYER_NAME);

        format(temp, sizeof(temp), "\n%s\t%d\t%s", name, pAdminLevel[i], GetPlayerStatus(i));
        strcat(string, temp);

        admins_online ++;
    }

    if(!admins_online)
    {
        return ShowPlayerDialog(playerid, DIALOG_OK, DIALOG_STYLE_MSGBOX, "Admin List", "No administrators are online.", "Close", "");
    }
    else
    {
        strins(string, "Name\tLevel\tStatus", 0);
        return ShowPlayerDialog(playerid, DIALOG_OK, DIALOG_STYLE_TABLIST_HEADERS, "Admin List", string, "Close", "");
    }
}

stock RandomBetween(minimum, maximum)
{
    new selected = random(maximum - minimum) + minimum;
    return selected;
}
Reply
#5

Quote:
Originally Posted by Kevln
Посмотреть сообщение
Here's a brief example, please adapt it to your script as it won't do you any good to just copy and paste it in to your gamemode.

pawn Код:
// DEVELOPMENT SCRIPT

// ** INCLUDES

#include <a_samp>
#include <sscanf>
#include <zcmd>

// ** DEFINES

// *** GENERAL

#define MAX_ADMIN_LEVELS 5

// *** FUNCTIONS

#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

// *** DIALOGS

#define DIALOG_OK 0

// ** VARIABLES

// *** PER-PLAYER VARIABLES

new pAdminLevel[MAX_PLAYERS],
pStatus[MAX_PLAYERS];

// ** MAIN

main()
{
    print("Loaded \"admin_statuses.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    pAdminLevel[playerid] = RandomBetween(1, MAX_ADMIN_LEVELS);
    return 1;
}

// ** COMMANDS

CMD:admins(playerid, params[])
{
    ShowAdminsListDialog(playerid);
    return 1;
}

CMD:status(playerid, params[])
{
    if(isnull(params) || !IsNumeric(params)) return SendClientMessage(playerid, -1, "Usage: /status (1, 2, 3).");

    new value = strval(params);
    if(value <= 0 || value >= 4) return SendClientMessage(playerid, -1, "You have entered an invalid status value.");

    pStatus[playerid] = value - 1;

    new string[144];
    format(string, sizeof(string), "You have changed your status to %s.", GetPlayerStatus(playerid));
    SendClientMessage(playerid, -1, string);
    return 1;
}

// ** FUNCTIONS

stock IsNumeric(const string[]) return !sscanf(string, "{d}");

stock GetPlayerStatus(playerid)
{
    new string[10];
    switch(pStatus[playerid])
    {
        case 0: strcat(string, "Available");
        case 1: strcat(string, "Busy");
        case 2: strcat(string, "Away");
        default: strcat(string, "Unknown");
    }
    return string;
}

stock ShowAdminsListDialog(playerid)
{
    new string[256], temp[128], name[MAX_PLAYER_NAME], admins_online;
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(!pAdminLevel[i]) continue;

        GetPlayerName(i, name, MAX_PLAYER_NAME);

        format(temp, sizeof(temp), "\n%s\t%d\t%s", name, pAdminLevel[i], GetPlayerStatus(i));
        strcat(string, temp);

        admins_online ++;
    }

    if(!admins_online)
    {
        return ShowPlayerDialog(playerid, DIALOG_OK, DIALOG_STYLE_MSGBOX, "Admin List", "No administrators are online.", "Close", "");
    }
    else
    {
        strins(string, "Name\tLevel\tStatus", 0);
        return ShowPlayerDialog(playerid, DIALOG_OK, DIALOG_STYLE_TABLIST_HEADERS, "Admin List", string, "Close", "");
    }
}

stock RandomBetween(minimum, maximum)
{
    new selected = random(maximum - minimum) + minimum;
    return selected;
}
I'm actually learning from these codes, although. and for an example how do I do that in "Admin list" it will count how much administrators online or hidden? like " Administrators online (X) hidden (Y)
Reply
#6

Quote:
Originally Posted by DemME
Посмотреть сообщение
I'm actually learning from these codes, although. and for an example how do I do that in "Admin list" it will count how much administrators online or hidden? like " Administrators online (X) hidden (Y)
Print the variable "admins_online".
Reply
#7

Quote:
Originally Posted by Kevln
Посмотреть сообщение
Print the variable "admins_online".
And how do I do this? I mentioned already that it's a little be difficult to me.
Reply
#8

Quote:
Originally Posted by DemME
Посмотреть сообщение
And how do I do this? I mentioned already that it's a little be difficult to me.
If you cannot even do something as simple as that, then you're not ready to be scripting anything, but rather learning.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)