Strange issue: SetPlayerScore(playerid);
#1

Okey i have this strange issue with this function, i show my code:

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        SendDeathMessage(killerid, playerid, reason);
	SetPlayerScore(playerid,GetPlayerScore(playerid)-1);
	if(killerid != INVALID_PLAYER_ID){SetPlayerScore(killerid,GetPlayerScore(killerid)+1);}
        return 1;
}
but when i try to test it and i suicide myself with a granade ( for example ) when the player dies the score still the same, why?
Reply
#2

Try this.

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        new newscore = GetPlayerScore(playerid) --;
        SendDeathMessage(killerid, playerid, reason);
	SetPlayerScore(playerid, newscore);
	if(killerid != INVALID_PLAYER_ID){SetPlayerScore(killerid,GetPlayerScore(killerid)+1);}
        return 1;
}
Reply
#3

Quote:
Originally Posted by jihadmeneer
Код:
GetPlayerScore(playerid) --;
That's not even valid code.

OP, problem might be that when you kill yourself - killerid will probably be INVALID_PLAYER_ID (as far as i can remember). So if you want to test it properly, just call OnPlayerDeath with your ID.

Код:
//Inside some command
OnPlayerDeath(NOT_PLAYERID, playerid, 0);
This is assuming it's the killer score that isn't changing. Your code should work btw.

EDIT: Also if it doesn't send INVALID_KILLER_ID, but instead your ID - you will just be decresing the score (playerid: your id) then increasing it (killerid: also your id) so it will have no effect.
Reply
#4

Quote:
Originally Posted by iggy1
Посмотреть сообщение
That's not even valid code.

OP, problem might be that when you kill yourself - killerid will probably be INVALID_PLAYER_ID (as far as i can remember). So if you want to test it properly, just call OnPlayerDeath with your ID.

Код:
//Inside some command
OnPlayerDeath(NOT_PLAYERID, playerid, 0);
This is assuming it's the killer score that isn't changing. Your code should work btw.

EDIT: Also if it doesn't send INVALID_KILLER_ID, but instead your ID - you will just be decresing the score (playerid: your id) then increasing it (killerid: also your id) so it will have no effect.
Thanks, solved.
Reply


Forum Jump:


Users browsing this thread: