dcmd - kick
#1

I'm a beginning scripter, and for all my commands I've always used strcmp. Many people told me to use
dcmd, they said it was a LOT more easy.
So with some help from samp wiki and other people, I have been trying to make a kick with dcmd...
Unfortunatly I keep receiving errors. Is there anyone who can help me with this please?

note: this code is scripted in OnPlayerCommandText(playerid, cmdtext[])
Код:
       {
		dcmd(kick, 4, cmdtext);
		return 0;
	}
	dcmd_kick(playerid, params[]) 
	{
		new id;
		if (sscanf(params, "d", id)) 
		{ 
			SendClientMessage(playerid, COLOR_BRIGHTRED, "/kick <id>");
		}
		else if (!IsPlayerConnected(id)) 
		{
			SendClientMessage(playerid, COLOR_BRIGHTRED, "This player does not exist.");
		}
		else 
		{
			Kick(id);
		}
		
	}
NOTE: THE DCMD DEFINE LINE IS ON TOP OF MY SCRIPT, BENEATH THE DEFININGS.
This is this define line, maybe the mistake is in there ...
Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
I also added this code at the END of my script:

Код:
// SSCANF [DCMD]
stock sscanf(string[], format[], {Float,_}:...) {
	new
		formatPos = 0,
		stringPos = 0,
		paramPos = 2,
		paramCount = numargs();
	while (paramPos < paramCount && string[stringPos]) {
		switch (format[formatPos++]) {
			case '\0': {
				return 0;
			}
			case 'i', 'd': {
				new
					neg = 1,
					num = 0,
					ch = string[stringPos];
				if (ch == '-') {
					neg = -1;
					ch = string[++stringPos];
				}
				do {
					stringPos++;
					if (ch >= '0' && ch <= '9')	{
						num = (num * 10) + (ch - '0');
					} else {
						return 1;
					}
				} while ((ch = string[stringPos]) && ch != ' ');
				setarg(paramPos, 0, num * neg);
			}
			case 'h', 'x': {
				new
					ch,
					num = 0;
				while ((ch = string[stringPos++])) {
					switch (ch) {
						case 'x', 'X': {
							num = 0;
							continue;
						}
						case '0' .. '9': {
							num = (num << 4) | (ch - '0');
						}
						case 'a' .. 'f': {
							num = (num << 4) | (ch - ('a' - 10));
						}
						case 'A' .. 'F': {
							num = (num << 4) | (ch - ('A' - 10));
						}
						case ' ': {
							break;
						}
						default: {
							return 1;
						}
					}
				}
				setarg(paramPos, 0, num);
			}
			case 'c': {
				setarg(paramPos, 0, string[stringPos++]);
			}
			case 'f': {
				new tmp[25];
				strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
				setarg(paramPos, 0, _:floatstr(tmp));
			}
			case 's', 'z': {
				new
					i = 0,
					ch;
				if (format[formatPos]) {
					while ((ch = string[stringPos++]) && ch != ' ') {
						setarg(paramPos, i++, ch);
					}
					if (!i) return 1;
				} else {
					while ((ch = string[stringPos++])) {
						setarg(paramPos, i++, ch);
					}
				}
				stringPos--;
				setarg(paramPos, i, '\0');
			}
			default: {
				continue;
			}
		}
		while (string[stringPos] && string[stringPos] != ' ') {
			stringPos++;
		}
		while (string[stringPos] == ' ') {
			stringPos++;
		}
		paramPos++;
	}
	while (format[formatPos] == 'z') formatPos++;
	return format[formatPos];
}
Next errors appear after compiling:

Quote:

:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\VDM.pwn(709) : error 017: undefined symbol "dcmd_kick"
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\VDM.pwn(712) : warning 225: unreachable code
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\VDM.pwn(712) : error 017: undefined symbol "dcmd_kick"
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\VDM.pwn(715) : error 017: undefined symbol "params"

...can anyone tell me what I did wrong please? i've been raging for hours on this
Reply
#2

Don't add your DCMD command like this:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(kick, 4, cmdtext);
return 0;
}
// Command
Add it like this:

pawn Код:
// Command

public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(kick, 4, cmdtext);
return 0;
}
Reply
#3

It doesn't matter, I have all of my commands under OnPlayerCommandText and have never had trouble with it.
As for the kick command: Don't use 'd' as operator, use 'u' (user).

pawn Код:
dcmd_kick(playerid, params[])
{
  if(!IsPlayerAdmin(playerid)) return 0;
  new targetid, reason[64], string[128];
  if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, RED, "Usage: /kick [playerid/partofname] [reason]");
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, "Player not connected!");
  format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
  SendClientMessage(targetid, string);
  Kick(targetid);
  return 1;
}
Reply
#4

I did what you both said, (I put the dcmd_kick ABOVE the OnPlayerCommandText) and the error ("undefined object "params"") did not appear anymore.

Although, I got this error:

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\VDM.pwn(401) : error 035: argument type mismatch (argument 2)
The error appears in the code of Vince:

Код:
dcmd_kick(playerid, params[])
{
	if(!IsPlayerAdmin(playerid)) return 0;
	new targetid, reason[64], string[128];
	if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Usage: /kick [playerid/partofname] [reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_BRIGHTRED, "Player not connected!");
	format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
	SendClientMessage(targetid, string);
	Kick(targetid);
	return 1;
}
Line 401 = SendClientMessage(targetid, string);

Edit: I just noticed it, the color wasn't added

SendClientMessage(targetid, RED, string);
Reply
#5

argument 2 is the color
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)