SA-MP Forums Archive
Getting the player kills? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting the player kills? (/showthread.php?tid=650994)



Getting the player kills? - ivndosos - 11.03.2018

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.


Re: Getting the player kills? - cessil - 11.03.2018

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


Re: Getting the player kills? - X337 - 11.03.2018

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"


Re: Getting the player kills? - ivndosos - 11.03.2018

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.


Re: Getting the player kills? - RogueDrifter - 11.03.2018

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


Re: Getting the player kills? - ivndosos - 11.03.2018

Ready carefully, I fixed it.


Re: Getting the player kills? - RogueDrifter - 11.03.2018

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


Re: Getting the player kills? - ivndosos - 11.03.2018

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


Re: Getting the player kills? - cessil - 11.03.2018

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


Re: Getting the player kills? - RogueDrifter - 11.03.2018

Remove sscanf and use the playerid provided by the cmd.