[RELEASE]Notepad.cs (save & read notes)

GoodMan

Active member
Joined
Jun 4, 2014
Messages
148
Reaction score
0
Hello UGBASE, i would like to make public one of my projects which is a notepad for SAMP.

Features:

Type /n <text> to save a note
Type /rn <text> to search for a note

REMINDER:
Do not leave empty lines in your Notepad.ini file as it will lead to duplicated results when using /rn to search for a note. i couldn't fix this using STRLEN, if you find a bug, wanna add more features to it, let me know, im willing to improve the code and add more features. post your suggestions below.

BTW: no need to create ini file because it will be created automatically once you launch the cleo for first time.
CODE:
PHP:
{$CLEO .cs}
0000: NOP

WHILE 8AFA: is_samp_available
    WAIT 0
END

03A4: name_thread 'Notepad'
0AF8: samp add_message_to_chat "Visit {4B0082}U{2F4F4F}G{4B0082}B{483D8B}A{2E8B57}S{4B0082}E{556B2F}.{3B3B6D}E{5F9EA0}U {4B0082}| \"GoodMan\"" 0xFF4682B4

IF 0AAB: file_exists "CLEO\Notepad.ini"
THEN
    0AF8: samp add_message_to_chat "USAGE:{AAAAAA} Type {4682B4}/n <text>{AAAAAA} to save a note" 0xFF4682B4
    0AF8: samp add_message_to_chat "USAGE:{AAAAAA} Type {4682B4}/rn <text>{AAAAAA} to search for a note" 0xFF4682B4
ELSE
    CHATMSG "{FF0000}File wasn't found: \"Notepad.INI\", It is being created now, then you can add information there." 0xFF4682B4
    WHILE 8A9A: 1@ = openfile "CLEO\Notepad.ini" mode "at"
    WAIT 0
    END
    0AF8: samp add_message_to_chat "USAGE:{AAAAAA} Type {4682B4}/n <text>{AAAAAA} to save a note" 0xFF4682B4
    0AF8: samp add_message_to_chat "USAGE:{AAAAAA} Type {4682B4}/rn <text>{AAAAAA} to search for a note" 0xFF4682B4
END

0B34: samp register_client_command "N" to_label @N
0B34: samp register_client_command "RN" to_label @RN

WHILE TRUE
    WAIT 0
    /**/  
    IF AND
        8B21: samp is_chat_opened
        8B4C: samp is_dialog_active -1
        0AB0: KEY_PRESSED 27
    THEN
        0B63: samp unregister_client_command "N"
        0B63: samp unregister_client_command "RN"
        REPEAT
        WAIT 0
        UNTIL 8AB0: KEY_PRESSED 27
        0A92: create_custom_thread "Notepad.cs"
        004E: end_thread
    END
   
END
//-------------------------------------------------------//
{
REPEAT                                                     //DOES THIS WORK TO PREVENT CRASH?
WAIT 0                                                     //DOES THIS WORK TO PREVENT CRASH?
    PRINTF "Press 'X' to restart Notepad.cs script" 100    //DOES THIS WORK TO PREVENT CRASH?
UNTIL 0AB0: KEY_PRESSED 88 // X                            //DOES THIS WORK TO PREVENT CRASH?
0A92: create_custom_thread "Notepad.cs"                    //DOES THIS WORK TO PREVENT CRASH?
004E: end_thread                                           //DOES THIS WORK TO PREVENT CRASH?
//-------------------------------------------------------//
}

:N
WAIT 0
0AB1: @CREATE_NOTE 0
0B43: samp cmd_ret

:RN
WAIT 0  
0AB1: @READ_NOTEPAD 0 
0B43: samp cmd_ret  
            
:READ_NOTEPAD
0B35: samp 0@ = get_last_command_params
0C17: 5@ = strlen 0@
IF 5@ > 0
THEN
    4@ = 0 // COUNT
    IF 0AAB: file_exists "CLEO\Notepad.ini"
    THEN
        WHILE 8A9A: 1@ = openfile "CLEO\Notepad.ini" mode "rt"
        WAIT 0
        END 
        ALLOC 2@ 24
        REPEAT
        0AD7: read_string_from_file 1@ to 2@ size 23
        0C17: 6@ = strlen 2@
        IF 6@ > 0
        THEN
            IF 0C29: 3@ = stristr string1 2@ string2 0@
            THEN
                4@ += 1
                CHATMSG "%d: {00FF00}%s" 0xFF4682B4 4@ 2@
            END
        END
        UNTIL 0AD6:   end_of_file 1@ reached
        0A9B: closefile 1@
        FREE 2@ 
    ELSE
        CHATMSG "(NOTE) {4682B4}Notepad.ini not found in your CLEO folder! A new empty file has been generated." 0xFF4682B4
        WHILE 8A9A: 1@ = openfile "CLEO\Notepad.ini" mode "rt"
        WAIT 0
        END 
        ALLOC 2@ 24
        REPEAT
        0AD7: read_string_from_file 1@ to 2@ size 23
        0C17: 6@ = strlen 2@
        IF 6@ > 0
        THEN
            IF 0C29: 3@ = stristr string1 2@ string2 0@
            THEN
                4@ += 1
                CHATMSG "%d: {00FF00}%s" 0xFF4682B4 4@ 2@
            END
        END
        UNTIL 0AD6:   end_of_file 1@ reached
        0A9B: closefile 1@                 
        FREE 2@
    END
    IF 4@ > 0
    THEN CHATMSG "(NOTE) Matching entries found for {AAAAAA}\"%s\": {00FF00}%d" 0xFF4682B4 0@ 4@
    ELSE CHATMSG "(NOTE) {4B0082}No matching entries found for {AAAAAA}\"%s\"." 0xFF4682B4 0@
    END
ELSE 0AF8: samp add_message_to_chat "(NOTE){AAAAAA} Type {4682B4}/rn <text>{AAAAAA} to search for a note" 0xFF4682B4
END
0AB2: RET 0

:CREATE_NOTE
0B35: samp 0@ = get_last_command_params
0C17: 3@ = strlen 0@
IF 3@ > 0
THEN
    IF 0AAB: file_exists "CLEO\Notepad.ini"
    THEN   
        WHILE 8A9A: 1@ = openfile "CLEO\Notepad.ini" mode "at"
        WAIT 0
        END 
        0AD9: write_text "%s %c" in_file 1@ 0@ 0xA
        CHATMSG "\"%s\"" 0xFFAAAAAA 0@
        CHATMSG "(NOTE) {AAAAAA}New entry saved. Total characters: {00FF00}%d" 0xFF4682B4 3@
        0A9B: closefile 1@
    ELSE
        WHILE 8A9A: 1@ = openfile "CLEO\Notepad.ini" mode "at"
        WAIT 0
        END  
        0AD9: write_text "%s %c" in_file 1@ 0@ 0xA
        CHATMSG "(NOTE) {AAAAAA}Notepad.ini not found in your CLEO folder! A new empty file has been generated." 0xFF4682B4
        CHATMSG "\"%s\"" 0xFFAAAAAA 0@
        CHATMSG "(NOTE) {AAAAAA}New entry saved. Total characters: {00FF00}%d" 0xFF4682B4 3@
        0A9B: closefile 1@
    END
ELSE
    0AF8: samp add_message_to_chat "(NOTE) {AAAAAA}Type {4682B4}/n <text>{AAAAAA} to save a note" 0xFF4682B4
END
0AB2: RET 0
 

Attachments

  • Notepad.cs
    23.1 KB · Views: 0
Last edited by a moderator:
Top