Cant Hide TextDraws
#1

So I made a fuction that making shows textdraw to player:
PHP код:
new Text:textdraw;
MyTextDraw(playeridFloat:TextXFloat:TextYTextString[50], TextColorTextOutlineTextShadowTextFontFloat:LetterXFloat:LetterY)
{
    
textdraw TextDrawCreate(TextXTextYTextString);
    
TextDrawColor(textdrawTextColor);
    
TextDrawSetOutline(textdrawTextOutline);
    
TextDrawSetShadow(textdrawTextShadow);
    
TextDrawFont(textdrawTextFont);
    
TextDrawLetterSize(textdrawLetterXLetterY);
    
TextDrawAlignment(textdraw2);
    
TextDrawShowForPlayer(playeridtextdraw);

and then I added few skins:
PHP код:
public OnGameModeInit()
{
    
SetGameModeText("Deathmatch");
    
#include <Playerskins> //include of all the AddPlayerClass
    
return 1;

And under OnPlayerRequestClass I used my function:
PHP код:
public OnPlayerRequestClass(playeridclassid)
{
    
MyTextDraw(playerid32055"Choose Skin:"COLOR_LIGHTBLUE1030.73.1);
    return 
1;

And finnaly I tried to hid the textdraw when they spawn
PHP код:
public OnPlayerRequestSpawn(playerid)
{
    
TextDrawHideForPlayer(playeridtextdraw);
    return 
1;

When they choose the first skin (CJ) the textdraw dissappear perfectly, but when they choose another skin the textdraw doesnt dissapper
I dont know what to do
Reply
#2

that happens because you're creating textdraw multiple times.

you should make this var per player, reset it, check for it, destroy it....

->
PHP код:
new Text:textdraw[MAX_PLAYERS] = {-1, ...};
MyTextDraw(playeridFloat:TextXFloat:TextYTextString[50], TextColorTextOutlineTextShadowTextFontFloat:LetterXFloat:LetterY)
{
    
textdraw[playerid] = TextDrawCreate(TextXTextYTextString);
    
TextDrawColor(textdraw[playerid], TextColor);
    
TextDrawSetOutline(textdraw[playerid], TextOutline);
    
TextDrawSetShadow(textdraw[playerid], TextShadow);
    
TextDrawFont(textdraw[playerid], TextFont);
    
TextDrawLetterSize(textdraw[playerid], LetterXLetterY);
    
TextDrawAlignment(textdraw[playerid], 2);
    
TextDrawShowForPlayer(playeridtextdraw[playerid]);

PHP код:
public OnPlayerRequestClass(playeridclassid)
{
    if(
textdraw[playerid] == -1)
        
MyTextDraw(playerid32055"Choose Skin:"COLOR_LIGHTBLUE1030.73.1);
    return 
1;

PHP код:
public OnPlayerRequestSpawn(playerid)
{
    if(
textdraw[playerid] != -1)
    {
        
TextDrawHideForPlayer(playeridtextdraw[playerid]);
        
PlayerTextDrawDestroy(playeridtextdraw[playerid]);
        
textdraw[playerid] = Text:-1;
    }
    return 
1;

please consider that there's way much better ways to get this done and also you need to destroy and reset he var textdraw[playerid] on player disconnect in case the textdraw exists.

also you can use global textdraw, make it once, show it once, hide it once...
Reply
#3

Quote:
Originally Posted by jlalt
Посмотреть сообщение
that happens because you're creating textdraw multiple times.

you should make this var per player, reset it, check for it, destroy it....

->
PHP код:
new Text:textdraw[MAX_PLAYERS] = {-1, ...};
MyTextDraw(playeridFloat:TextXFloat:TextYTextString[50], TextColorTextOutlineTextShadowTextFontFloat:LetterXFloat:LetterY)
{
    
textdraw[playerid] = TextDrawCreate(TextXTextYTextString);
    
TextDrawColor(textdraw[playerid], TextColor);
    
TextDrawSetOutline(textdraw[playerid], TextOutline);
    
TextDrawSetShadow(textdraw[playerid], TextShadow);
    
TextDrawFont(textdraw[playerid], TextFont);
    
TextDrawLetterSize(textdraw[playerid], LetterXLetterY);
    
TextDrawAlignment(textdraw[playerid], 2);
    
TextDrawShowForPlayer(playeridtextdraw[playerid]);

PHP код:
public OnPlayerRequestClass(playeridclassid)
{
    if(
textdraw[playerid] == -1)
        
MyTextDraw(playerid32055"Choose Skin:"COLOR_LIGHTBLUE1030.73.1);
    return 
1;

PHP код:
public OnPlayerRequestSpawn(playerid)
{
    if(
textdraw[playerid] != -1)
    {
        
TextDrawHideForPlayer(playeridtextdraw[playerid]);
        
PlayerTextDrawDestroy(playeridtextdraw[playerid]);
        
textdraw[playerid] = Text:-1;
    }
    return 
1;

please consider that there's way much better ways to get this done and also you need to destroy and reset he var textdraw[playerid] on player disconnect in case the textdraw exists.

also you can use global textdraw, make it once, show it once, hide it once...
Ok thank you but what the -1 means in this line:

PHP код:
new Text:textdraw[MAX_PLAYERS] = {-1, ...}; 
Reply
#4

setting textdraw id to invalid id, so we can know if its already made or no.
Reply
#5

The -1 is like INVALID PLAYER ID, as in samp Player ID started from 0, Not -1 !
So that it can be used for players, and also getting that is it used or not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)