public OnPlayerDeath(playerid, killerid, reason)
{
new string[128], killername[MAX_PLAYER_NAME];
GetPlayerName(lasthit[playerid], killername, MAX_PLAYER_NAME);
if(killstreak[playerid] >= 3)
{
format(string,sizeof(string), "~ %s has ended %s's killstreak", killername, GetName(playerid));
SendClientMessageToAll(COLOR_ORANGE, string);
SetPlayerColor(playerid, COLOR_WHITE);
}
killstreak[playerid] = 0;
HandleKS(killerid);
ResetPlayerWeapons(playerid);
GameTextForPlayer(playerid,"~r~~h~WASTED",8000,1);
if(PlayerInfo[killerid][pDonator] == 1)
{
GivePlayerCash(killerid, 200);
}
else {
GivePlayerCash(killerid, 100);
}
SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
GivePlayerCash(killerid, 100);
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
SaveAccountStats(playerid);
if(lasthit[playerid] == INVALID_PLAYER_ID)
{
SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
return 1;
}
if(lasthit[playerid] != INVALID_PLAYER_ID)
{
format(string, sizeof(string), "* %s[%d] has been killed by %s.", GetName(playerid),playerid, killername);
SendDeathMessage(lasthit[playerid],playerid,GetPlayerWeapon(lasthit[playerid]));
SendClientMessageToAll(COLOR_WHITE, string);
return 1;
}
lasthit[playerid] = INVALID_PLAYER_ID;
return 1;
}
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
if(damagedid != INVALID_PLAYER_ID)
{
new Float:armour; GetPlayerArmour(damagedid,armour);
if(armour < 1)
{
new Float:health; GetPlayerHealth(damagedid, health);
SetPlayerHealth(damagedid,health-amount);
lasthit[damagedid] = playerid;
return 1;
}
if(armour > 0)
{
if(armour < amount)
{
new Float:health; GetPlayerHealth(damagedid, health);
new Float:value = amount-armour;
SetPlayerArmour(damagedid,0);
SetPlayerHealth(damagedid,health-value);
lasthit[damagedid] = playerid;
return 1;
}
if(armour > amount)
{
SetPlayerArmour(damagedid,armour-amount);
lasthit[damagedid] = playerid;
return 1;
}
return 1;
}
return 1;
}
return 1;
}
if(lasthit[playerid] == INVALID_PLAYER_ID)
{
if(killerid != INVALID_PLAYER_ID)
{
It's the exact same thing, your last hit can not be accurate at all.
|
This is awfully wrong you see, why do this:
PHP код:
PHP код:
![]() It's the exact same thing, your last hit can not be accurate at all. Change those "lasthit" checks to killerid checks for validity. |
Sometimes my code sets the health to 0 resulting in the player suiciding but it also sets a variable that checks the player who has performed the last shot and so sends the death message with the last shot variable. I'm so confused. What should I do?
|
What's the other areas (Callbacks and functions), that you are using that lasthit array?
Where are you setting their health to 0 to make them die like that? |
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
if(damagedid != INVALID_PLAYER_ID)
{
new Float:armour; GetPlayerArmour(damagedid,armour);
if(armour < 1)
{
new Float:health; GetPlayerHealth(damagedid, health);
SetPlayerHealth(damagedid,health-amount);
lasthit[damagedid] = playerid;
return 1;
}
if(armour > 0)
{
if(armour < amount)
{
new Float:health; GetPlayerHealth(damagedid, health);
new Float:value = amount-armour;
SetPlayerArmour(damagedid,0);
SetPlayerHealth(damagedid,health-value);
lasthit[damagedid] = playerid;
return 1;
}
if(armour > amount)
{
SetPlayerArmour(damagedid,armour-amount);
lasthit[damagedid] = playerid;
return 1;
}
return 1;
}
return 1;
}
return 1;
}
You don't get it buddy, spare yourself the torture, replace all of the if(lasthit[ != invalid_player_id) with killerid like if(killerid != INVALID_PLAYER_ID)
this is never going to be accurate (because of the kill shot) and moreover WHY ARE U DOING IT IN THE FIRST PLACE you know? cuz the last hit is already caught by the system and stored in the killerid param in the OnPlayerDeath callback so why why why? |
this is never going to be accurate (because of the kill shot) and moreover WHY ARE U DOING IT IN THE FIRST PLACE you know? cuz the last hit is already caught by the system and stored in the killerid param in the OnPlayerDeath callback so why why why?
|
Are you sure?
If a player gets shot by a player, then jumps off something and dies, then killerid will be invalid, but lasthit won't... |