commands with id...
#4

So first that won't work at all, it'd crash your server due to :


pawn Код:
SendClientMessage(otherplayerid,COLOUR_GREEN,"The Admin %d killed you!");
2th. Get Sscanf, and "ZCMD" includes. Or use strcmp.

//P.S @ Hayden, you didn't explain everything in your tut.

Код:
//Put this under "OnPlayerCommandText
if(strcmp(cmd, "/freeze", true) == 0) // Freezes the player. Prevents him from moving
	{
		new reason[128];
		
		
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, ORANGE, "USAGE: /freeze [playername/id] [reason]");
				SendClientMessage(playerid, ORANGE, "FUNCTION: Will freeze the specified player.");
				return 1;
			}

			new giveplayerid = ReturnUser(tmp);
			if(giveplayerid != INVALID_PLAYER_ID)
			{
			    GetPlayerName(giveplayerid, giveplayername, sizeof(giveplayername));
				GetPlayerName(playerid, sendername, sizeof(sendername));
				reason = bigstrtok(cmdtext, idx);
				if(!strlen(reason)) return SendClientMessage(playerid, ORANGE, "USAGE: /freeze [playername/id] [reason]");
				format(string, sizeof(string), " Administrator %s froze %s. [Reason: %s ] ", sendername, giveplayername, reason);
	   			SendClientMessageToAll(red, string);
				TogglePlayerControllable(giveplayerid, false);
			}
			else if(giveplayerid == INVALID_PLAYER_ID)
			{
				format(string, sizeof(string), "%d is not an active player.", giveplayerid);
				SendClientMessage(playerid, RED, string);
			}
			return 1;
	}
Put this whats below here down your script, outside any Callback.

Код:
stock strtok(const string[], &idx)
{
    new length = strlen(string);
	while ((idx < length) && (string[idx] <= ' '))
	{
		idx++;
	}
	new offset = idx;
	new result[128];
	while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
	{
		result[idx - offset] = string[idx];
		idx++;
	}
	result[idx - offset] = EOS;
	return result;
}
With this the same, put it under / above stock strtok.

Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
	new pos = 0;
	while (text[pos] < 0x21)
	{
		if (text[pos] == 0) return INVALID_PLAYER_ID;
		pos++;
	}
	new userid = INVALID_PLAYER_ID;
	if (IsNumeric(text[pos]))
	{
		userid = strval(text[pos]);
		if (userid >=0 && userid < MAX_PLAYERS)
		{
			if(!IsPlayerConnected(userid))
				userid = INVALID_PLAYER_ID;
			else return userid;
		}
	}
	new len = strlen(text[pos]);
	new count = 0;
	new pname[MAX_PLAYER_NAME];
	for (new i = 0; i < MAX_PLAYERS; i++)
	{
		if (IsPlayerConnected(i))
		{
			GetPlayerName(i, pname, sizeof (pname));
			if (strcmp(pname, text[pos], true, len) == 0)
			{
				if (len == strlen(pname)) return i;
				else
				{
					count++;
					userid = i;
				}
			}
		}
	}
	if (count != 1)
	{
		if (playerid != INVALID_PLAYER_ID)
		{
			if (count) SendClientMessage(playerid, YELLOW, "There are multiple users, enter full playername.");
			else SendClientMessage(playerid, RED, "Playername not found.");
		}
		userid = INVALID_PLAYER_ID;
	}
	return userid;
}
And the unfreeze command:

Код:
if(strcmp(cmd, "/unfreeze", true) == 0) // Unfreezes the player
	{
		 // if IsPlayerAdmin(playerid))  
	                  //{
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, ORANGE, "USAGE: /unfreeze [playername/id]");
				SendClientMessage(playerid, ORANGE, "FUNCTION: Will unfreeze the specified player.");
				return 1;
			}

			new giveplayerid = ReturnUser(tmp);
			if(giveplayerid != INVALID_PLAYER_ID)
			{
			    GetPlayerName(giveplayerid, giveplayername, sizeof(giveplayername));
				GetPlayerName(playerid, sendername, sizeof(sendername));
				format(string, sizeof(string), " Administrator %s has unfrozen %s ", sendername,giveplayername);
				MessageToAdmins(blue, string);
				TogglePlayerControllable(giveplayerid, true);
			}
			else if(giveplayerid == INVALID_PLAYER_ID)
			{
				format(string, sizeof(string), "%d is not an active player.", giveplayerid);
				SendClientMessage(playerid, RED, string);
			}
				return 1;
	}
//Credits to Seif for that cmds.
Reply


Messages In This Thread
commands with id... - by omer5198 - 13.01.2011, 12:06
Re: commands with id... - by Haydz - 13.01.2011, 12:08
Re: commands with id... - by omer5198 - 13.01.2011, 12:22
Re: commands with id... - by [SU]Balli - 13.01.2011, 12:43
Re: commands with id... - by omer5198 - 13.01.2011, 12:54
Re: commands with id... - by Toreno - 13.01.2011, 13:11
Re: commands with id... - by [SU]Balli - 13.01.2011, 13:52
Re: commands with id... - by omer5198 - 13.01.2011, 15:38
Re: commands with id... - by alpha500delta - 13.01.2011, 15:50
Re: commands with id... - by [SU]Balli - 13.01.2011, 16:13

Forum Jump:


Users browsing this thread: 5 Guest(s)