Calling %s in a textdraw? Help needed.
#1

I've been trying to create a /afk command with textdraws, but when when I try and do it just fails. If I add ,pName at the end of the textdraw it says number of arguments does not match definition, and when I leave it just %s is AFK! It just says simply "%s" and not the name. Help please?

Код:
{
		if(strcmp("/afk",cmdtext, true) == 0) {
		new pName[MAX_PLAYER_NAME];
		GetPlayerName(playerid,pName,sizeof(pName));
TextDrawShowForAll(IsAFK);
		TogglePlayerControllable(playerid,0);
		return 1;
		}
Код:
IsAFK = TextDrawCreate(260.000000,222.000000,"%s is now AFK!");
	TextDrawAlignment(IsAFK,0);
	TextDrawBackgroundColor(IsAFK,0x000000ff);
	TextDrawFont(IsAFK,3);
	TextDrawLetterSize(IsAFK,0.599999,1.900000);
	TextDrawColor(IsAFK,0xff0000ff);
	TextDrawSetOutline(IsAFK,1);
	TextDrawSetProportional(IsAFK,1);
	TextDrawSetShadow(IsAFK,1)
Reply
#2

Here, put this function at the bottom of your script.
Код:
stock PlayerName(playerid)
{
  new name[MAX_PLAYER_NAME];
  GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  return name;
}
This makes using a player name 'easier'.

Код:
new str[48];//put this in your command
format(str,48,"%s is now AFK!",PlayerName(playerid);
TextDrawSetString(IsAFK,str);
TextDrawHideForAll(IsAFK);
TextDrawShowForAll(IsAFK);
SetTimer("HideTextTimer",5000,0);//optional
Код:
forward HideTextTimer();//optional
public HideTextTimer()
{
  TextDrawHideForAll(IsAFK);
}


Reply
#3

Hmm.. I appreciate your help but for some reason it still shows as this;

And the timer didn't seem to work either. :\
Reply
#4

Код:
format(str,48,"%s is now AFK!",PlayerName(playerid);
needs to be:

Код:
format(str,48,"%s is now AFK!",PlayerName(playerid));
one extra ) at the end
Reply
#5

I know, I already fixed that but it's still bugged.
Reply
#6

Do you want an other colour?
Reply
#7

Код:
//Top of your script
new FALSE = false;
#define TextDrawSetFormat(%0,%1) do{new _str[128]; format(_str,128,%1); TextDrawSetString(%0,_str);}while(FALSE) //This function isn't really necessary, but it simplified the script.

new AFKTDTimer;
new bool:IsAFKShown;

forward HideAFK();
Код:
public OnGameModeInit()
{
	IsAFKShown = false;
}
Код:
public SomePublicWhereYouWantToCreateYourTextDraw(...)
{
	IsAFK = TextDrawCreate(260.000000,222.000000,"_"); //Empty TextDraw, it isn't needed to contain something.
	TextDrawAlignment(IsAFK,0);
	TextDrawBackgroundColor(IsAFK,0x000000ff);
	TextDrawFont(IsAFK,3);
	TextDrawLetterSize(IsAFK,0.599999,1.900000);
	TextDrawColor(IsAFK,0xff0000ff);
	TextDrawSetOutline(IsAFK,1);
	TextDrawSetProportional(IsAFK,1);
	TextDrawSetShadow(IsAFK,1);
}
Код:
public OnPlayerCommandText(playerid, cmdtext)
{
	if(strcmp("/afk",cmdtext, true) == 0) 
	{
		if(IsAFKShown == true) KillTimer(AFKTDTimer);
		AFKTDTimer = SetTimer("HideAFK", 5000, false);
		IsAFKShown = true;
		TogglePlayerControllable(playerid,0);
		TextDrawSetFormat(IsAFK, "%s is now AFK!", PlayerName(playerid)) //PlayerName Function from [LSD]Rac3r
		TextDrawShowForAll(IsAFK);
		return 1;
	}
	return 0;
}
Код:
public HideAFK()
{
	IsAFKShown = false;
	TextDrawHideForAll(IsAFK);
	return 1;
}
Should work.
Reply
#8

I added exactly what you said, and got this;

(27) : warning 235: public function lacks forward declaration (symbol "AFKTextdraw")
(104) : error 025: function heading differs from prototype
(106) : error 035: argument type mismatch (argument 2)
(113) : error 001: expected token: ";", but found "-identifier-"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


3 Errors.

Line 27: public AFKTextdraw()
Line 104: public OnPlayerCommandText(playerid, cmdtext)
Line 106: if(strcmp("/afk",cmdtext, true) == 0)
Line 113: TextDrawShowForAll(IsAFK);
Reply
#9

Line 27: I never said something about a public called AFKTextdraw(), but you need to forward it as I did with HideAFK().

Line 104: change cmdtext into cmdtext[]

Line 106: Must be solved with the fix at line 104.

Line 113: Place a ; at the end of line 112.
Reply
#10

Quote:
Originally Posted by Remi-X
Line 27: I never said something about a public called AFKTextdraw(), but you need to forward it as I did with HideAFK().
Thanks for the help, the other three are fixed, but I was thinking when you put:
Quote:
Originally Posted by Remi-X
Код:
public SomePublicWhereYouWantToCreateYourTextDraw(...)
{
	IsAFK = TextDrawCreate(260.000000,222.000000,"_"); //Empty TextDraw, it isn't needed to contain something.
	TextDrawAlignment(IsAFK,0);
	TextDrawBackgroundColor(IsAFK,0x000000ff);
	TextDrawFont(IsAFK,3);
	TextDrawLetterSize(IsAFK,0.599999,1.900000);
	TextDrawColor(IsAFK,0xff0000ff);
	TextDrawSetOutline(IsAFK,1);
	TextDrawSetProportional(IsAFK,1);
	TextDrawSetShadow(IsAFK,1);
}
Should work.
To change it to whatever I want..?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)