Quote:
Originally Posted by Randyy
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
new string[256];
SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
GivePlayerMoney(killerid, 200);
SendClientMessage(killerid, -1, "You received 200$ and 1 score.");
GivePlayerMoney(playerid, -100);
SendClientMessage(playerid, -1, "You lost 100$ because you got killed.");
format(string, sizeof(string), " %s Has killed a enemy!", PlayerName[playerid]);
SendClientMessageToAll(COLOR_RED, string);
return 1;
}
}
look's better ![Cheesy](images/smilies/biggrin.png)
|
It looks better but you just create a 256 characters long string, which is just NOT NEEDED.
Let's count your string:
Код:
%s Has killed a enemy!
It has exactly 22 CHARACTERS. Let's add the maximum player name to those 22. So 22 + 24 (MAX_PLAYER_NAME) = 46. So, a 46 long string is the maximum you'd need. You created a 256 characters string, which means 210 more characters than needed, which means a huge memory use which you don't need.
ps: iOmar, put a 'return 1' right before you close the bracket ( } ) in the OnPlayerDeath callback.
So:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
// BLA BLA CODE HERE
return 1;
}