error with my admin script -.-
#1

hey,


I have an error because id 0 counts for every ID on the server,
Reply
#2

Cool story bro

We cant do anything without a code. Drop one command here, so we can check what youre doing wrong.
Are you using 0.3C/D? If im right sscanf doesnt work (YET) with 0.3D, so that can be the problem
Reply
#3

ahh kk sorry and its 0.3c hes one of the commands:

pawn Код:
CMD:kick(playerid, params[])
{
    new
        pID,
        reason[70]
    ;
    if(gPlayerData[playerid][E_ADMIN_LEVEL] < 2) return 0;
    else if(sscanf(params, "uS(No reason)[70]", pID, reason)) SendUsage(playerid, "/kick [PLAYER_ID] [REASON]");
    else if(!IsPlayerConnected(pID)) SendError(playerid, "This player is not connected!");
    else if(pID == playerid) SendError(playerid, "You cannot kick yourself.");
    else if(IsHigherAdminLevel(pID, playerid)) SendError(playerid, "This player has a greater admin level then yours!");
    else
    {
        SendClientMessageFormattedToAll(COLOR_YELLOW, ""COL_GREY"[SERVER]{FFFFFF} %s(%d) has been kicked from the server by %s(%d) [Reason: %s]", ReturnPlayerName(pID), pID, ReturnPlayerName(playerid), playerid, reason);
        Kick(pID);
    }
    return 1;
}
it does the same for every command that i tested but not with explode how ever i went to id 64 and it still was exploding me thanks in advance
Reply
#4

i recommend you use dcmd
thats way easier

INCLUDE DCMD.inc
Код:
#if defined _dcmd_included
	#endinput
#endif
#define _dcmd_included

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
//dcmd(WasSollGesuchtWerden, Lдnge(von 0), vonwo);

//sscanf(vonwo, "datentypkьrzel (z.b. "D")", wohin 1, ... wohin n);
//liefert false wenns was gab, wenn nicht dann true (if (sscanf(xy, "d", dahin)) wenns kein d gab oder d eigl ein s war :D dann gehts net


//SSCANF!!!!
stock sscanf(string[], format[], {Float,_}:...)
{
	#if defined isnull
		if (isnull(string))
	#else
		if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
	#endif
		{
			return format[0];
		}
	#pragma tabsize 4
	new
		formatPos = 0,
		stringPos = 0,
		paramPos = 2,
		paramCount = numargs(),
		delim = ' ';
	while (string[stringPos] && string[stringPos] <= ' ')
	{
		stringPos++;
	}
	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 ('0' <= ch <= '9')
					{
						num = (num * 10) + (ch - '0');
					}
					else
					{
						return -1;
					}
				}
				while ((ch = string[stringPos]) > ' ' && ch != delim);
				setarg(paramPos, 0, num * neg);
			}
			case 'h', 'x':
			{
				new
					num = 0,
					ch = string[stringPos];
				do
				{
					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));
						}
						default:
						{
							return -1;
						}
					}
				}
				while ((ch = string[stringPos]) > ' ' && ch != delim);
				setarg(paramPos, 0, num);
			}
			case 'c':
			{
				setarg(paramPos, 0, string[stringPos++]);
			}
			case 'f':
			{

				new changestr[16], changepos = 0, strpos = stringPos;
				while(changepos < 16 && string[strpos] && string[strpos] != delim)
				{
					changestr[changepos++] = string[strpos++];
    				}
				changestr[changepos] = '\0';
				setarg(paramPos,0,_:floatstr(changestr));
			}
			case 'p':
			{
				delim = format[formatPos++];
				continue;
			}
			case '\'':
			{
				new
					end = formatPos - 1,
					ch;
				while ((ch = format[++end]) && ch != '\'') {}
				if (!ch)
				{
					return -1;
				}
				format[end] = '\0';
				if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
				{
					if (format[end + 1])
					{
						return -1;
					}
					return 0;
				}
				format[end] = '\'';
				stringPos = ch + (end - formatPos);
				formatPos = end + 1;
			}
			case 'u':
			{
				new
					end = stringPos - 1,
					id = 0,
					bool:num = true,
					ch;
				while ((ch = string[++end]) && ch != delim)
				{
					if (num)
					{
						if ('0' <= ch <= '9')
						{
							id = (id * 10) + (ch - '0');
						}
						else
						{
							num = false;
						}
					}
				}
				if (num && IsPlayerConnected(id))
				{
					setarg(paramPos, 0, id);
				}
				else
				{
					#if !defined foreach
						#define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
						#define __SSCANF_FOREACH__
					#endif
					string[end] = '\0';
					num = false;
					new
						name[MAX_PLAYER_NAME];
					id = end - stringPos;
					foreach (Player, playerid)
					{
						GetPlayerName(playerid, name, sizeof (name));
						if (!strcmp(name, string[stringPos], true, id))
						{
							setarg(paramPos, 0, playerid);
							num = true;
							break;
						}
					}
					if (!num)
					{
						setarg(paramPos, 0, INVALID_PLAYER_ID);
					}
					string[end] = ch;
					#if defined __SSCANF_FOREACH__
						#undef foreach
						#undef __SSCANF_FOREACH__
					#endif
				}
				stringPos = end;
			}
			case 's', 'z':
			{
				new
					i = 0,
					ch;
				if (format[formatPos])
				{
					while ((ch = string[stringPos++]) && ch != delim)
					{
						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] != delim && string[stringPos] > ' ')
		{
			stringPos++;
		}
		while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
		{
			stringPos++;
		}
		paramPos++;
	}
	do
	{
		if ((delim = format[formatPos++]) > ' ')
		{
			if (delim == '\'')
			{
				while ((delim = format[formatPos++]) && delim != '\'') {}
			}
			else if (delim != 'z')
			{
				return delim;
			}
		}
	}
	while (delim > ' ');
	return 0;
}
in your scriptfile:
example: kick

