Help with my Name Colour Script?
#1

Alrighty, I'm in the need of some help. I know there must be an easier way to have this code. I have ZCMD and YCMD if that's a better way to shorten it.
pawn Код:
#define COLOR_BLUE 0x0000FFAA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_PURPLE 0x9900FFAA
#define COLOR_CYAN 0x99FFFFAA
#define COLOR_PINK 0xFF66FFAA
#define COLOR_LIME 0x99FF00AA
#define COLOR_RED 0xEB000FFF
#define COLOR_WHITE 0xFFFFD5FF

#define FILTERSCRIPT
#include <a_samp>
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Name Colour Script by CrystalMethod");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Name Colour Script by CrystalMethod");
    print("----------------------------------\n");
}

#endif

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/nc", cmdtext, true, 10) == 0)
    {
            SendClientMessage(playerid, COLOR_WHITE, "Change the colour of your name by doing /nc [desired colour]")
            ;
            SendClientMessage(playerid, COLOR_WHITE, "List of colours:")
            ;
            SendClientMessage(playerid, COLOR_BLUE, "Blue")
            ;
            SendClientMessage(playerid, COLOR_GREY, "Grey")
            ;
            SendClientMessage(playerid, COLOR_GREEN, "Green")
            ;
            SendClientMessage(playerid, COLOR_PURPLE, "Purple")
            ;
            SendClientMessage(playerid, COLOR_CYAN, "Cyan")
            ;
            SendClientMessage(playerid, COLOR_PINK, "Pink")
            ;
            SendClientMessage(playerid, COLOR_LIME, "Lime")
            ;
            SendClientMessage(playerid, COLOR_RED, "Red")
            ;
    }
   

    if (strcmp("/nc blue", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_BLUE)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc grey", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_GREY)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc green", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_GREEN)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc purple", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_PURPLE)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc cyan", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_CYAN)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc pink", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_PINK)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc lime", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_LIME)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    if (strcmp("/nc red", cmdtext, true, 10) == 0)
    {
            SetPlayerColor(playerid, COLOR_RED)
            ;
            SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!")
            ;
    }
   
    return 1;


}
You can see how every (what should be) sub-command is it's own command, and must be typed exactly like that for it to work. So, uh, any help?
(I'm still a beginner, so go easy? D: )
Reply
#2

You can use a dialog (dialog_style_list).

https://sampwiki.blast.hk/wiki/ShowPlayerDialog
Reply
#3

I've made one for you, if the DIALOG ID number has conflicted, change the DIALOG ID number to 500 or number that you like.

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#define COLOR_BLUE 0x0000FFAA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_PURPLE 0x9900FFAA
#define COLOR_CYAN 0x99FFFFAA
#define COLOR_PINK 0xFF66FFAA
#define COLOR_LIME 0x99FF00AA
#define COLOR_RED 0xEB000FFF
#define COLOR_WHITE 0xFFFFD5FF

#include <a_samp>
#include <zcmd>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Name Colour Script by CrystalMethod ");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    print("\n--------------------------------------");
    print(" Name Colour Script by CrystalMethod has been unloaded!");
    print("--------------------------------------\n");
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Name Colour Script by CrystalMethod");
    print("----------------------------------\n");
}

#endif


