PDA

View Full Version : Player Textdraw Doesn't show...


SsHady
18/12/2016, 06:17 AM
Hey!

So, I made a player-textdraw that would show everytime when someone types a wrong command.

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
new str[256];
format(str,sizeof(str),"The Command ~y~%s ~w~does not exist, To see all commands use ~y~/cmds ",cmdtext);
PlayerTextDrawSetString(playerid,wrongcmd[playerid],str);
PlayerTextDrawShow(playerid,wrongcmd[playerid]);
SetTimerEx("HideWrongTD", 4000, false, "i", playerid);
}
return 1;
}

forward HideWrongTD(playerid);

public HideWrongTD(playerid)
{
PlayerTextDrawHide(playerid, wrongcmd[playerid]);
}

Somehow, The textdraw isn't showing... Whenever someone types a wrong command, nothing happens.
I tried changing this
public HideWrongTD(playerid)
{
PlayerTextDrawHide(playerid, wrongcmd[playerid]);
}

to this

public HideWrongTD(playerid)
{
PlayerTextDrawDestroy(playerid, wrongcmd[playerid]);
}

It shows the textdraw for the first time, but after that it doesn't show it.

This is irritating, any kind of help would be appreciated?

iLearner
18/12/2016, 06:32 AM
Don't destroy it, just hide it(if it shows for first time only).

SsHady
18/12/2016, 06:37 AM
I am hiding it using the following
public HideWrongTD(playerid)
{
PlayerTextDrawHide(playerid, wrongcmd[playerid]);
}

But it isn't showing in the first place...Nothing is happening whenever someone is typing a wrong command.

iLearner
18/12/2016, 06:43 AM
Do you mind showing us the textdraw?

SsHady
18/12/2016, 06:54 AM
The problem is in here,

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
new str[75];
format(str,sizeof(str),"The Command ~y~%s ~w~does not exist, To see all commands use ~y~/cmds ",cmdtext);
PlayerTextDrawSetString(playerid,wrongcmd[playerid],str);
PlayerTextDrawShow(playerid,wrongcmd[playerid]);
SetTimerEx("HideWrongTD", 6000, false, "i", playerid);
}
return 1;
}

If I use new str[70]; and keep it within 70, it perfectly shows the textdraw however some text doesn't show. If i increase it over 70, it doesn't show the entire textdraw.

NaS
18/12/2016, 06:58 AM
Never put spaces at the end of a Textdraw Text! That prevents any TextDraw/GameText from showing.

The size of the string should be at least 90 btw. That will show a command of the length 20 maximum, when longer the text will get cut.

SsHady
18/12/2016, 07:04 AM
Never put spaces at the end of a Textdraw Text! That prevents any TextDraw/GameText from showing.

The size of the string should be at least 90 btw. That will show a command of the length 20 maximum, when longer the text will get cut.

Thanks a lot, it fixed it.

Does anyone know whether there is a way in which like if a player types /blahslkdjasdkasd or any other big wrong command, it only shows some characters of it and change it to like /blahsikl.... and with dots at the end?


public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
new str[75];
format(str,sizeof(str),"The Command ~y~%s ~w~does not exist, To see all commands use ~y~/cmds",cmdtext);
PlayerTextDrawSetString(playerid,wrongcmd[playerid],str);
PlayerTextDrawShow(playerid,wrongcmd[playerid]);
SetTimerEx("HideWrongTD", 6000, false, "i", playerid);
}
return 1;
}

NaS
18/12/2016, 07:05 AM
Thanks a lot, it fixed it.

Does anyone know whether there is a way in which like if a player types /blahslkdjasdkasd or any other big wrong command, it only shows some characters of it and change it to like /blahsikl.... and with dots at the end?

[pawn]
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
new str[75];
format(str,sizeof(str),"The Command ~y~%s ~w~does not exist, To see all commands use ~y~/cmds",cmdtext);
PlayerTextDrawSetString(playerid,wrongcmd[playerid],str);
PlayerTextDrawShow(playerid,wrongcmd[playerid]);
SetTimerEx("HideWrongTD", 6000, false, "i", playerid);
}
return 1;
}/pawn]

Use strmid if the text is longer than X characters. strmid copies a string, from a given start position to a given end position.


new str[90];

if(strlen(cmdtext) > 20)
{
strmid(str, cmdtext, 0, 20);
strcat(str, "...");
}
else strcat(str, cmdtext);

format(str,sizeof(str),"The Command ~y~%s ~w~does not exist, To see all commands use ~y~/cmds", str);


Alternatively you can set the last 4 characters of cmdtext to "...\0" to cap it at 20 characters max.

SsHady
18/12/2016, 08:20 AM
Thanks alot.