Help making a Textdraw -
jakejohnsonusa - 24.11.2012
Ok so I am relitively new to scripting and have never made a textdraw. I was wondering if someone could show me how to make the following code (which is currently a client message) into a textdraw located under the chat messages.
Please & Thanks: jakejohnsonusa
I usually Rep. people who are able to help me
Here is what I would like made into a TextDraw:
Here is the command part:
pawn Код:
new DetectorTimer[MAX_PLAYERS];
new DetectorOn[MAX_PLAYERS]=1;
if (strcmp("/detectoron", cmdtext, true, 11) == 0)
{
if(PlayerInfo[playerid][pDetector])
{
if(IsPlayerInAnyVehicle(playerid))
{
if(DetectorTimer[playerid] != -1) KillTimer(DetectorTimer[playerid]);//
DetectorTimer[playerid] = SetTimerEx("RunDetector", 2000, true, "i", playerid);
SendClientMessage(playerid,-1,"Detector On");
DetectorOn[playerid]=1;
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
return 1;
}
if (strcmp("/detectoroff", cmdtext, true, 12) == 0)
{
if(PlayerInfo[playerid][pDetector])
{
if(IsPlayerInAnyVehicle(playerid))
{
if(DetectorOn[playerid]==0)return SendClientMessage(playerid,-1,"Detector Already OFF");
SendClientMessage(playerid,-1,"Detector OFF");
KillTimer(DetectorTimer[playerid]);
DetectorOn[playerid]=0;
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
return 1;
}
SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
return 1;
}
Here is the Timer part of the command:
pawn Код:
public RunDetector(playerid)
{
new counter = 0, string[128];
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
{
format(string, sizeof(string), "Law Enforcment Detected", Nick(i), i);
SendClientMessage(playerid,0xFF0000FF,string);
counter++;
}
}
if(counter == 0) return SendClientMessage(playerid, 0x1CFF1CFF, "No Law Enforcment Detected.");
return 1;
}
Re: Help making a Textdraw -
Joshman543 - 25.11.2012
You simply create a textdraw like this:
PHP код:
NAMEYOURTD = TextDrawCreate(COORD, COORD, "WHAT YOU WANT TO SAY ");
TextDrawBackgroundColor(NAMEOFTD, COLORID);
TextDrawFont(NAMEOFTD, FONTID);
TextDrawLetterSize(NAMEOFTD,SIZE, SIZE);
TextDrawColor(NAMEOFTD^, -1);
TextDrawSetOutline(NAMEOFTD, 0);
TextDrawSetProportional(NAMEOFTD, 1);
TextDrawSetShadow(NAMEOFTD, 1);
TextDrawUseBox(NAMEOFTD, 1);
TextDrawBoxColor(NAMEOFTD, COLORID;
TextDrawTextSize(NAMEOFTD, SIZE, 0.000000);
Then you can do: TextDrawShowForPlayer(playerid, NAMEOFTD);
TextDrawHideForPlayer(playerid, NAMEOFTD);
I hope this helps!
Re: Help making a Textdraw -
jakejohnsonusa - 25.11.2012
Yes thanks, but how do I make a text draw to display text that changes, I want to make my radar detector code (in first post) a textdraw (That will be under the chat messages area)... Can someone show me how to do this?
Re: Help making a Textdraw -
Bakr - 25.11.2012
You can use the TextDrawSetString function. You need to re-show the textdraw to make it appear with the changes via TextDrawShowForPlayer.
Re: Help making a Textdraw -
jakejohnsonusa - 25.11.2012
I'm very new to scripting and am confused... Would you mind showing me what you mean please?
Thanks: jakejohnsonusa
Re: Help making a Textdraw -
Bakr - 25.11.2012
First you need to declare a variable to hold the TD for each player:
pawn Код:
new
Text: TD_Detector[MAX_PLAYERS];
Now we will create each TD, one for each player. This should be done in OnGameModeInit or OnFilterScriptExit
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
// You need to adjust the coordinates to the desired location
TD_Detector[i] = TextDrawCreate(471.000000, 429.000000, "Your text here");
TextDrawAlignment(TD_Detector[i], 0);
TextDrawBackgroundColor(TD_Detector[i], 0x000000ff);
TextDrawFont(TD_Detector[i], 1);
TextDrawLetterSize(TD_Detector[i], 0.499999,0.899999);
TextDrawColor(TD_Detector[i], 0xffffffff);
TextDrawSetOutline(TD_Detector[i], 1);
TextDrawSetProportional(TD_Detector[i], 1);
TextDrawSetShadow(TD_Detector[i], 1);
}
Now that the TD is created, to display it whenever you need to the player, use TextDrawShowForPlayer
pawn Код:
TextDrawShowForPlayer(playerid, TD_Detector[playerid]);
If you wish to change the text of the TD, then you will need to hide it, change the text, and re-show it.
pawn Код:
TextDrawHideForPlayer(playerid, TD_Detector[playerid]);
TextDrawSetString(TD_Detector[playerid], "Text");
TextDrawShowForPlayer(playerid, TD_Detector[playerid]);
For any documentation of these functions, refer to the Wiki. I CBA to explain them all myself. For easy textdraw creation, look at this script (all done in-game via a menu):
https://sampforum.blast.hk/showthread.php?tid=387597
Re: Help making a Textdraw -
jakejohnsonusa - 25.11.2012
Thanks, this helps alot! I'm working on it right now...