Changing player's score under misc conditions
From SA-MP Wiki
Well, let's extend the deathmatch we made in PAWN Tutorial 1. Let's begin with adding some actions when a player dies. As first, let's add those information appearing at the right side of the screen when a player dies, showing the weapon he was killed with and the killer's name. To do this, simply add this line to your OnPlayerDeath():
Making info about players' death displayed on the right side of the screen
SendDeathMessage(playerid,killerid,reason);
OK - so far so good :) Now, let's add the player some points after he kills an enemy and reduce his score after he kills a teammate. Also, displaying a message when he commits a suicide would be nice.
Changing the player's score
Let's begin with adding points when the player kills someone (no matter who). Paste this under the line we added before:
SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
So, what this function does? After a player is killed by the killer, it adds 1 to the players score (GetPlayerScore(killerid) + 1). If we have written:
SetPlayerScore(killerid,1);
it would set the score to 1, so we have to get the value from the server first.
Scoring for team deathmatches
Now, let's add support for teamkilling (how to create teams is described in the PAWN Tutorial 1). So, we have TEAM_GROVE and TEAM_BALLA defined, and they don't like each other ;) Let's get back to scripting (replace the old SetPlayerScore() line with this).
// check if the player is connected if(IsPlayerConnected(killerid)) { // if the killer's team = killed player's team, then... if(gTeam[playerid]==gTeam[killerid]) { // reduce his score by 1 SetPlayerScore(killerid,GetPlayerScore(killerid)-1); // send him a red message saying that he lost a point SendClientMessage(killerid,0xFF3030AA,"You have killed a teammate! Point lost."); } // if player's ID isn't = killer's ID the killer had to kill an enemy, so let's add him a point else { // add him a point SetPlayerScore(killerid,GetPlayerScore(killerid)+1); } } // so, the player isn't connected? The killer had to be death itself then. else { // reduce his score by 1 SetPlayerScore(killerid,GetPlayerScore(killerid)-1); // send him a red message saying that he lost a point SendClientMessage(killerid,0xFF3030AA,"You have died! Point lost."); }
That's all. Hope you enjoy your new scoring script.
--Sniper89 22:02, 25 July 2006 (CEST)