SA-MP Forums Archive
Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem (/showthread.php?tid=89195)



Problem - tturvas - 31.07.2009

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"


Re: Problem - Correlli - 31.07.2009

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


Re: Problem - tturvas - 31.07.2009

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


Re: Problem - MadeMan - 31.07.2009

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
}



Re: Problem - tturvas - 31.07.2009

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?


Re: Problem - MadeMan - 31.07.2009

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


Re: Problem - tturvas - 31.07.2009

can you plz add it to my code.

I am so noob


Re: Problem - Correlli - 31.07.2009

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