dcmd_kill(playerid, params[])
{
new player2 = strval(params);
new params1[256], index;
params1 = strtok(params, index);
if(!strlen(params))
{
SendClientMessage(playerid,COLOR_RED,"Usage: /kill [playerid]");
return 1;
}
if(!IsPlayerConnected(player2))
{
SendClientMessage(playerid,0xFFFFFFAA,"Error: Player is not connected");
return 1;
}
new playername[MAX_PLAYER_NAME], playername2[MAX_PLAYER_NAME], string[256];
GetPlayerName(player2, playername, sizeof(playernamename));
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string, sizeof(string), "%s has killed %s", playername2, playername);
SendClientMessageToAll(0xFF000AA, string);
SetPlayerHealth(player2, 0);
return 1;
}
Originally Posted by еddy
This is an example:
pawn Код:
|
#include a_samp
#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
dcmd_kill(playerid,params[])
{
new player2 = strval(params);
new params1[256], index;
params1 = strtok(params, index);
if(!strlen(params))
{
SendClientMessage(playerid,0xFF0000AA,"Usage: /kill [playerid]");
return 1;
}
if(!IsPlayerConnected(player2))
{
SendClientMessage(playerid,0xFFFFFFAA,"Error: Player is not connected");
return 1;
}
new playername[MAX_PLAYER_NAME], playername2[MAX_PLAYER_NAME], string[256];
GetPlayerName(player2, playername, sizeof(playername));
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string, sizeof(string), "%s has killed %s", playername2, playername);
SendClientMessageToAll(0xFF000AA, string);
SetPlayerHealth(player2, 0);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(kill,4,cmdtext);
return 0;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
#include a_samp
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/kill", true, 5))
{
new player2 = strval(cmdtext);
new cmdtext1[256], index;
cmdtext1 = strtok(cmdtext, index);
if(!strlen(cmdtext))
{
SendClientMessage(playerid,0xFF0000AA,"Usage: /kill [playerid]");
return 1;
}
if(!IsPlayerConnected(player2))
{
SendClientMessage(playerid,0xFFFFFFAA,"Error: Player is not connected");
return 1;
}
new playername[MAX_PLAYER_NAME], playername2[MAX_PLAYER_NAME], string[256];
GetPlayerName(player2, playername, sizeof(playername));
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string, sizeof(string), "%s has killed %s", playername2, playername);
SendClientMessageToAll(0xFF000AA, string);
SetPlayerHealth(player2, 0);
return 1;
}
return 0;
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
Originally Posted by Frankox
K, is there any other way besides dcmd?
|
// On top:
#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
// OnPlayerCommandText:
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(adminkill,9,cmdtext);
return 0;
}
dcmd_adminkill(playerid, params[])
{
new otherid = strval(params);
if(IsPlayerAdmin(playerid))
{
if (sscanf(params, "d", otherid))
return SendClientMessage(playerid, 0xFFFFFF, "/adminkill playerid");
if(!IsPlayerConnected(otherid))
return SendClientMessage(playerid, 0xFFFFFF, "That player is not connected!");
SetPlayerHealth(otherid, 0);
}
return 1;
}