#1

all code in onplayerdeath not works.who can help me?

Код:
public OnPlayerDeath(playerid,killerid,reason){
	new dname[MAX_PLAYER_NAME],kname[MAX_PLAYER_NAME],str[128];
	SendDeathMessage(killerid,playerid,reason);
	GetPlayerName(playerid,dname,MAX_PLAYER_NAME);
	GetPlayerName(killerid,kname,MAX_PLAYER_NAME);
    GetPlayerPos(playerid,Bodyx[playerid],Bodyy[playerid],Bodyz[playerid]);
    SetTimerEx("RemoveBodyPos",4000,false,"i",playerid);
    hshield[playerid]=false;
	lshield[playerid]=false;
	SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
	PlayerInfo[killerid][pScore]++;
	PlayerInfo[killerid][pKill]++;
	PlayerInfo[killerid][pKillSpree]++;
	PlayerInfo[killerid][pRatio]=PlayerInfo[killerid][pKill]/PlayerInfo[killerid][pDeath];
	format(str,sizeof(str),"~g~Kills:~w~%d-~r~Deaths:~w~%d",PlayerInfo[killerid][pKill],PlayerInfo[killerid][pDeath]);
	TextDrawSetString(info2[playerid],str);
	SetPlayerScore(playerid,GetPlayerScore(playerid)+1);
	PlayerInfo[playerid][pScore]++;
	PlayerInfo[playerid][pDeath]++;
	PlayerInfo[playerid][pRatio]=PlayerInfo[playerid][pKill]/PlayerInfo[playerid][pDeath];
	format(str,sizeof(str),"You have been killed by %s(%d).",kname,killerid);
	SendClientMessage(playerid,COLOR_RED,str);
	SendClientMessage(playerid,COLOR_RED,"You lost 1000$ for dying.");
	GivePlayerMoney(playerid,-1000);
	PlayerInfo[playerid][pMoney]-=1000;
	format(str,sizeof(str),"~g~Kills:~w~%d-~r~Deaths:~w~%d",PlayerInfo[playerid][pKill],PlayerInfo[playerid][pDeath]);
	TextDrawSetString(info2[playerid],str);
	SendSpreeMassage(playerid,kname);
	format(str,sizeof(str),"%s(%d) has ended %s(%d)'s kill spree of %i",kname,killerid,dname,playerid,PlayerInfo[playerid][pKillSpree]);
	if(PlayerInfo[playerid][pKillSpree]>0)SendClientMessageToAll(COLOR_ORANGE,str);
	PlayerInfo[playerid][pKillSpree]=0;
	new kurl[120];
		switch(random(8)){
		    case 0: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-beautiful-01.mp3";
		    case 1: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-sloppy-01.mp3";
		    case 2: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-goodnight-01.mp3";
		    case 3: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-hesdown-01.mp3";
		    case 4: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-neutralized-01.mp3";
		    case 5: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-noisy-01.mp3";
		    case 6: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-perfect-01.mp3";
		    case 7: kurl="http://vip.opload.ir/vipdl/94/11/arefkhan/so-hid-ghil-tango-down-01.mp3";}
		PlayAudioStreamForPlayer(killerid,kurl,0.0,0.0,0.0,0.0,0);
    new durl[120];
		switch(random(2)){
		    case 0: durl="http://vip.opload.ir/vipdl/94/11/arefkhan/deadms1.mp3";
		    case 1: durl="http://vip.opload.ir/vipdl/94/11/arefkhan/deadms2.mp3";}
		PlayAudioStreamForPlayer(playerid,durl,0.0,0.0,0.0,0.0,0);
    if(IsBeingSpeced[playerid]==true){
	    foreach(Player,i){
	    	if(Spectatorid[i]==playerid){
				TogglePlayerSpectating(i,false);}}}
	return 1;}
Reply
#2

  1. Add whitespace.
  2. Never use killerid as an array index before having verified that it is actually a valid player.
  3. "all of code" and "not works" is hardly descriptive.
Reply
#3

I tried all ways but not work.
Reply
#4

And what're those ways? Coming up with a description of "what have you tried" & "what exactly doesn't work" would motivate people right out here to help you. "Errors/Warning/Anything similar" you came across? Yelling "doesn't work" after posting a poorly-indented code just demoralize others to look into the code.
Reply
#5

I must say,
That is the messiest code I have ever seen.
Clean it up, and you might find the issue.
Reply
#6

It is a strange problem.i change it but samp-server close when i kill player.
Reply
#7

Quote:
Originally Posted by GeneralAref
Посмотреть сообщение
It is a strange problem.i change it but samp-server close when i kill player.
This means your code f*cks it up at some point.
As Vince said before, never use killerid if you didn't check if killerid == INVALID_PLAYER_ID before.
Best way to find out what is killing it, you can comment all your code out and then uncomment line by line until you'll find the line that causes the crash.
This is way that requires most work on fixing that.

What could speed it up is: Clean up your code and write a proper description of the issue. Then someone here could easily tell you the problem. This way though noone will bother to read that mess of a code.
Reply
#8

problem in this line
SetPlayerScore(killerid,GetPlayerScore(killerid)+1 );
i forgot = and thanks for your help.
Reply
#9

Get crashdetect plugin.
Reply
#10

This will fix all your problems.

pawn Код:
public OnPlayerDeath(playerid,killerid,reason)
{
if(IsPlayerConnected(killerid) && reason < 46)
{
//Your code here

}
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)