PDA

View Full Version : Getting the player kills?


ivndosos
11/03/2018, 11:03 AM
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:


new gKills[MAX_PLAYERS];
new gDeaths[MAX_PLAYERS];


OnPlayerDeath

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


and on stats command


CMD:stats(playerid, params[])
{
new
id,
PlayerName[MAX_PLAYER_NAME],
String[256];

if(sscanf(params, "s[64]", id)) id = playerid;

GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

format(String, sizeof(String), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", PlayerName, playerid, gKills[id], gDeaths[id]);

SendClientMessage(playerid, -1, String);

return true;
}


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

cessil
11/03/2018, 11:10 AM
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

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

X337
11/03/2018, 11:10 AM
the problem is on your stats command.

in this 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:

GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

i suppose you are wanted to get "id" name instead of "playerid"

ivndosos
11/03/2018, 11:12 AM
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.

RogueDrifter
11/03/2018, 11:29 AM
What even is the use of sscanf if youre getting stats of the command issuer??

ivndosos
11/03/2018, 11:30 AM
Ready carefully, I fixed it.

RogueDrifter
11/03/2018, 11:32 AM
No you didnt, you dont even need to use sscanf here...

ivndosos
11/03/2018, 11:34 AM
So does anyone knows why isn't it counting my k/d?

cessil
11/03/2018, 11:36 AM
yes, you're using sscanf wrong and using playerid instead of id

RogueDrifter
11/03/2018, 11:46 AM
Remove sscanf and use the playerid provided by the cmd.

iKarim
11/03/2018, 12:19 PM
He obviously is using sscanf right (after he fixed it to integer instead of string), to understand the logic of the command above, read it again. The command problem is not sscanf, it's why he used "playerid" in the following functions, which shows stats of his account and only that, it should be "id" instead to show other players'.


Your problem is that you don't check that killerid is valid, thus your code crashes trying to access the array at 65535 index.


if (killerid != INVALID_PLAYER_ID) gKills[killerid]++;

RogueDrifter
11/03/2018, 12:20 PM
He obviously is using sscanf right (after he fixed it to integer instead of string), you are failing miserably to understand the logic of the command above, read it again.


Your problem is that you don't check that killerid is valid, thus your code crashes trying to access the array at 65535 index.


if (killerid != INVALID_PLAYER_ID) gKills[killerid]++;

How about you read that genius?
if(sscanf(params, "s[64]", id)) id = playerid;

GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

format(String, sizeof(String), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", PlayerName, playerid, gKills[id], gDeaths[id]);

iKarim
11/03/2018, 12:23 PM
How about you read that genius?


if(sscanf(params, "u", id)) id = playerid;


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

He does need sscanf, but his command is messed up, you could've suggested to fix it instead of asking to remove it. The sscanf example above is totally valid.

RogueDrifter
11/03/2018, 12:24 PM
if(sscanf(params, "u", id)) id = playerid;




He does need sscanf, but his command is messed up, you could've suggested to fix it instead of asking to remove it. The sscanf example above is totally valid.
He obviously was trying to make a self-stats check, hence there's no need for sscanf in the first place...

iKarim
11/03/2018, 12:25 PM
He obviously was trying to make a self-stats check, hence there's no need for sscanf in the first place...

And how did you come to this conclusion?

ivndosos
11/03/2018, 12:28 PM
I'm not trying to make a self-stats check, I was just typing fast and I haven't noticed.

Anyway my problem is that kills and deaths don't show on my stats.

RogueDrifter
11/03/2018, 12:29 PM
And how did you come to this conclusion?
Why not? he hasn't specified anything and the fact that the usage of sscanf was wrong seemed like he hasn't got an idea on using it.

Let alone this:
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));


