Problem
#1

Hi i made code that says when you kill someone "You have killed [NAME]" //right
And when somebody will kill you it will say "[Name] Has just killed you" //right

But when you type /kill (suicide). then it will say "[Yourname] has just killed you" //wrong
Lets say tturvas types /kill then it will say "tturvas has just killed you". //wrong

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	SendDeathMessage(killerid, playerid, reason);
	new string[256];
  	new playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playername,sizeof(playername));
	
  	//killer
	GetPlayerName(playerid, playername,sizeof(playername));
	format(string, sizeof(string), "You have killed %s", playername);
	SendClientMessage(killerid,0xAA3333AA,string);
	GivePlayerMoney(killerid,1000);
	SetPlayerScore(killerid,1);
	SetPlayerColor(killerid,red);
	
	
	//victim 
	GetPlayerName(killerid, playername,sizeof(playername));
	format(string, sizeof(string), "%s has just killed you", playername);
	SendClientMessage(playerid,0xAA3333AA,string);
	GivePlayerMoney(playerid,-1000);
	SetPlayerScore(playerid,-1);
	SetPlayerColor(playerid,ugly_yellow);
	
	return 1;
}
and the /kill command

Код:
	if (strcmp("/kill", cmdtext, true, 10) == 0)
	{
		SetPlayerHealth(playerid,0);
		return 1;
	}
Can somebody write code here so if player will type /kill than it will say "You have just killed yourself"
Reply
#2

At OnPlayerDeath, check if killerid is a valid player id.
Reply
#3

Quote:
Originally Posted by Don Correlli
At OnPlayerDeath, check if killerid is a valid player id.
Sorry i cant understand?, i am new on scripting
Reply
#4

If you kill yourself then killerid is INVALID_PLAYER_ID. You should check if killerid is not invalid.

pawn Код:
if (killerid != INVALID_PLAYER_ID)
{
//Add your code here
}
Reply
#5

Quote:
Originally Posted by MadeMan
If you kill yourself then killerid is INVALID_PLAYER_ID. You should check if killerid is not invalid.

pawn Код:
if (killerid != INVALID_PLAYER_ID)
{
//Add your code here
}
I should add this to OnPlayerCommandText or OnPlayerDeath?
Reply
#6

Quote:
Originally Posted by tturvas
I should add this to OnPlayerCommandText or OnPlayerDeath?
OnPlayerDeath.
Reply
#7

can you plz add it to my code.

I am so noob
Reply
#8

http://sa-mp.pastebin.com/f34bdb181
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)