Help making a Textdraw
#1

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;
}
Reply
#2

You simply create a textdraw like this:
PHP код:
NAMEYOURTD TextDrawCreate(COORDCOORD"WHAT YOU WANT TO SAY ");
    
TextDrawBackgroundColor(NAMEOFTDCOLORID);
    
TextDrawFont(NAMEOFTDFONTID);
    
TextDrawLetterSize(NAMEOFTD,SIZESIZE);
    
TextDrawColor(NAMEOFTD^, -1);
    
TextDrawSetOutline(NAMEOFTD0);
    
TextDrawSetProportional(NAMEOFTD1);
    
TextDrawSetShadow(NAMEOFTD1);
    
TextDrawUseBox(NAMEOFTD1);
    
TextDrawBoxColor(NAMEOFTDCOLORID;
    
TextDrawTextSize(NAMEOFTDSIZE0.000000); 
Then you can do: TextDrawShowForPlayer(playerid, NAMEOFTD);
TextDrawHideForPlayer(playerid, NAMEOFTD);

I hope this helps!
Reply
#3

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?
Reply
#4

You can use the TextDrawSetString function. You need to re-show the textdraw to make it appear with the changes via TextDrawShowForPlayer.
Reply
#5

I'm very new to scripting and am confused... Would you mind showing me what you mean please?

Thanks: jakejohnsonusa
Reply
#6

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
Reply
#7

Thanks, this helps alot! I'm working on it right now...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)