Player Scores Bug
#1

When a player kills another player, their scores are not going up. Here's the OnPlayerDeath code.
http://pastebin.com/TcCmfS7j
Reply
#2

Hey,Look at the example the wiki provided and try to figure it out. https://sampwiki.blast.hk/wiki/OnPlayerDeath
if you still don't understand feel free to reply back but try first.
Reply
#3

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
     
SendDeathMessage(killeridplayeridreason);
     if(
duelinfo[killerid][induel] == 1)
     {
          
duelinfo[killerid][induel] = 0;
          new 
string[128];
          new 
Float:health GetPlayerHealth(killeridhealth);
          
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth);
          
SendClientMessageToAll(-1string);
          
SetPlayerScore(killeridGetPlayerScore(killerid) + 2);
          
GiveCoins(killerid2);
          
PlayerInfo[killerid][pDuelWins] +=1;
          
PlayerInfo[playerid][pDuelLoses] +=1;
     }
     
GiveCoins(killerid1);
     
PlayerInfo[killerid][pKills] += 1;
     
PlayerInfo[playerid][pDeaths] += 1;
     return 
1;

Just look into your code ^, it's pretty obvious, you are increasing the killer's score if they are in a duel only. Also, you should check if the killerid isn't invalid before using it in an array.
Reply
#4

Try this

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid == INVALID_PLAYER_ID) return 0;
    
SendDeathMessage(killeridplayeridreason); 
    if(
duelinfo[killerid][induel] == 1
    { 
        
duelinfo[killerid][induel] = 0
        new 
string[128]; 
        new 
Float:health GetPlayerHealth(killeridhealth); 
        
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth); 
        
SendClientMessageToAll(-1string); 
        
SetPlayerScore(killeridGetPlayerScore(killerid) + 2); 
        
GiveCoins(killerid2); 
        
PlayerInfo[killerid][pDuelWins] +=1
        
PlayerInfo[playerid][pDuelLoses] +=1;
    }
    else if(
duelinfo[killerid][induel] != 1
    {
        
GiveCoins(killerid1);
        
SetPlayerScore(killeridGetPlayerScore(killerid) + 1); 
        
PlayerInfo[killerid][pKills] += 1
        
PlayerInfo[playerid][pDeaths] += 1;
    }
    return 
1;

"You MUST check whether 'killerid' is valid (not INVALID_PLAYER_ID) before using it in an array (or really anywhere), as it will cause the OnPlayerDeath script to crash (not the entire script). This is because INVALID_PLAYER_ID is defined as 65535, and if an array only has 'MAX_PLAYERS' elements, e.g. 500, you're trying to access an index that is above 499, which is out of bounds." - Taken from Wiki
Reply
#5

Quote:
Originally Posted by Tass007
Посмотреть сообщение
Try this

PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
killerid == INVALID_PLAYER_ID) return 0;
    
