PDA

View Full Version : Players Number


IceSKull
08/04/2017, 11:35 AM
Hello guys! need a bit help!

---- if(IsPlayerInArea....) die ----
I want the total number of players die in the area!

+ Give him the score same to the numbers of Players died

LEOTorres
08/04/2017, 11:45 AM
This should be good.

new deathcount;

public OnPlayerDeath(playerid, killerid, reason)
{
if (IsPlayerInArea (playerid, ...))
{
deathcount++;
SetPlayerScore (playerid, deathcount);
}

return 1;
}

Odeath
08/04/2017, 11:52 AM
You want to give score to the players who die or to the player who killed them ?

IceSKull
08/04/2017, 11:54 AM
Who killed them!

LEOTorres
08/04/2017, 11:56 AM
Who killed them!

In that case:

new deathcount;

public OnPlayerDeath(playerid, killerid, reason)
{
if (IsPlayerInArea (playerid, ...))
{
deathcount++;

if(killerid != INVALID_PLAYER_ID)
{
SetPlayerScore (killerid, deathcount);
}
}

return 1;
}

IceSKull
08/04/2017, 11:58 AM
I also want to Get a number of Players:

format(String,sizeof(String),"*%s Players Has been killed.",deathcount);

But that Gives error!

LEOTorres
08/04/2017, 12:03 PM
I also want to Get a number of Players:

format(String,sizeof(String),"*%s Players Has been killed.",deathcount);

But that Gives error!

deathcount is an integer, in this case, you would use:

format (String, sizeof(String), "%i players have been killed.", deathcount);

IceSKull
08/04/2017, 12:05 PM
Thank u very much :P im just a beginner :p

Odeath
08/04/2017, 12:15 PM
Don't use
new deathcount;

public OnPlayerDeath(playerid, killerid, reason)
{
if (IsPlayerInArea (playerid, ...))
{
deathcount++;

if(killerid != INVALID_PLAYER_ID)
{
SetPlayerScore (killerid, deathcount);
}
}

return 1;
}
it will not increment the player's score it will initialize the score and then set it to deathcount
for example if you killed 4 players and you had 5 score you score will be 4 not 9
if(killerid != INVALID_PLAYER_ID)
{
new Score = GetPlayerScore(killerid) + 1;
SetPlayerScore (killerid, Score);
}

IceSKull
08/04/2017, 12:20 PM
Well the score wasnt the probleM! i wanted to know to get the Number of players! But that integer also gives error!

Odeath
08/04/2017, 12:24 PM
Show me the error

IceSKull
08/04/2017, 12:29 PM
Fixed!

LEOTorres
08/04/2017, 12:30 PM
Don't use

it will not increment the player's score it will initialize the score and then set it to deathcount
for example if you killed 4 players and you had 5 score you score will be 4 not 9

Perhaps I'm not understanding his English, but I was under the impression that's what he said he wanted.

If it isn't, you can simply do:

SetPlayerScore (killerid, GetPlayerScore(killerid) + deathcount);

The code you provided only increases the score by one, it doesn't take into account the other players dead within the area, which if someone else were to kill, wouldn't be added onto the killer's score.

Again, I'm assuming that is what he wants, your interpretation may be correct.

Odeath
08/04/2017, 12:46 PM
Perhaps I'm not understanding his English, but I was under the impression that's what he said he wanted.

If it isn't, you can simply do:

SetPlayerScore (killerid, GetPlayerScore(killerid) + deathcount);

The code you provided only increases the score by one, it doesn't take into account the other players dead within the area, which if someone else were to kill, wouldn't be added onto the killer's score.

Again, I'm assuming that is what he wants, your interpretation may be correct.

No i just corrected the SetPlayerScore.
If you use SetPlayerScore (killerid, GetPlayerScore(killerid) + deathcount);
When you kill the first person for example and your score is 0 deathcount will be 1 and you're score will be 1.
And when you kill the second person deathcount will be 2 and you're score will be 3 not 2 because it will add 2 to the score.
So he must add 1 score and he must also set deathcount to 0 after some second and set deathcount as array deathcount[MAX_PLAYERS] so every player can have his deathcount.

LEOTorres
08/04/2017, 12:53 PM
No i just corrected the SetPlayerScore.
If you use SetPlayerScore (killerid, GetPlayerScore(killerid) + deathcount);
When you kill the first person for example and your score is 0 deathcount will be 1 and you're score will be 1.
And when you kill the second person deathcount will be 2 and you're score will be 3 not 2 because it will add 2 to the score

He stated he wanted the total number of overall players who have died within that area to be added onto the score, not just one player, or the players that a specific player has killed, which you're under the impression of.

numbers of Players died

Anyway, he's fixed the problem, so it's all good.

Odeath
08/04/2017, 12:56 PM
But he will get a probleme when many players are killing in the same time .
And deathcount will never reset and it will cause many problemes!

LEOTorres
08/04/2017, 01:04 PM
But he will get a probleme when many players are killing in the same time .
And deathcount will never reset and it will cause many problemes!

What are you talking about?

His script isn't restricted to the code he provided, the deathcount doesn't need to be reset within the OnPlayerDeath callback. OP can reset the deathcount at another place where he wishes, we're only here to help him with the script issues he's having. We can't make assumptions about how his gamemode works because, he hasn't stated what his intention with the feature is.

Anyway, this is going off-topic; I'll stop replying.