Weapon textdraw
#1

Hello,

I am trying to make textdraw which will show current weapon player is holding.
But the problem is, when I enter the game I can only see how much ammo I have, wepaon textdraw is full black

Code:
Код:
new PlayerText:playerweapon[MAX_PLAYERS];
new PlayerText:playerammo[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
PlayerTextDrawShow(playerid,playerweapon[playerid]);
PlayerTextDrawShow(playerid,playerammo[playerid]);
}
public OnPlayerDisconnect(playerid)
{
PlayerTextDrawHide(playerid,playerweapon[playerid]);
PlayerTextDrawDestroy(playerid,playerweapon[playerid]);
PlayerTextDrawHide(playerid,playerammo[playerid]);
PlayerTextDrawDestroy(playerid,playerammo[playerid]);
}

stock CreatePlayerTD(playerid) // under onplayerconnect
{
	playerweapon[playerid] = CreatePlayerTextDraw(playerid, 521.500000, 70.000000, ".");
	PlayerTextDrawLetterSize(playerid, playerweapon[playerid], 0.449999, 1.600000);
	PlayerTextDrawAlignment(playerid, playerweapon[playerid], 1);
	PlayerTextDrawColor(playerid, playerweapon[playerid], -1);
	PlayerTextDrawSetShadow(playerid, playerweapon[playerid], 0);
	PlayerTextDrawSetOutline(playerid, playerweapon[playerid], 1);
	PlayerTextDrawFont(playerid, playerweapon[playerid], TEXT_DRAW_FONT_MODEL_PREVIEW);
 	PlayerTextDrawSetPreviewModel(playerid, playerweapon[playerid], 325135); 

	playerammo[playerid] = CreatePlayerTextDraw(playerid, 564.500000, 72.916648, "Ammo: 0");
	PlayerTextDrawLetterSize(playerid, playerammo[playerid], 0.287000, 1.430833);
	PlayerTextDrawAlignment(playerid, playerammo[playerid], 1);
	PlayerTextDrawColor(playerid, playerammo[playerid], -1);
	PlayerTextDrawSetShadow(playerid, playerammo[playerid], 0);
	PlayerTextDrawSetOutline(playerid, playerammo[playerid], 1);
	PlayerTextDrawBackgroundColor(playerid, playerammo[playerid], 255);
	PlayerTextDrawFont(playerid, playerammo[playerid], 1);
	PlayerTextDrawSetProportional(playerid, playerammo[playerid], 1);
}
timer OnUpdatePlayer[1000]()
{
    foreach(Player,i)
	{
        new weaponid = GetPlayerWeapon(i);
 		PlayerTextDrawSetPreviewModel(i, playerweapon[i], GetWeaponModel(weaponid));
}
	return 1;
}
stock GetWeaponModel(weaponid)
{
	switch(weaponid)
	{
	    case 1:
	        return 331;

		case 2..8:
		    return weaponid+331;

        case 9:
		    return 341;

		case 10..15:
			return weaponid+311;

		case 16..18:
		    return weaponid+326;

		case 22..29:
		    return weaponid+324;

		case 30,31:
		    return weaponid+325;

		case 32:
		    return 372;

		case 33..45:
		    return weaponid+324;

		case 46:
		    return 371;
	}
	return 0;
}
Reply
#2

Anyone?
Reply
#3

Before anything, use printf and make sure GetWeaponModel returns the correct value. Then, try doing something like this:
PHP код:
PlayerTextDrawSetPreviewModel(iplayerweapon[i], GetWeaponModel(weaponid));
PlayerTextDrawShow(iplayerweapon[i]); 
Usually you must show the TextDraw again in order to apply the changes.

PD: you might avoid initialing a new variable (weaponid) doing this:
PHP код:
GetWeaponModelGetPlayerWeapon(i) ) 
Reply
#4

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
Before anything, use printf and make sure GetWeaponModel returns the correct value. Then, try doing something like this:
PHP код:
PlayerTextDrawSetPreviewModel(iplayerweapon[i], GetWeaponModel(weaponid));
PlayerTextDrawShow(iplayerweapon[i]); 
Usually you must show the TextDraw again in order to apply the changes.

PD: you might avoid initialing a new variable (weaponid) doing this:
PHP код:
GetWeaponModelGetPlayerWeapon(i) ) 
Where should I implement the last one you have written?
Under stock or OnUpdatePlayer?


EDIT: problem...
Reply
#5

Inside OnUpdatePlayer timer. Alright, returning to the TextDraw issue, are you sure you created it correctly? It looks like a huge black element to me, you should worry about that!

Remember preview models don't use box but they require the text size function.
Reply
#6

Код:
	playerweapon[playerid] = CreatePlayerTextDraw(playerid, 521.500000, 70.000000, "_");
	PlayerTextDrawLetterSize(playerid, playerweapon[playerid], 0.449999, 1.600000);
	PlayerTextDrawAlignment(playerid, playerweapon[playerid], 1);
	PlayerTextDrawColor(playerid, playerweapon[playerid], -1);
	PlayerTextDrawSetShadow(playerid, playerweapon[playerid], 0);
	PlayerTextDrawSetOutline(playerid, playerweapon[playerid], 1);
	PlayerTextDrawFont(playerid, playerweapon[playerid], TEXT_DRAW_FONT_MODEL_PREVIEW);
 	PlayerTextDrawSetPreviewModel(playerid, playerweapon[playerid], 325135);
This is weapon textdraw
Reply
#7

I don't see any PlayerTextDrawTextSize line there, you must use it in order to define the size.
Quote:
Originally Posted by SA-MP Wiki
Using font type 4 (sprite) and 5 (model preview) converts X and Y of this function from corner coordinates to WIDTH and HEIGHT (offsets).
Reply
#8

I have managed to do something.

Thank you for help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)