SendDeathMessage(killeridplayeridreason); 
    if(
duelinfo[killerid][induel] == 1
    { 
        
duelinfo[killerid][induel] = 0
        new 
string[128]; 
        new 
Float:health GetPlayerHealth(killeridhealth); 
        
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth); 
        
SendClientMessageToAll(-1string); 
        
SetPlayerScore(killeridGetPlayerScore(killerid) + 2); 
        
GiveCoins(killerid2); 
        
PlayerInfo[killerid][pDuelWins] +=1
        
PlayerInfo[playerid][pDuelLoses] +=1;
    }
    else if(
duelinfo[killerid][induel] != 1
    {
        
GiveCoins(killerid1);
        
SetPlayerScore(killeridGetPlayerScore(killerid) + 1); 
        
PlayerInfo[killerid][pKills] += 1
        
PlayerInfo[playerid][pDeaths] += 1;
    }
    return 
1;

"You MUST check whether 'killerid' is valid (not INVALID_PLAYER_ID) before using it in an array (or really anywhere), as it will cause the OnPlayerDeath script to crash (not the entire script). This is because INVALID_PLAYER_ID is defined as 65535, and if an array only has 'MAX_PLAYERS' elements, e.g. 500, you're trying to access an index that is above 499, which is out of bounds." - Taken from Wiki
Quote:

"You MUST check whether 'killerid' is valid (not INVALID_PLAYER_ID) before using it in an array (or really anywhere), as it will cause the OnPlayerDeath script to crash

PHP код:
if(killerid == INVALID_PLAYER_ID) return 0
That's bad, there won't be any difference, since the rest of the code won't execute at all if the killerid is invalid.
Reply
#6

Quote:
Originally Posted by Jelly23
Посмотреть сообщение
PHP код:
if(killerid == INVALID_PLAYER_ID) return 0
That's bad, there won't be any difference, since the rest of the code won't execute at all if the killerid is invalid.
PHP код:
public OnPlayerDeath(playeridkilleridreason

    if(
killerid != INVALID_PLAYER_ID)
    {
        
SendDeathMessage(killeridplayeridreason);  
        if(
duelinfo[killerid][induel] == 1)  
        {  
            
duelinfo[killerid][induel] = 0;  
            new 
string[128];  
            new 
Float:health GetPlayerHealth(killeridhealth);  
            
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth);  
            
SendClientMessageToAll(-1string);  
            
SetPlayerScore(killeridGetPlayerScore(killerid) + 2);  
            
GiveCoins(killerid2);  
            
PlayerInfo[killerid][pDuelWins] +=1;  
            
PlayerInfo[playerid][pDuelLoses] +=1
        } 
        else if(
duelinfo[killerid][induel] != 1)  
        { 
            
GiveCoins(killerid1); 
            
SetPlayerScore(killeridGetPlayerScore(killerid) + 1);  
            
PlayerInfo[killerid][pKills] += 1;  
            
PlayerInfo[playerid][pDeaths] += 1
        } 
    }
    return 
1

Is that better?
Reply
#7

Quote:
Originally Posted by Tass007
Посмотреть сообщение
PHP код:
public OnPlayerDeath(playeridkilleridreason

    if(
killerid != INVALID_PLAYER_ID)
    {
        
SendDeathMessage(killeridplayeridreason);  
        if(
duelinfo[killerid][induel] == 1)  
        {  
            
duelinfo[killerid][induel] = 0;  
            new 
string[128];  
            new 
Float:health GetPlayerHealth(killeridhealth);  
            
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth);  
            
SendClientMessageToAll(-1string);  
            
SetPlayerScore(killeridGetPlayerScore(killerid) + 2);  
            
GiveCoins(killerid2);  
            
PlayerInfo[killerid][pDuelWins] +=1;  
            
PlayerInfo[playerid][pDuelLoses] +=1
        } 
        else if(
duelinfo[killerid][induel] != 1)  
        { 
            
GiveCoins(killerid1); 
            
SetPlayerScore(killeridGetPlayerScore(killerid) + 1);  
            
PlayerInfo[killerid][pKills] += 1;  
            
PlayerInfo[playerid][pDeaths] += 1
        } 
    }
    return 
1

Is that better?
Still, the kill list messages & playerid's deaths will only increase if the killerid is valid, pretty much the same.

Anything related to playerid shouldn't be under if(killerid != INVALID_PLAYER_ID) condition.
Reply
#8

Then how do you suggest to do it then?
Reply
#9

PHP код:
public OnPlayerDeath(playeridkilleridreason)  
{  
     
SendDeathMessage(killeridplayeridreason);   
     if(
killerid != INVALID_PLAYER_ID && duelinfo[killerid][induel] == 1)   
     {   
         
duelinfo[killerid][induel] = 0;   
         new 
string[128],Float:health GetPlayerHealth(killeridhealth);   
         
format(stringsizeof(string), ""RED"[DUEL] "WHITE"%s(%d) has defeated %s(%d) in a duel with %.2f health left"duelinfo[killerid][playername], killeridduelinfo[playerid][playername], playeridhealth);   
         
SendClientMessageToAll(-1string);   
         
SetPlayerScore(killeridGetPlayerScore(killerid) + 2);   
         
GiveCoins(killerid2);   
         
PlayerInfo[killerid][pDuelWins] +=1;   
         
PlayerInfo[playerid][pDuelLoses] +=1;  
     }  
     else
     {
         if(
killerid != INVALID_PLAYER_ID)
         {  
              
GiveCoins(killerid1);  
              
SetPlayerScore(killeridGetPlayerScore(killerid) + 1);   
              
PlayerInfo[killerid][pKills] += 1;   
         }
         
PlayerInfo[playerid][pDeaths] += 1;   
     } 
     return 
1;  

Reply
#10

I've tried both solutions and still isn't working. Thanks so much for the help either way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)