Actions Happen to other players
#1

How in the world do u make a command like

/kill id

and the actions happen to them..Not YOU..I only know how to make stuff that happen to me

Please give me a example of how i can type /kill id and it kills them..
Reply
#2

You use either SSCANF (good) or strtok (EUUGH)... for example:

Adapted from ban command on the wiki:
pawn Код:
dcmd_kick(playerid, params[])
{
    new
        id,
        reason[100];
    if (sscanf(params, "uz", id, reason)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick <playerid/partname> <reason (optional)>");
    else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        SetPlayerHealth(playerid, 0.0);
        format(reason, sizeof (reason), "You have been killed%s%s.", reason[0] ? (" for: ") : (""), reason);
        SendClientMessage(id, 0xFF0000AA, reason);
        SendClientMessage(playerid, 0x00FF00AA, "Player Killed");
    }
    return 1;
}
For this to work, you will need DCMD and SSCANF, both of which can be found here: CLICK

DCMD is the long "thing" #define, and SSCANF is the vary "tall" ~ 200 line stock.
Reply
#3

Hahaha! He said KILL, not KICK.

Usage:
[ADMIN]:
/kill [ID] - kills target [cannot be other admins]
/kill - kills self

[NON-ADMIN]:
/kill - kills self

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

new cmd[128];
new tmp[128];
new idx;

cmd = strtok(cmdtext, idx);

if(strcmp(cmd, "/kill", true) == 0)
{

	if(!IsPlayerAdmin(playerid))
	{
		SetPlayerHealth(playerid,0);
	}

	if(IsPlayerAdmin(playerid))
	{

		tmp = strtok(cmdtext, idx);

		if(!strlen(tmp))
		{
			SetPlayerHealth(playerid,0);
		} else {

		new id = strval(tmp);

		if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID)
		{
			SendClientMessage(playerid, RED, "Invalid player ID");
		}

		if(id != playerid)
		{

			if(IsPlayerAdmin(id))
			{
				SendClientMessage(playerid, RED, "You cannot /kill admins");
			} else {
				SetPlayerHealth(id,0);
			}
		}
	}
}

return 1;
}

}
Enjoy!
Reply
#4

Erm...<.>

this is how my commands look

Код:
if(!strcmp(cmdtext,"/website",true))
	{
  SendClientMessage(playerid,0xFFFFFFFF,"Our topic in on Sa Mp forum.sa-mp.com/index.php?topic=102824.0");
  return 1;
}
i dont get in the world what u are doing<.>
Reply
#5

Quote:
Originally Posted by Sal_Kings
How in the world do u make a command like

/kill id

and the actions happen to them..Not YOU..I only know how to make stuff that happen to me

Please give me a example of how i can type /kill id and it kills them..
Says here you wanted a command to kill other players...
What in the world does a website have to do with anything? xD
Reply
#6

Well as much as strtok i popular it's unreliable and IMO harder to use than SSCANF.

DCMD is a "better" way of handling commands than strcmp, but you can still use SSCANF with normal commands. I suggest you look at the Fast Commands section on the wiki for more information.

EDIT: Devil as much as I'm sure Sal_kings appreciates your help, I think they want to understand what is going on =/
Reply
#7

I've never ever ever had any problems with strtok.
Reply
#8

It has fewer functions, can be broken when using long messy strings (people do this maliciously to "break" servers, and it isn't as clear.
Reply
#9

errr devill...
Код:
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(136) : error 017: undefined symbol "strtok"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(136) : error 033: array must be indexed (variable "cmd")
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(135) : warning 203: symbol is never used: "idx"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(134) : warning 204: symbol is assigned a value that is never used: "tmp"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(783) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(783) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(784) : warning 217: loose indentation
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(790) : error 017: undefined symbol "strtok"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(790) : error 033: array must be indexed (variable "cmd")
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(803) : error 017: undefined symbol "strtok"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(803) : error 033: array must be indexed (variable "tmp")
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(814) : error 017: undefined symbol "RED"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(822) : error 017: undefined symbol "RED"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(830) : warning 217: loose indentation
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(788) : warning 203: symbol is never used: "idx"
C:\Documents and Settings\Salim\Desktop\SalsTestinGrounds\SalsTestingGrounds.pwn(788 -- 836) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


10 Errors.
Reply
#10

Sal, although it pains me to say this, add this to your script:

pawn Код:
stock 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


Forum Jump:


Users browsing this thread: 1 Guest(s)