GetTextdrawX?
#1

Alright so I am making some textdraws etc, anyone so far came across that they need the X of the textdraw? Well basicaly I will have a command to update the textdraw (bump it by x+5), so far I didnt find any UpdateTextDraw or such, what methods you guys use?
Reply
#2

What are you actually trying to do?
Reply
#3

You can make this yourself very easily.

pawn Код:
enum TDINFO {
    Float:TDX,
    Float:TDY,
}

new TDData[MAX_TEXT_DRAWS][TDInfo];

#define SetTextDrawX(%0,%1) TDData[%0][TDX] = %1
#define GetTextDrawX(%0) TDData[%0][TDX]
#define SetTextDrawY(%0,%1) TDData[%0][TDY] = %1
#define GetTextDrawZ(%0) TDData[%0][TDY]
You could even hook the function if you feel like it.
Reply
#4

Feel free to re-use my textdraw system.

pawn Код:
/* ------------ Purpose: Game TextDraws ------------  */

enum ETDType {
    EType_Normal,
    EType_VehGUI, //vehicle GUI
};
enum eTextDrawProps {
    TextDrawName[128],
    Float:TDScreenX,
    Float:TDScreenY,
    Float:TDLetterSizeX,
    Float:TDLetterSizeY,
    Float:PlayerTDTextSizeX,
    Float:PlayerTDTextSizeY,
    TDAlignment,
    TDColor,
    TDUseBox,
    TDBoxColor,
    TDSetShadow,
    TDSetOutline,
    TDBgColor,
    TDFont,
    TDSetProportional,
    TDCanBeHiddenByPlayer,
    ETDType:ETDrawType
};
new TextDrawProperties[][eTextDrawProps] = { //Here you can add the textdraw formats to manipulate them later, they load automatically
    {"uiHelpText", 529.000732, 157.629531, 0.150333, 0.849183,513.667419, 166.340988,2,-1,true,150,0,0,180,2,1,0,EType_Normal},
    {"FadeScreen", -20.000000, 2.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0, 0,true,0,0,0,0,0,1,0,EType_Normal},
    {"WebsiteTD", 570.000000, 10.000000, 0.270000, 1.000000,-415.458435, 167.092651, 2, -1724710657,false,0,0,1,255,3,1,0,EType_Normal}
};

new PlayerText:TextDrawID[MAX_TEXT_DRAWS][MAX_PLAYERS];

initializeTextDraws(playerid) { //Here we can initialize textdraws among other things
    showSiteTD(playerid, 1, 255, 0xFF0000FF, "~r~nameofyourserver.com"); //-1724710657
}
forward showSiteTD(playerid, show, bgcolor, fontcolor, const parsedstring[]);
public showSiteTD(playerid, show, bgcolor, fontcolor, const parsedstring[]) {
    new websiteTD = GetPVarInt(playerid, "WebsiteTD");
    new stringParse[64];
    PlayerTextDrawHide(playerid, PlayerText:websiteTD); //Hide it first so it doesn't overlap
    if(show == 1) {
        format(stringParse,sizeof(stringParse),"%s",parsedstring);
        PlayerTextDrawSetString(playerid, PlayerText:GetPVarInt(playerid, "WebsiteTD"), stringParse);
        PlayerTextDrawBackgroundColor(playerid, PlayerText:websiteTD, bgcolor);
        PlayerTextDrawBoxColor(playerid, PlayerText:websiteTD, bgcolor);
        PlayerTextDrawColor(playerid, PlayerText:websiteTD, fontcolor);
        PlayerTextDrawShow(playerid, PlayerText:websiteTD);
    } else {
        PlayerTextDrawHide(playerid, PlayerText:websiteTD);
    }
}
forward colorScreen(playerid, show, color);
public colorScreen(playerid, show, color) {
    new fadeID = GetPVarInt(playerid, "FadeScreen");
    PlayerTextDrawHide(playerid, PlayerText:fadeID); //Hide it first so it doesn't overlap
    if(show == 1) {
        PlayerTextDrawBackgroundColor(playerid, PlayerText:fadeID, color);
        PlayerTextDrawBoxColor(playerid, PlayerText:fadeID, color);
        PlayerTextDrawColor(playerid, PlayerText:fadeID, color);
        PlayerTextDrawShow(playerid, PlayerText:fadeID);
    } else {
        PlayerTextDrawHide(playerid, PlayerText:fadeID);
    }
}
ShowScriptMessage(playerid, parsedstring[], timeout = 5000) {
    hideHelpText(playerid);
    new string[128];
    format(string,sizeof(string),"%s",parsedstring);
    PlayerTextDrawSetString(playerid, PlayerText:GetPVarInt(playerid, "uiHelpTxt"), string);
    PlayerTextDrawShow(playerid, PlayerText:GetPVarInt(playerid, "uiHelpTxt"));
    SetTimerEx("hideHelpText", timeout, false, "d", playerid);
    textDrawInUse(playerid, 1);
    return 1;
}
forward hideHelpText(playerid);
public hideHelpText(playerid) {
    PlayerTextDrawHide(playerid, PlayerText:GetPVarInt(playerid, "uiHelpTxt"));
    return 1;
}
forward hideAllTextDrawsForPlayer(playerid);
public hideAllTextDrawsForPlayer(playerid) {
    for(new i=0; i < sizeof(TextDrawProperties); i++) {
        if(TextDrawProperties[i][TDCanBeHiddenByPlayer] == 1) {
            PlayerTextDrawHide(playerid, PlayerText:GetPVarInt(playerid, TextDrawProperties[i][TextDrawName]));
        }
    }
    textDrawInUse(playerid, 0);
}
forward destroyAllTextDrawsForPlayer(playerid);
public destroyAllTextDrawsForPlayer(playerid) {
    for(new i=0; i < sizeof(TextDrawProperties); i++) {
        PlayerTextDrawDestroy(playerid, PlayerText:GetPVarInt(playerid, TextDrawProperties[i][TextDrawName]));
        DeletePVar(playerid, TextDrawProperties[i][TextDrawName]);
    }
}
textDrawInUse(playerid, active) {
    if(active == 1) {
        SetPVarInt(playerid, "TextDrawInUse", active);
    } else {
        DeletePVar(playerid, "TextDrawInUse");
    }
    return 1;
}
isTextDrawInUse(playerid) {
    if(GetPVarType(playerid, "TextDrawInUse") != PLAYER_VARTYPE_NONE) {
        return 1;
    }
    return 0;
}
textdrawsOnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    #pragma unused oldkeys
    if(isTextDrawInUse(playerid)) {
        if(newkeys & KEY_FIRE) {
            hideAllTextDrawsForPlayer(playerid);
        }
    }
    return 1;
}
/* Initialize TD's*/
textdrawsOnPlayerConnect(playerid) {
    for(new i=0; i < sizeof(TextDrawProperties); i++) {
        TextDrawID[i][playerid] = CreatePlayerTextDraw(playerid, TextDrawProperties[i][TDScreenX], TextDrawProperties[i][TDScreenY], "None");
        PlayerTextDrawLetterSize(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDLetterSizeX], TextDrawProperties[i][TDLetterSizeY]);
        PlayerTextDrawTextSize(playerid, TextDrawID[i][playerid], TextDrawProperties[i][PlayerTDTextSizeX], TextDrawProperties[i][PlayerTDTextSizeY]);
        PlayerTextDrawAlignment(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDAlignment]);
        PlayerTextDrawColor(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDColor]);
        PlayerTextDrawUseBox(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDUseBox]);
        PlayerTextDrawBoxColor(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDBoxColor]);
        PlayerTextDrawSetShadow(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDSetShadow]);
        PlayerTextDrawSetOutline(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDSetOutline]);
        PlayerTextDrawBackgroundColor(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDBgColor]);
        PlayerTextDrawFont(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDFont]);
        PlayerTextDrawSetProportional(playerid, TextDrawID[i][playerid], TextDrawProperties[i][TDSetProportional]);
        SetPVarInt(playerid, TextDrawProperties[i][TextDrawName], _:TextDrawID[i][playerid]);
    }
}
/* Remove all TD's on disconnect */
textdrawsOnTextDrawDisconnect(playerid, reason) {
    if(reason != 3) {
        destroyAllTextDrawsForPlayer(playerid);
    }
}
Using it is simple, you just have to call the functions when your script loads the stuff.
On OnPlayerKeyStateChange you would call textdrawsOnPlayerKeyStateChange(playerid, newkeys, oldkeys) and so on for other callbacks.
initializeTextDraws(playerid) should be called OnPlayerConnect.
Reply
#5

