TextDraw problem...
#1

Ok this is mine TextDraw stats but it only works for id 0 and 1-200 is showing the same as id 0.. how to fix this.. and smal credits to [FS]| .:[ - Vehicle Name Display by Seif - ]:.|[FS]..

Код:
#include <a_samp>

#define GREEN 0x21DD00FF
#define ORANGE 0xF97804FF
#define RED 0xE60000FF

forward statsc();

new Text:Vehicle[MAX_PLAYERS];
new str[256];


new killed[MAX_PLAYERS];
new killer[MAX_PLAYERS];
public OnFilterScriptInit()
{
	print("");
	print("");
	print("");
	SetTimer("statsc",300,1);
 	for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
 	{
	 	Vehicle[playerid] = TextDrawCreate(10.0, 425.0,":");
		TextDrawAlignment(Vehicle[playerid],0);
		TextDrawBackgroundColor(Vehicle[playerid],0x000000ff);
		TextDrawFont(Vehicle[playerid],1);
		TextDrawLetterSize(Vehicle[playerid],0.499999,1.100000);
		TextDrawColor(Vehicle[playerid],0xffffffff);
		TextDrawSetOutline(Vehicle[playerid],1);
		TextDrawSetProportional(Vehicle[playerid],1);
		TextDrawSetShadow(Vehicle[playerid],1);
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	killed[playerid]++;
	killer[killerid]++;
	return 1;
}
public OnFilterScriptExit()
{
  for(new i = 0;i < MAX_PLAYERS; i++)
  {
 		TextDrawHideForPlayer(i,Vehicle[i]);
  }
	return 1;
}

public statsc()
{

	for(new i=0;i<MAX_PLAYERS;i++)
	{
		if (IsPlayerConnected(i))
	  {
		TextDrawHideForPlayer(i,Vehicle[i]);
    format(str, sizeof(str), "Stats: Killed %d Death %d" , killer, killed);
    TextDrawSetString(Vehicle[i],str);
    TextDrawShowForPlayer(i,Vehicle[i]);

  	}
	}
	return 1;
}



public OnPlayerConnect(playerid)
  {
	killed[playerid] = 0;
	killer[playerid] = 0;
	statsc();
	TextDrawShowForPlayer(playerid,Vehicle[playerid]);
	return 1;
}
And sorry for bad English
Reply
#2

Problem is here:
pawn Код:
format(str, sizeof(str), "Stats: Killed %d Death %d" , killer, killed);
Reply
#3

Quote:

Problem is here:
PAWN Code:
format(str, sizeof(str), "Stats: Killed %d Death %d" , killer, killed);

Ok but how to fix it I have tryed so many times..
Reply
#4

pawn Код:
format(str, sizeof(str), "Stats: Killed %d Death %d" , killer, killed);
As "killer" and "killed" are arrays, it's like doing:
pawn Код:
format(str, sizeof(str), "Stats: Killed %d Death %d" , killer[0], killed[0]);
Which is why it show playerid 0's stats to other players.


Also..anywhere else, you do killer[playerid] or so..why not here?

Fixed:
pawn Код:
format(str, sizeof(str), "Stats: Killed %d Death %d" , killer[i], killed[i]);
Reply
#5

Tanks tanks! But now it dosent work on any id... i think is the
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	print("debug");
	killed[playerid]++;
	killer[killerid]++;
	return 1;
}
reson the debug text dosent apper ... when i die..
Reply
#6

This part of code will crash your script when players kill themself because if they /kill or whatever that kill themself, killerid is set to INVALID_PLAYER_ID, which is defined 255 so will produce an out of memory bounds error as you try to modify an inexisting memory address (killer[255])

fix:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
  killed[playerid]++;
  if (killerid != INVALID_PLAYER_ID)
    killer[killerid]++;
  return 1;
}
Reply
#7

Tanks i test it now who noob im am.. I think is working but i dont know (noplayers at the server at this time) Its work...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)