Commands with arguments
#1

Hello. Who uses the sampgdk library, tell me. How to work with commands and arguments? For example, /giveadmin [playerid] [levev]. How to lay cmdtext arguments? Or maybe someone has a mini () command processor?
I use this:
Код:
        char idx[16] = " ";
	char newcmdtext[32];
	strcpy(newcmdtext, cmdtext);
	char *cmd = strtok(newcmdtext, idx);
	if (strcmp(cmd, "/giveadmin") == 0) {
//		if(PlayerInfo[playerid].State < LOGGED_PLAYER || AdminInfo[playerid].AdminLevel < ADMIN_LEVEL_MAX) return 0;
		int id, level;
		if(sscanf(cmdtext, "%s%d%d", cmd, &id, &level) != 3) return PlayerInfo[playerid].SendMessage(0xFFFFFFAA, "ERROR!");
		PlayerInfo[playerid].SendMessage(0xFFFFFFAA, string_format("ID: %d LEVEL: %d", id, level).c_str());
		return true;
	}
But it is a bad option. Because if there is too long a command or something, the server crashed.
Reply


Messages In This Thread
Commands with arguments - by devStyle - 02.07.2016, 20:21
Re: Commands with arguments - by CodeStyle175 - 02.07.2016, 22:05
Re: Commands with arguments - by devStyle - 02.07.2016, 22:16
Re: Commands with arguments - by NewbProgrammer - 03.07.2016, 03:52
Re: Commands with arguments - by devStyle - 03.07.2016, 06:36
Re: Commands with arguments - by iggy1 - 03.07.2016, 11:18

Forum Jump:


Users browsing this thread: 1 Guest(s)