I have one little problem so pls help.
#1

I dont know how to make some command what will (for example) kill other player...
So pls can u tell me how can i make commands what will be made to other players.






TNX
Reply
#2

This is an example:

pawn Код:
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;
}
Reply
#3

You can always download a command
Reply
#4

Quote:
Originally Posted by еddy
This is an example:

pawn Код:
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;
}
K, tnx.
Reply
#5

D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(762) : error 017: undefined symbol "dcmd_kill"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(764) : error 017: undefined symbol "params"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(766) : error 017: undefined symbol "strtok"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(766) : error 033: array must be indexed (variable "params1")
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(767) : error 017: undefined symbol "params"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(77 : error 017: undefined symbol "playernamename"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(77 : error 029: invalid expression, assumed zero
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(77 : warning 215: expression has no effect
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(765) : warning 203: symbol is never used: "index"
D:\New Folder\GTA San Andreas\SAMP\SAMP SERVER\gamemodes\abcd.pwn(765 -- 790) : warning 225: unreachable code
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Reply
#6

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;
}
Compile that as a filterscript.
Reply
#7

K, is there any other way besides dcmd?
Reply
#8

pawn Код:
#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;
}
Reply
#9

Quote:
Originally Posted by Frankox
K, is there any other way besides dcmd?
You should use dcmd + sscanf it's the best, for example:

pawn Код:
// 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;
}
You can get sscanf here: https://sampwiki.blast.hk/wiki/Sscanf
Reply
#10

Tnx
Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)