Problem with global kills - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with global kills (
/showthread.php?tid=260883)
Problem with global kills -
Face9000 - 11.06.2011
Hi all,i've coded a textdraw to show global kills of a team. (In this case usa).
I do it in this way:
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?
Re: Problem with global kills -
0ne - 11.06.2011
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
Re: Problem with global kills -
PotH3Ad - 11.06.2011
This line is most likely your problem.
Replace it with:
pawn Код:
if(GetPlayerTeam(killerid) == TEAM_USA)
EDIT: Use 0ne's code but change the line I posted above.
Re: Problem with global kills -
Face9000 - 11.06.2011
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?
Re: Problem with global kills -
PotH3Ad - 11.06.2011
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;
}
Re: Problem with global kills -
Face9000 - 11.06.2011
Thanks very much! It works