TextDrawDestroy (a workaround/upgrade?)
#21

I do 2 things to avoid this issue

1. Create a textdraw wrapper.. aka a textdraw with id 0 for player texts and server textdraws, so incase anything happens, it will try to destroy id 0. (which is the invisible unused textdraw)

2. Initilize textdraws as INVALID_TEXT_DRAW (INVALID_PLAYER_TEXT_DRAW)

3. On destroy, set the textdraw variable to INVALID_TEXT_DRAW (INVALID_PLAYER_TEXT_DRAW)

works perfect.
Reply
#22

pawn Код:
new Text:pTextdraw[MAX_PLAY] = {Text:INVALID_TEXT_DRAW, ...};
is for one dimension.

How to declare two dimension textdraws?
for example

new PlayetText: Options[MAX_PLAYERS][MAX_OPTIONS]=
Reply
#23

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
pawn Код:
new Text:pTextdraw[MAX_PLAY] = {Text:INVALID_TEXT_DRAW, ...};
is for one dimension.

How to declare two dimension textdraws?
for example

new PlayetText: Options[MAX_PLAYERS][MAX_OPTIONS]=
I believe it's something like this

pawn Код:
new Array[ARRAY_SIZE][ARRAY_SIZE]= { {number, ...}, ...};
Reply
#24

No idea. By the way I thought of a problem with my hooking method. If you destroy textdraws in a loop:

pawn Код:
for(new i=0; i<MAX_TEXTDRAWS; i++)
{
    TextDrawDestroy(i);
}
It's going to set 'i' to INVALID_TEXT_DRAW. Nobody really deletes all textdraws in a loop though so idk. Not sure what would happen if you put a literal integer in like

TextDrawDestroy(69);

Both things that should never be done though.
Reply
#25

What I've seen some people do is improperly initialize arrays of TextDraw IDs, such as this:
pawn Код:
new
    Text:g_SomeTextDraw[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW}
;
The proper way to do it is this:
pawn Код:
new
    Text:g_SomeTextDraw[MAX_PLAYERS] = {Text:INVALID_TEXT_DRAW, ...} // <- dots
;
If you leave the dots out, only the first element will be INVALID_TEXT_DRAW; the rest will be 0.

Edit: Oops, didn't see page 2.


Quote:
Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
I believe it's something like this

pawn Код:
new Array[ARRAY_SIZE][ARRAY_SIZE]= { {number, ...}, ...};
The only way to initialize multi-dimensional arrays is by looping, preferably in On(GameMode/FilterScript)Init.

Edit 3: Like this.
Reply
#26

To prevent having to init the var/arrays it'd probably be easier just to skip ID 0 (create a textdraw that is never shown and never deleted). Then in a hooked function if you try to delete ID 0 just deny it. That'd save initializing variables.
Reply
#27

Why is that better? You lose a text draw slot and have to run custom code in the destruction function, instead of using an in-built compiler feature that's takes half a second to use.
Reply
#28

What in-built compiler feature? Initializing variables to INVALID_TEXT_DRAW? It's easier to skip that part. Plus:

http://forum.sa-mp.com/showpost.php?...postcount=3341
Reply
#29

Yeah I know, I'm not even sure if I want to be a programmer anymore. I have a lot to learn.

(I edited my post, original post was something like 'I like to script things simply not complicated').

Anyway - off-topic.
Reply
#30

Quote:
Originally Posted by Slice
Посмотреть сообщение
Here's a little include I wrote to initialize multi-dimensional arrays. So far it's very simple, but I might add some more features and officially release it.
I was wondering if you would do that (I was tempted after I saw your Useful Functions post). Nicely done (though I'm not sure how the mutli-line declaration you've used in that example will work, but I've not looked closely).
Reply
#31

I settled for prepending "stock @_Ar<ARRAY NAME>" so the list either carries on or stops by a semi-colon.
Reply
#32

Ahh. Something I have tried to solve numerous times (well, one of the things I'm constantly mulling over in the back of my mind) is if it's possible to detect HOW the variables were declared, so instead of "stock" you could put "new" or "static const" there based on what was first typed.
Reply
#33

As i see it, this does explain an issue based on the following circumstances:

PlayerX is playing...
Server restarts...
PlayerX crashes...
PlayerX connects...


When that happens a GPS textdraw i made looks a bit weird, but the script fixes that when the player spawns.

This is because the textdraw string for that player does not initialize correctly, Even tho i have a proper use of TextDrawDestroy in OnGameModeExit and OnPlayerDisconnect.

Instead of showing "] ] ]". It actually shows nothing, so either the textdraw string is initalized as null or a string with characters that does not show up in a textdraw. E.g: space, underscore, etc.
Reply
#34

I had this problem, in my gamemode I simply set all text-draws and player text-draws to be created on OnGameModeInit and destroyed on OnGameModeExit, this works well enough. It's best to just avoid creating/deleting them in runtime in my opinion.


The only problem I have is if I do this:

Start server
Load a filterscript with textdraws
Restart the server

Then I get problems with gamemode textdraws taking instructions from filterscripts.

But then again I only load and de-load filterscripts for testing purposes, when my gamemode is hosted the only filterscript won't have any GUI, all the main stuff is in the gamemode.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)