CMD:nc(playerid,params[])
{
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Name colour selection", "Blue\nGrey\nGreen\nPurple\nCyan\nPink\nLime\nRed", "Choose", "Exit");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(response)
    {
        switch(dialogid)
        {
            case 1:
            {
                switch(listitem)
                {
                    case 1: return SetPlayerColor(playerid, COLOR_BLUE), SendClientMessage(playerid, COLOR_BLUE, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 2: return SetPlayerColor(playerid, COLOR_GREY), SendClientMessage(playerid, COLOR_GREY, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 3: return SetPlayerColor(playerid, COLOR_GREEN), SendClientMessage(playerid, COLOR_GREEN, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 4: return SetPlayerColor(playerid, COLOR_PURPLE), SendClientMessage(playerid, COLOR_PURPLE, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 5: return SetPlayerColor(playerid, COLOR_CYAN), SendClientMessage(playerid, COLOR_CYAN, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 6: return SetPlayerColor(playerid, COLOR_PINK), SendClientMessage(playerid, COLOR_PINK, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 7: return SetPlayerColor(playerid, COLOR_LIME), SendClientMessage(playerid, COLOR_LIME, "Name colour has been changed. (The colour of this message is same with the name colour.");
                    case 8: return SetPlayerColor(playerid, COLOR_RED), SendClientMessage(playerid, COLOR_RED, "Name colour has been changed. (The colour of this message is same with the name colour.");
                }
            }
        }
    }
    return 1;
}
And download ZCMD here if you see this error.

Код:
C:\Documents and Settings\User\Desktop\0.3x script\filterscripts\color.pwn(16) : fatal error 100: cannot read from file: "zcmd"
Reply
#4

Command method

pawn Код:
CMD:nc(playerid, arg[])
{
    if(!strcmp(arg, "blue", true)) { SetPlayerColor(playerid, COLOR_BLUE); }
    else if(!strcmp(arg, "grey", true)) { SetPlayerColor(playerid, COLOR_GREY); }
    else if(!strcmp(arg, "green", true)) { SetPlayerColor(playerid, COLOR_GREEN); }
    else if(!strcmp(arg, "purple", true)) { SetPlayerColor(playerid, COLOR_PURPLE); }
    else if(!strcmp(arg, "cyan", true)) { SetPlayerColor(playerid, COLOR_CYAN); }
    else if(!strcmp(arg, "pink", true)) { SetPlayerColor(playerid, COLOR_PINK); }
    else if(!strcmp(arg, "lime", true)) { SetPlayerColor(playerid, COLOR_LIME); }
    else if(!strcmp(arg, "red", true)) { SetPlayerColor(playerid, COLOR_RED); }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "Change the colour of your name by doing /nc [desired colour]");
        SendClientMessage(playerid, COLOR_WHITE, "List of colours:");
        SendClientMessage(playerid, COLOR_BLUE, "Blue");
        SendClientMessage(playerid, COLOR_GREY, "Grey");
        SendClientMessage(playerid, COLOR_GREEN, "Green");
        SendClientMessage(playerid, COLOR_PURPLE, "Purple");
        SendClientMessage(playerid, COLOR_CYAN, "Cyan");
        SendClientMessage(playerid, COLOR_PINK, "Pink");
        SendClientMessage(playerid, COLOR_LIME, "Lime");
        SendClientMessage(playerid, COLOR_RED, "Red");
        return 1;
    }
    SendClientMessage(playerid, COLOR_WHITE, "Name colour changed!");
    return 1;
}
@LeeXian99 I disagree with doing this

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(response)
    {
        switch(dialogid)
        {
If you do that then you might have another switch(dialogid) when reponse is 0, this is not good it means the code would be separated from where response is 1 that could be a pain in the ass to work with it should really be the following code convention to prevent potentially hundreds of lines between areas of code that should be grouped for readability. But if I was using dialogs I would use y_inline and y_dialog anyways

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        if(response)
        {
        }
        else
        {
        }
        {
That is a far better practice.
Reply
#5

Use my color changer COLOR CHANGER-CLICK ME
Reply
#6

As They Said, Use You can use a dialog (dialog_style_list).

https://sampwiki.blast.hk/wiki/ShowPlayerDialog
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Command method
*Your code*

@LeeXian99 I disagree with doing this

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(response)
    {
        switch(dialogid)
        {
If you do that then you might have another switch(dialogid) when reponse is 0, this is not good it means the code would be separated from where response is 1 that could be a pain in the ass to work with it should really be the following code convention to prevent potentially hundreds of lines between areas of code that should be grouped for readability. But if I was using dialogs I would use y_inline and y_dialog anyways

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        if(response)
        {
        }
        else
        {
        }
        {
That is a far better practice.
I learned a lesson today! Thanks Pottus, rep.
Reply
#8

Quote:
Originally Posted by kalanerik99
Посмотреть сообщение
Use my color changer COLOR CHANGER-CLICK ME
he ask for help him, not for ads you fs
Reply
#9

ya2 -,-
Reply
#10

Problem fixed.
Thanks everyone for your help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)