Код:
[...] //global
#include "../include/dcmd.inc"

[...] //global
forward dcmd_kick (playerid, params[]);
//dcmd_command-name (playerid, params[])
//playerid is the id of the player typing that command
//params is everything after the command (e.g. /kick abc def) "abc def" would be params then

[...] //in your onplayercommand callback

    dcmd(kick, 4, cmdtext); //dcmd(text-to-serch-for, lenght of text to serch for, cmdtext);
[...] //global

dcmd_kick (playerid /*id of command typer*/, params[])
{
	new id, reason[MAX_STRING], string[MAX_STRING]; //max_string not defined
	new player_name[MAX_PLAYERNAME], kicked_name[MAX_PLAYERNAME];
	
	format(reason, MAX_STRING, "(-/-)"); //predefine reason
	if (IsPlayerAdmin(playerid))
	{
		if( sscanf(params, "ds", id, reason) ) //split params in a D-part (integer) and a S-part (string), save it into the variables provided and returns 0 if successfull, 1 if it failed
		{
		    if ( sscanf(params, "d", id) )
		    {
		        SendClientMessage(playerid, ERROR_COLOR, "USAGE: /kick [playerid] [reason]");
				SendClientMessage(playerid, ERROR_COLOR, "OR: /kick [playerid]");
		    }
			else
			{
			    if (!IsPlayerConnected(id))
		 	    {
		 	        SendClientMessage(playerid, ERROR_COLOR, "Player not found!");
		 	    }
		 	    else
		 	    {
		 	        GetPlayerName(playerid, player_name, 20);
		 	        GetPlayerName(id, kicked_name, 20);
		 	        format(string, sizeof(string), "Player %s (ID %d) was kicked by admin %s (ID %d)! (Reason: -/-)", kicked_name, id, player_name, playerid, reason);
		 	        SendClientMessageToAll(ERROR_COLOR, string);
		 	        Kick(id);
		 	    }
			}
	 	}
	 	else
	 	{
	 	    if (!IsPlayerConnected(id))
	 	    {
	 	        SendClientMessage(playerid, ERROR_COLOR, "Player not found!");
	 	    }
	 	    else
	 	    {
	 	        GetPlayerName(playerid, player_name, 20);
	 	        GetPlayerName(id, kicked_name, 20);
	 	        format(string, sizeof(string), "Player %s (ID %d) was kicked by admin %s (ID %d)! (Reason: %s)", kicked_name, id, player_name, playerid, reason);
	 	        SendClientMessageToAll(ERROR_COLOR, string);
	 	        Kick(id);
	 	    }
	 	}
 	}
 	else
 	    SendClientMessage(playerid, ERROR_COLOR, "You are not admin!");
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)