13.01.2011, 16:13
PHP код:
#include <a_samp>
#define FILTERSCRIPT
#if defined FILTERSCRIPT
#define COLOUR_GREEN 0x33AA33AA
#define COLOUR_RED 0xAA3333AA
#define COLOUR_YELLOW 0xFFFF00AA
#define COLOUR_LIGHTBLUE 0x33CCFFAA
#define COLOUR_ORANGE 0xFF9900AA
public OnFilterScriptInit()
{
print("\n****************************************");
print("* AdminCmds *");
print("****************************************\n");
return 1;
}
#endif
public OnPlayerCommandText(playerid, cmdtext[])
{
new giveplayername[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME], giveplayerid, tmp[256], cmd[256], idx;
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, COLOUR_ORANGE, "USAGE: /freeze [playername/id] [reason]");
SendClientMessage(playerid, COLOUR_ORANGE, "FUNCTION: Will freeze the specified player.");
return 1;
}
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, COLOUR_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, COLOUR_RED, string);
}
return 1;
}
return 0;
}
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;
}
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;
}