pvars are you kidding me?
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
pvars are you kidding me?
PVars are really useful, except that the SA-MP PVar limit per player is around 800. PVars do allow you to do a lot of things and are useful if you use them carefully, this could've been done with the regular variables to save on performance and not have a lot of pvars being used but who is going to have 300 textdraws anyways?

Here's some of the things you can do with PVars:

pawn Код:
YCMD:setplayervar(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Sets a player PVar");
        return 1;
    }
    new playa, name[64], value[64],type;
    if(!sscanf(params, "k<playerLookup_acc>ds[64]s[64]", playa, type, name, value)) {
        if(!IsPlayerConnected(playa)) {
            SendClientMessage(playerid, X11_RED3, "User not found.");
            return 1;
        }
        switch(type) {
            case PLAYER_VARTYPE_INT: {
                SetPVarInt(playa, name, strval(value));
            }
            case PLAYER_VARTYPE_STRING: {
                SetPVarString(playa, name, value);
            }
            case PLAYER_VARTYPE_FLOAT: {
                SetPVarFloat(playa, name, floatstr(value));
            }
            default: {
                SendClientMessage(playerid, X11_RED3, "Invalid Var Type! The valid types are: 1(int), 2(string), 3(float)");
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_CUSTOMGOLD, "[Notice]: Done!");
    } else {
        SendClientMessage(playerid, X11_WHITE, "USAGE: /SetPlayerVar [playerid/name] [type] [name] [value]");
    }
    return 1;
}
YCMD:deleteplayervar(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, X11_WHITE, "Deletes a players PVar");
        return 1;
    }
    new playa, name[64];
    if(!sscanf(params, "k<playerLookup_acc>s[64]", playa, name)) {
        if(!IsPlayerConnected(playa)) {
            SendClientMessage(playerid, X11_RED3, "User not found.");
            return 1;
        }
        new type = GetPVarType(playa, name);
        if(type == PLAYER_VARTYPE_NONE) {
            SendClientMessage(playerid, X11_RED3, "Failed: PVar not found");
            return 1;
        }
        DeletePVar(playa, name);
        SendClientMessage(playerid, COLOR_CUSTOMGOLD, "[Notice]: Done!");
    } else {
        SendClientMessage(playerid, X11_WHITE, "USAGE: /DeletePlayerVar [playerid/name] [name]");
    }
    return 1;
}
While someone on the forums claimed they were slower, they don't need to be initialized as the regular variables, resulting in more lines of code. While it's not smart enough to use them for something like this, they're actually useful if they're used wisely.
Anyways, let's keep on topic.
Reply
#7

They're completely useless well almost, actually it's a bad habit to use them just like it is to smoke. I could never sink to such a low to use them it's against my standards
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)