Commands do bring one
#1

Hi, I have a few commands and I would be reduced to one example of what's going on:

/command [createbillboard, destroybillboard, editbillboard]

Код:
CMD:createbillboard(playerid, params[])
{
	static
	    id = -1;

    if (PlayerData[playerid][pAdmin] < 5)
	    return SendErrorMessage(playerid, "You don't have permission to use this command.");

	id = Billboard_Create(playerid, -1);

	if (id == -1)
	    return SendErrorMessage(playerid, "The server has reached the limit for billboards.");

	SendServerMessage(playerid, "You have successfully created billboard ID: %d.", id);
	return 1;
}

CMD:destroybillboard(playerid, params[])
{
	static
	    id = 0;

    if (PlayerData[playerid][pAdmin] < 5)
	    return SendErrorMessage(playerid, "You don't have permission to use this command.");

	if (sscanf(params, "d", id))
	    return SendSyntaxMessage(playerid, "/destroybillboard [bb id]");

	if ((id < 0 || id >= MAX_BILLBOARDS) || !BillBoardData[id][bbExists])
	    return SendErrorMessage(playerid, "You have specified an invalid billboard ID.");

	Billboard_Delete(id);
	SendServerMessage(playerid, "You have successfully destroyed billboard ID: %d.", id);
	return 1;
}

CMD:editbillboard(playerid, params[])
{
	static
	    id,
	    type[24],
	    string[128];

	if (PlayerData[playerid][pAdmin] < 5)
	    return SendErrorMessage(playerid, "You don't have permission to use this command.");

	if (sscanf(params, "ds[24]S()[128]", id, type, string))
 	{
	 	SendSyntaxMessage(playerid, "/editbillboard [id] [name]");
	    SendClientMessage(playerid, COLOR_YELLOW, "[NAMES]:{FFFFFF} location, name, price, message, owner, range");
		return 1;
	}
	if ((id < 0 || id >= MAX_BILLBOARDS) || !BillBoardData[id][bbExists])
	    return SendErrorMessage(playerid, "You have specified an invalid business ID.");

	if (!strcmp(type, "location", true))
	{
 		GetPlayerPos(playerid, BillBoardData[id][bbPos][0], BillBoardData[id][bbPos][1], BillBoardData[id][bbPos][2]);

		Billboard_Refresh(id);
		Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the location of billboard ID: %d.", ReturnName(playerid, 0), id);
	}
	else if (!strcmp(type, "price", true))
	{
	    new price;

	    if (sscanf(string, "d", price))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [price] [new price]");

	    BillBoardData[id][bbPrice] = price;

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the price of billboard ID: %d to %s.", ReturnName(playerid, 0), id, FormatNumber(price));
	}
	else if (!strcmp(type, "name", true))
	{
	    new name[32];

	    if (sscanf(string, "s[32]", name))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [name] [new name]");

	    format(BillBoardData[id][bbName], 32, name);

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the name of billboard ID: %d to \"%s\".", ReturnName(playerid, 0), id, name);
	}
	else if (!strcmp(type, "message", true))
	{
	    new name[32];

	    if (sscanf(string, "s[230]", name))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [message] [new message] (Max Chars: 230)");

	    format(BillBoardData[id][bbMessage], 32, name);

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the message of billboard ID: %d to \"%s\".", ReturnName(playerid, 0), id, name);
	}
	else if (!strcmp(type, "owner", true))
	{
	    new giveplayerid;

	    if (sscanf(string, "d", giveplayerid))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [(remove)owner] [playerid]");

        if (giveplayerid == INVALID_PLAYER_ID)
	    	return SendErrorMessage(playerid, "That player is disconnected.");
		BillBoardData[id][bbOwner] = GetPlayerSQLID(giveplayerid);

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the owner of billboard ID: %d", ReturnName(playerid, 0), id);
	}
	else if (!strcmp(type, "removeowner", true))
	{
	    if (sscanf(string, "d"))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [removeowner]");

		BillBoardData[id][bbOwner] = 0;

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has removed the owner of billboard ID: %d", ReturnName(playerid, 0), id);
	}
	else if (!strcmp(type, "range", true))
	{
	    new range;

	    if (sscanf(string, "d", range))
	        return SendSyntaxMessage(playerid, "/editbillboard [id] [range] [new range]");

        if(range < 10)
		{
		    SendErrorMessage(playerid, "Range can only be 10-200");
		    return 1;
		}

		if(range > 200)
		{
		    SendErrorMessage(playerid, "Range can only be 10-200");
		    return 1;
		}

	    BillBoardData[id][bbRange] = range;

	    Billboard_Refresh(id);
	    Billboard_Save(id);

		SendAdminAlert(COLOR_LIGHTRED, "[ADMIN]: %s has adjusted the range of billboard ID: %d to %d.", ReturnName(playerid, 0), id, range);
	}
	return 1;
}
Reply
#2

What do you want -_- !!
Reply
#3

I'm not sure, but I think he wants to merge those 3 commands in 1 command so you get something like:
/billboard [create/delete/edit]
Reply
#4

He wants to unite all these commands one to what was entered after the command is checked and performs a command .
Reply
#5

You could do that by getting the first parameter with sscanf and then use strcmp to see what the player wants.

pawn Код:
CMD:billboard(playerid, params[])
{
    new commandtype[16];
    sscanf(params, "s[16]", commandtype)
    if(strcmp(commandtype, "create", true)==0)
    {
        //Put here your code to create a billboard
    }

    else if(strcmp(commandtype, "delete", true)==0)
    {
        //Put here your code to delete a billboard
    }

    else if(strcmp(commandtype, "edit", true)==0)
    {
        //Put here your code to edit a billboard
    }
    else
    {
        SendErrorMessage(playerid, "Use: /billboard [create/delete/edit]");
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by Schneider
Посмотреть сообщение
You could do that by getting the first parameter with sscanf and then use strcmp to see what the player wants.

pawn Код:
CMD:billboard(playerid, params[])
{
    new commandtype[16];
    sscanf(params, "s[16]", commandtype)
    if(strcmp(commandtype, "create", true)==0)
    {
        //Put here your code to create a billboard
    }

    else if(strcmp(commandtype, "delete", true)==0)
    {
        //Put here your code to delete a billboard
    }

    else if(strcmp(commandtype, "edit", true)==0)
    {
        //Put here your code to edit a billboard
    }
    else
    {
        SendErrorMessage(playerid, "Use: /billboard [create/delete/edit]");
    }
    return 1;
}
Theres only one problem with your example, you've provided one "Parameter" for the type, you should explain how to process more than one for things such as "Edit"
Reply
#7

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
Theres only one problem with your example, you've provided one "Parameter" for the type, you should explain how to process more than one for things such as "Edit"
do not already have a problem with him I do not know how to edit the work , too How should .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)