Kills and Deaths
#1

Okay so first i'm making a gangwar server so i got a register and login script i did everything else like Setplayerhealth and vehicles adding i just need help when some one dies the get a -1 score and they get a death ponit in there user like on the account and if a person gets a kill they get 2 points and they get a kill point on there users so when i go to my user file and click a name i can see there kills and deaths.
Reply
#2

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        if(killerid == INVALID_PLAYER_ID)//They killed them self
    {
        SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
        }
    else if(gTeam[killerid] != gTeam[playerid])//They killed a opposite team member
    {
        SendDeathMessage(killerid,playerid,reason);
        SetPlayerScore(killerid,GetPlayerScore(killerid)+2);//Killer Gains 2 Score
        SetPlayerScore(playerid,GetPlayerScore(playerid)-1);//Player Loses 1 Score
        }
        else //else they killed someone
    {
        SetPlayerScore(killerid,GetPlayerScore(killerid)+2);//Killer Gains 2 Score
        SetPlayerScore(playerid,GetPlayerScore(playerid)-1);//Player Loses 1 Score
        SendDeathMessage(killerid,playerid,reason);
        }
        return 1;
}
Try that
Reply
#3

Hello, here is few things:

About score things, put this 'OnPlayerDeath'
pawn Код:
public OnPlayerDeath(playerid, killerid)
{
SetPlayerScore(playerid,GetPlayerScore(playerid)-1); // Gives -1 point to player who died.
PlayerInfo[playerid][deaths] = PlayerInfo[playerid][deaths] +1; // Gives death point to player who died, you need to adjust this to your script
SetPlayerScore(playerid,GetPlayerScore(killerid)+2); // Gives +2 point to player who killed another player.
PlayerInfo[killerid][deaths] = PlayerInfo[killerid][kills] +1; // Gives kill point to player who killed another player, you need to adjust this to your script
}
Then save 'PlayerInfo[playerid][deaths]' and 'PlayerInfo[killerid][kills]' on player disconenct.

Edit this script to fit your GM, and note that this wasn't tested, and it might be incorrect.

EDIT:Nevermind this, as it was answered before i managed to press 'Post'.
Reply
#4

thanks all but it wont save onto the server files the score will save but the kills doesn't how do i edit my register system to save the kills and deaths onto the folder

examples of save how do i make it so it would make senence with the other get player a kill script i used

dini_IntSet(playerfile, "Level", level[playerid]);
dini_IntSet(playerfile, "Cash", GetPlayerMoney(playerid));
dini_IntSet(playerfile, "Score", GetPlayerScore(playerid));
Reply
#5

Quote:
Originally Posted by GoldenM4
Посмотреть сообщение
thanks all but it wont save onto the server files the score will save but the kills doesn't how do i edit my register system to save the kills and deaths onto the folder

examples of save how do i make it so it would make senence with the other get player a kill script i used

dini_IntSet(playerfile, "Level", level[playerid]);
dini_IntSet(playerfile, "Cash", GetPlayerMoney(playerid));
dini_IntSet(playerfile, "Score", GetPlayerScore(playerid));
This is a snippet of my code.

pawn Код:
//top of the script.
new Kills[MAX_PLAYERS];
new Deaths[MAX_PLAYERS];

//put these under OnPlayerDisconnect, it will save the players current kills/deaths when they disconnect.
//Could also place these in a timer which saves players stats every once and awhile.
dini_IntSet(playerfile, "Kills", Kills[playerid]);
dini_IntSet(playerfile, "Deaths", Deaths[playerid]);

//under OnPlayerDeath
Kills[killerid] ++; //increases the killers "kills" stats by 1
Deaths[playerid] ++; //increases the player who died "deaths" stats by 1.

//put this code when a player registers there account, e.g When a player types /register and it's sucessful.
//or if you use a dialog, place it when the register dialog is sucessful.
dini_IntSet(playerfile, "Deaths", 0);
dini_IntSet(playerfile, "Kills", 0);

//add this when a player logs into there account.
//e.g, When a player types /login and it's sucessful. or if you use dialog when the player types in the correct login password
Kills[playerid] = dini_Int(playerfile, "Kills");
Deaths[playerid] = dini_Int(playerfile, "Deaths");

//the /stats command, you could also add other stats such as admin levels/vip levels to this command if you really wanted to.

COMMAND:stats(playerid, params[])
{
    new string1[126];
    new plname[25];
    GetPlayerName(playerid, plname, 25);
    new Float:ratio=floatdiv(Kills[playerid], Deaths[playerid]); //also added in a K/D Ratio for you you can just delete it if you don't want it.
    format(string1, sizeof(string1), "%s's Stats: Kills: %d, Deaths %d, K/D Ratio: %.2f", plname,Kills[playerid],Deaths[playerid],ratio);
    SendClientMessage(playerid,COLOR_ORANGE, string1);
    return 1;
}
//you could add other stats in here like Money by Money[playerid]; or however you saved it.
format(string1, sizeof(string1), "%s's Stats: Kills: %d, Deaths %d, K/D Ratio: %.2f,Money: %d", plname,Kills[playerid],Deaths[playerid],ratio,Money[playerid]);
//then you could also go about adding in your score saving etc, or if you already have a /stats command you could merge these together.
The code works fine on my server but this was just a copy/paste from my GM so hopefully i havn't missed anything out.

If you wanted to get the players stats that you clicked on you could do something like this
Credits to Hiddos for this tut which helped me learn this https://sampforum.blast.hk/showthread.php?tid=158294

pawn Код:
//not sure if this code will work as i do them differently on my server but yeh, if theres any problems you should beable to work them out with the tut.
public OnPlayerClickPlayer(playerid, clickedclickedplayerid, source)
{
    new string2[126];
    new plname[25];
    GetPlayerName(clickedplayerid, plname, 25);
    new Float:ratio=floatdiv(Kills[clickedplayerid], Deaths[clickedplayerid]);
    format(string2, sizeof(string2), "%s's Stats: Kills: %d, Deaths %d, K/D Ratio: %.2f", plname,Kills[clickedplayerid],Deaths[clickedplayerid],ratio);
    SendClientMessage(playerid,COLOR_ORANGE, string2);
    return 1;
}
Reply
#6

WOW love it nice but how do i do the ifplayer is admin theey can see but if there not admin they cant see?
Reply
#7

if(IsPlayerAdmin(playerid))

Use that line
Reply
#8

thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)