And then using it like this:
format(String, sizeof(String), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", PlayerName, playerid, gKills[id], gDeaths[id]);
Any sane person would say that's a hundred percent self-stats check, same id as command issuer and name.

iKarim
11/03/2018, 12:33 PM
I'm not trying to make a self-stats check, I was just typing fast and I haven't noticed.

Anyway my problem is that kills and deaths don't show on my stats.

Try this:

new gKills[MAX_PLAYERS];
new gDeaths[MAX_PLAYERS];

OnPlayerDeath

if (killerid != INVALID_PLAYER_ID) {
gKills[killerid] ++;
}
gDeaths[playerid] ++;


CMD:stats(playerid, params[])
{
new
targetid,
playerName[MAX_PLAYER_NAME],
message[128];

if(sscanf(params, "u", targetid)) targetid = playerid;
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Offline player")

GetPlayerName(tlayerid, playerName, sizeof(playerName));

format(message, sizeof(message), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", playerName, targetid, gKills[targetid], gDeaths[targetid]);

SendClientMessage(playerid, -1, message);

return true;
}

Why not? he hasn't specified anything and the fact that the usage of sscanf was wrong seemed like he hasn't got an idea on using it.



edit: yeah my bad I haven't noticed I added playerid instead of id.

He apparently did, yet you just ignored it and "OMGGGGGG REMOVE SSCANF!!!!!!111111111"

RogueDrifter
11/03/2018, 12:36 PM
Try this:

new gKills[MAX_PLAYERS];
new gDeaths[MAX_PLAYERS];

OnPlayerDeath

if (killerid != INVALID_PLAYER_ID) {
gKills[killerid] ++;
}
gDeaths[playerid] ++;


CMD:stats(playerid, params[])
{
new
targetid,
playerName[MAX_PLAYER_NAME],
message[128];

if(sscanf(params, "u", targetid)) targetid = playerid;
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Offline player")

GetPlayerName(tlayerid, playerName, sizeof(playerName));

format(message, sizeof(message), "Player Name: %s | ID: %d | Kills: %d | Deaths: %d", playerName, targetid, gKills[targetid], gDeaths[targetid]);

SendClientMessage(playerid, -1, message);

return true;
}






He apparently did, yet you just ignored it and "OMGGGGGG REMOVE SSCANF!!!!!!111111111"
You're retarded aren't you? review my previous reply,

And i have to comment out this: String[256];

Get outta here with that stereotypical nonsense shit, that string isn't even a hundred characters.

iKarim
11/03/2018, 12:39 PM
You're retarded aren't you? review my previous reply,

And i have to comment out this:
Get outta here with that stereotypical nonsense shit, that string isn't even a hundred characters.

smh I just copied his code, it's not that I meant to do it, and my post was updated even before yours, thus your quote showing my update.

I see you are failing miserably, getting irrelevant shit into the argument to sound smarter, duh!

RogueDrifter
11/03/2018, 12:42 PM
smh I just copied his code, it's not that I meant to do it, and my post was updated even before yours, thus your quote showing my update.

I see you are failing miserably, getting irrelevant shit into the argument to sound smarter, duh!
Riiight, lmfao, i'm outta there this shit is beyond me i don't like dealing with that high level stupid fucks tbfh, good luck handing code over without an explanation to get reps you fuckwit lol.

if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Offline player")

The most stupid shit i ever seen i'm literally laughing hard rn.

iKarim
11/03/2018, 12:45 PM
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Offline player")

The most stupid shit i ever seen i'm literally laughing hard rn.

You do realize that sscanf passes INVALID_PLAYER_ID with "u" specifier when the name/id entered is invalid? Guess not.

high level stupid fucks [..] fuckwit


Thanks for the compliment lauv <3

good luck handing code over without an explanation to get reps


Apparently, I did explain:


Your problem is that you don't check that killerid is valid, thus your code crashes trying to access the array at 65535 index.


if (killerid != INVALID_PLAYER_ID) gKills[killerid]++;


Come on I thought you could read..

GhostHacker9
11/03/2018, 12:45 PM
Riiight, lmfao, i'm outta there this shit is beyond me i don't like dealing with that high level stupid fucks tbfh, good luck handing code over without an explanation to get reps you fuckwit lol.


chill you just got roasted and please drink some water...

The most stupid shit i ever seen i'm literally laughing hard rn.

and why is that so?

ivndosos
11/03/2018, 12:47 PM
for god sake take this somewhere else

RogueDrifter
11/03/2018, 12:57 PM
You do realize that sscanf passes INVALID_PLAYER_ID with "u" specifier when the name/id entered is invalid? Guess not.

Actually no.

Thanks for the compliment lauv <3
At least you know what describes you best!


Apparently, I did explain:



Come on I thought you could read.. Complete and utter bs, the whole code was flawed and you only explained one bit which might not even be the problem,

Hey at least i wasn't desperate enough to recreate my release threads about 2 times because no one ever gave a shit! what's even more funny is that i was the only one yet to reply again lmfao!

ivndosos
11/03/2018, 12:59 PM
@iKarim @cessil

Thanks guys your methods fixed it.

iKarim
11/03/2018, 01:00 PM
Actually no.


Actually, yes:

https://i.imgur.com/6BObJTi.png

Test it yourself, duh!


Complete and utter bs, the whole code was flawed and you only explained one bit which might not even be the problem,


Others explained the rest.


Hey at least i wasn't desperate enough to recreate my release threads about 2 times because no one ever gave a shit! what's even more funny is that i was the only one yet to reply again lmfao!

Again getting something completely irrelevant, because reasons, to sound smart.

ps. you are not.

RogueDrifter
11/03/2018, 01:02 PM
Actually, yes:

https://i.imgur.com/6BObJTi.png

Test it yourself, duh!



Others explained the rest.



Again getting something completely irrelevant, because reasons, to sound smart, ps. you are not.
Actually, yes:

Dumbass i meant i didn't know the plugin had this feature, whatever enough spam i'm done here and the thread starter got his problem fixed.

iKarim
11/03/2018, 01:04 PM
Dumbass i meant i didn't know the plugin had this feature, whatever enough spam

Yeah of course, you definitely posted that in your last reply.