[SNIPPET] Textdraw Finder

[shcode=cpp]    {$CLEO}

    :Noname_02                      /* This snippet has been created by Shanker :) Enjoy RPG.B-Zone.Ro (RO/EN) */
    WAIT 0 MS

    :Noname_03
    WAIT 0 MS
    IF NOT SAMP.Available
      THEN
      JUMP @Noname_03
    END
    
    0B34: Create Command "FindTXD" to label @Noname_8130
    CHATMSG "Textdraw Finder created by Shanker. Use /FindTXD INT | INT = 0 TO INT" -1
    CHATMSG "Enjoy FORUM.B-ZONE.RO THE BIGGEST SAMP COMMUNITY [RO/EN]" -1
    
    var
    1@ : int
    5@ : int
    end
    
    :Noname_04
    WAIT 0 MS
    JUMP @Noname_04
     
    :Noname_8130
    SAMP.IsCommandTyped(0@)
    IF 8AD4: NOT 4@ = SCAN 0@ format "%d" 5@
       THEN JUMP @ERROR
    END
       1@ += 1
         IF 1@ == 5@
          THEN GOTO @CMDRET
       END
          IF 0C5D: samp textdraw 1@ is_exists
            THEN CHATMSG "I found textdraw %d " -1 1@
         END
    
    :Noname_8140
    JUMP @Noname_8130
    
    :CMDRET
    1@ = 0 
    SAMP.CmdRet
    
    :ERROR
    CHATMSG "You need an integer. " -1
    SAMP.CmdRet[/shcode]

Hello I want to show you my method how to find a textdraw, after I finished my Interface Editor some guys asked me how I got ID of them :).
Because forum have some problems I will give you source here: http://pastebin.com/gmCucN1s
First time I wanted to do it with "FOR" function but I still don't know it very good, @Springfield can you show me an example please? You know I won't forget to add you a positive rate :)).
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
http://gtaforums.com/topic/696339-cleo-advanced-script-tutorial/
Check this out if you want to know more about loops, especially about FOR loop
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Check this too, http://ugbase.eu/Thread-Sanny-Builder-Syntax, might be useful.

Thanks for contributing, but you should format the text a little so it's easier to read/understand.

Here's an example on how to get the textdraw ID based on the textdraw text.

[shcode=cpp]
0B34: "txd" @textdraw
//usage example: "/txd b-zone.ro"

:textdraw
0B35: 0@
for 1@ = 0 to 2304
   if 0C5D: samp textdraw 1@ is_exists
   then
       alloc 2@ = 1024
       0C5A: samp textdraw 1@ get_string_to 2@
       if 0C29: 3@ = stristr string1 2@ string2 0@
       then 0AF8: "textdraw with id %d contains %s text" -1 1@ 0@
       end
free 2@
   end
end
0B43:
[/shcode]
 

shanker

Well-known member
Joined
Sep 18, 2016
Messages
291
Reaction score
16
Location
Romania
Hmm I have a question, I didn't tested your example it 100% should work, but,
[shcode=cpp]for 1@ = 0 to 2304 
if 0C5D: samp textdraw 1@ is_exists [/shcode]
I read some examples from "gogel" with FOR function and all of them contains smt like:
[shcode=cpp]FOR x@ = X to Y
do smt // This script will be repeated for Y-X times
END[/shcode]
 
so your script should look like:
[shcode=cpp]

:Noname_03
SAMP.IsCommandTyped(0@)
FOR 1@ = 0 TO 2000
  2@ += 1 // FROM HERE TO ... (CHECK FIRST END )
  IF 0C5D: samp textdraw 2@ is_exists
  THEN
      0AC8: $STRING = allocate_memory_size 260
      0C5A: samp textdraw 2@ get_string_to $STRING
      IF 0C29: 3@ = stristr string1 $STRING string2 0@  // OR 0C29: 3@ = stristr string1 0@ string2 $STRING , are the same thing right? if 3@ == 2@ then 2@ == 3@, then this "rule" should apply here to
        THEN 0AF8: "Textdraw with id %d contains %s text" -1 2@ $STRING
      END  // HERE SCRIPT WILL REPEATED FOR 2000 TIMES
    END
  END
END [/shcode]

p.S: Thanks for your example it will be useful :>
I just ask don't kill me please :( i'm sorry if I'm wrong it :D don't kill me :((
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Not quite. While your example will work, it might fail in some cases.

The for syntax is the following
[shcode=cpp]
for var@ = <start val> TO/DOWNTO <end val> step <n>
[/shcode]

meaning it will set var@ to <start val> and then for each loop it will increase/decrease var@ by <n> until is equal to <end val>

[shcode=cpp]
for 0@ = 0 to 5
   wait 0
   chatmsg "%d" -1 0@
end
[/shcode]

is the same as

[shcode=cpp]

0@ = 0
:_label
if 0@ >= 5 
then jump @_end
end
chatmsg "%d" -1 0@
0@++
jump @_label

:_end
[/shcode]

So in your example, 1@ will start from 0 and increase by 1 until it reaches 2000.

Read here about the sa-mp limits: https://wiki.sa-mp.com/wiki/Limits
It says there are a limit of 2048 + 256 textdraws, that means we should loop above 2000.
Also, the max string length is 1024, so if the text is longer than 260 it will crash the game.
 
Top