Getting the player kills?
#1

I'm making a simple gamemode just to test my abilities and stuff

I'm trying to make kills/deaths (without saving/storing them)


So what I've done is this:

PHP Code:
new gKills[MAX_PLAYERS];
new 
gDeaths[MAX_PLAYERS]; 
OnPlayerDeath
PHP Code:
    gKills[killerid] ++;
    
gDeaths[playerid] ++; 
and on stats command

PHP Code:
CMD:stats(playeridparams[])
{
   new
        
id,
        
PlayerName[MAX_PLAYER_NAME],
        
String[256];
        
   if(
sscanf(params"s[64]"id)) id playerid;
   
   
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
   
   
format(Stringsizeof(String), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d"PlayerNameplayeridgKills[id], gDeaths[id]);
   
   
SendClientMessage(playerid, -1String);
   
   return 
true;

It doesn't change on /stats command when I die.
Reply
#2

it's possible the code is cancelled before it reaches the part where it changes the variables, the rest seems fine.
post the whole OnPlayerDeath

Code:
GetPlayerName(id, PlayerName, sizeof(PlayerName)); 
    
   format(String, sizeof(String), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", PlayerName, id, gKills[id], gDeaths[id]);
I missed the playerid's you should change them to id
Reply
#3

the problem is on your stats command.

in this code:
Code:
if(sscanf(params, "s[64]", id)) id = playerid;
"s" specifier is for string while "id" variable is an integer. you can use "r" specifier for player, take a look at this thread for the list of sscanf specifier https://sampforum.blast.hk/showthread.php?tid=570927

and also at this code:
Code:
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
i suppose you are wanted to get "id" name instead of "playerid"
Reply
#4

Code:
public OnPlayerDeath(playerid, killerid, reason)
{

    SendDeathMessage(killerid, playerid, reason);

    gKills[killerid] ++;
    gDeaths[playerid] ++;

    return true;
}
edit: yeah my bad I haven't noticed I added playerid instead of id.
Reply
#5

What even is the use of sscanf if youre getting stats of the command issuer??
Reply
#6

Ready carefully, I fixed it.
Reply
#7

No you didnt, you dont even need to use sscanf here...
Reply
#8

So does anyone knows why isn't it counting my k/d?
Reply
#9

yes, you're using sscanf wrong and using playerid instead of id
Reply
#10

Remove sscanf and use the playerid provided by the cmd.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)