Is there a way to know how many 3D Text Label's my server haves?
#1

Like, for example, I create In Game 200 Text Labels.

Is there a callback, for example, that can be executed with a command which tells me that in that moment, my server haves 200 active 3D Text Labels?
Reply
#2

It don't think there is a native function for this, as far as I know, you can create an array, assign all of its slots to -1 or even better INVALID_3DTEXT_ID,
to find out the count, loop through that array, check if the slots do not equal those initial values (-1 or INVALID_3DTEXT_ID), and increase your counting variable by 1.

-Create a global array to store 3D label ID's:
PHP код:
new glabels[MAX_3DTEXT_GLOBAL] = {INVALID_3DTEXT_ID, ...}; //Global 3D labels
new plabels[MAX_3DTEXT_PLAYER] = {INVALID_3DTEXT_ID, ...}; //Player 3D labels 
- Store the id's of your 3D labels on that array

-Create these functions:
PHP код:
//Function that returns the amount of global 3D labels
glabelCount()
{
    new 
count 0;
    for(new 
0i<MAX_3DTEXT_GLOBALi++)
    {
        if(
glabels[i] != INVALID_3DTEXT_ID)
            
count++;
    }
    return 
count;
}
//Function that returns the amount of player 3D labels
plabelCount()
{
    new 
count 0;
    for(new 
0i<MAX_3DTEXT_PLAYERi++)
    {
        if(
plabels[i] != -1)
            
count++;
    }
    return 
count;

- Calling the functions:
PHP код:
printf("Global 3D labels count: %d"glabelCount());
printf("Player 3D labels count: %d"plabelCount());
printf("All 3D labels count: %d"glabelCount() + plabelCount()); 
Reply
#3

There is a better way:

Код:
new TextLabels = 0; // on the top of your script

// somewhere in your script
Text3D:Create3DTextLabelEx(text[], color, Float:X, Float:Y, Float:Z, Float:DrawDistance, VirtualW, testLOS = 0)
{
    TextLabels += 1;
    return Create3DTextLabel(text, color, X, Y, Z, DrawDistance, VirtualW, testLOS);
}

Delete3DTextLabelEx(Text3D:id)
{
    TextLabels -=1;
    return Delete3DTextLabel(Text3D:id);
}

How to use:

Use "Create3DTextLabelEx" instead of "Create3DTextLabel"
and "Delete3DTextLabelEx" instead of "Delete3DTextLabel"

printf("%d", TextLabels); // print number of created labels
EDIT: fixed name of the variable
Reply
#4

Quote:
Originally Posted by Hrb
Посмотреть сообщение
There is a better way:

Код:
new 3DTextLabels = 0;
Yeah, that's definitely better, but you can't start a variable name with numbers.
Reply
#5

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Yeah, that's definitely better, but you can't start a variable name with numbers.
small mistake, i forgot about this condition
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)