Problem with global kills
#1

Hi all,i've coded a textdraw to show global kills of a team. (In this case usa).

I do it in this way:

pawn Код:
new UsaKills;
OnPlayerConnect

pawn Код:
new ukills[128];
    format(ukills, sizeof(ukills), "Usa Kills: %d", UsaKills);
    TextDrawSetString(UKD, ukills);
    TextDrawShowForAll(UKD);
OnPlayerDeath

pawn Код:
if ( killerid == TEAM_USA )
    {
        UsaKills += 1 ;
    }
The textdraw shows but the counter of kills doesn't increase.What's wrong?
Reply
#2

try:

pawn Код:
if(killerid == TEAM_USA)
{
UsaKills+=1;
new ukills[24];
format(ukills, sizeof(ukills), "Usa Kills: %d", UsaKills);
TextDrawSetString(UKD, ukills);
}
Reason why it doesn't work is because you don't re update it after the score has increased
Reply
#3

This line is most likely your problem.
pawn Код:
if(killerid == TEAM_USA)
Replace it with:

pawn Код:
if(GetPlayerTeam(killerid) == TEAM_USA)
EDIT: Use 0ne's code but change the line I posted above.
Reply
#4

Thanks,it's fixed now.I've another problem.

When server restart,the textdraw doesn't save the kills counter,why?

Ex: It shows UsaKills: 65 - After restart: UsaKills 0

How to fix this?
Reply
#5

You'd have to save the score in a file. I'll edit my post with some code.


EDIT: This should save the score if I scripted it correctly.
pawn Код:
#include <dini>

#define SCOREFILE "score.ini"

public OnPlayerDeath(playerid)
{
    if(GetPlayerTeam(killerid) == TEAM_USA)
    {
        UsaKills++;
        new ukills[20];
        format(ukills, sizeof(ukills), "Usa Kills: %d", UsaKills);
        TextDrawSetString(UKD, ukills);
    }
        return 1;
}

public OnGameModeInit()
{
    UsaKills = dini_Int(SCOREFILE, "USAKills"); //Store the value from the file into the variable.
    return 1;
}

public OnGameModeExit()
{
    dini_IntSet(SCOREFILE, "USAKills", UsaKills); //Save the team's kills into a file.
    return 1;
}
Reply
#6

Thanks very much! It works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)