SA-MP Forums Archive
Cant Hide TextDraws - 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)
+--- Thread: Cant Hide TextDraws (/showthread.php?tid=642878)



Cant Hide TextDraws - iTz1T4Y - 08.10.2017

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


Re: Cant Hide TextDraws - jlalt - 08.10.2017

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...


Re: Cant Hide TextDraws - iTz1T4Y - 10.10.2017

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, ...}; 



Re: Cant Hide TextDraws - jlalt - 10.10.2017

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


Re: Cant Hide TextDraws - FuNkYTheGreat - 10.10.2017

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.