SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/03/2018, 11:03 AM   #1
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 403
Reputation: 18
Default Getting the player kills?

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.
__________________
ivndosos is offline   Reply With Quote
Old 11/03/2018, 11:10 AM   #2
cessil
High-roller
 
cessil's Avatar
 
Join Date: Apr 2009
Posts: 1,346
Reputation: 296
Default Re: Getting the player kills?

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
cessil is offline   Reply With Quote
Old 11/03/2018, 11:10 AM   #3
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 872
Reputation: 291
Default Re: Getting the player kills?

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 http://forum.sa-mp.com/showthread.php?t=570927

and also at this code:
Code:
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
i suppose you are wanted to get "id" name instead of "playerid"
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 11/03/2018, 11:12 AM   #4
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 403
Reputation: 18
Default Re: Getting the player kills?

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.
__________________
ivndosos is offline   Reply With Quote
Old 11/03/2018, 11:29 AM   #5
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,193
Reputation: 420
Default Re: Getting the player kills?

What even is the use of sscanf if youre getting stats of the command issuer??
__________________
Quote:
Originally Posted by Andy
My anti cheat is still relevant *puts shades on* https://github.com/RogueDrifter/Anti_cheat_pack

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link

RogueDrifter is offline   Reply With Quote
Old 11/03/2018, 11:30 AM   #6
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 403
Reputation: 18
Default Re: Getting the player kills?

Ready carefully, I fixed it.
__________________
ivndosos is offline   Reply With Quote
Old 11/03/2018, 11:32 AM   #7
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,193
Reputation: 420
Default Re: Getting the player kills?

No you didnt, you dont even need to use sscanf here...
__________________
Quote:
Originally Posted by Andy
My anti cheat is still relevant *puts shades on* https://github.com/RogueDrifter/Anti_cheat_pack

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link

RogueDrifter is offline   Reply With Quote
Old 11/03/2018, 11:34 AM   #8
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 403
Reputation: 18
Default Re: Getting the player kills?

So does anyone knows why isn't it counting my k/d?
__________________
ivndosos is offline   Reply With Quote
Old 11/03/2018, 11:36 AM   #9
cessil
High-roller
 
cessil's Avatar
 
Join Date: Apr 2009
Posts: 1,346
Reputation: 296
Default Re: Getting the player kills?

yes, you're using sscanf wrong and using playerid instead of id
cessil is offline   Reply With Quote
Old 11/03/2018, 11:46 AM   #10
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,193
Reputation: 420
Default Re: Getting the player kills?

Remove sscanf and use the playerid provided by the cmd.
__________________
Quote:
Originally Posted by Andy
My anti cheat is still relevant *puts shades on* https://github.com/RogueDrifter/Anti_cheat_pack

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link

RogueDrifter is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Player With The Most Kills? Blackazur Scripting Help 4 04/03/2014 12:34 PM
A explosion kills a player, but player does not recieve credit. rangerxxll Scripting Help 6 09/03/2013 06:50 AM
How to kick a player if he kills a player? [EDT]AmanSingh123 Help Archive 15 23/08/2011 04:51 PM


All times are GMT. The time now is 09:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.