Help Chat Verify Bot

zefedy

New member
Joined
Oct 29, 2022
Messages
2
Reaction score
0
The situation I need in a roleplay server is that after catching a few fish, the chat drops a 6-digit code "SERVER: You must enter the fish code first. (/fishcode 123456)" and makes it impossible for you to catch fish until you write the code in parentheses. I am waiting for your help.

Can we turn this into a bot? For example, let's say the fishing command is /takefish, should it give a 6-second timeout and hold it until the code arrives, if it can enter the code at any time it wants and continue?

I saw crazy people on this forum who could do it, but none of them were useful to me. I'm looking forward to your help, friends :)))
 

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
165
Location
Poland
Script.cs
PHP:
{$CLEO .cs}
{$USE bitwise}
0000:

WHILE TRUE
WAIT 0

IF 0ADC:   test_cheat "1" 
THEN
    0B12: 31@ = 31@ XOR 1
    IF 31@ == 1
    THEN
        0AD1: "~g~Script has been~n~turned on" 1000
    ELSE
        0AD1: "~r~Script has been~n~turned off" 1000
    END
END

IF 31@ == 1
THEN
    IF 0256:   player $PLAYER_CHAR defined
    THEN
        0AC8: 0@ = allocate_memory_size 1024
        0AC8: 1@ = allocate_memory_size 1024
        0AB1: @getChatString 1 ChatID 99 _Returned: Text 0@ PrefixText 1@ Color 2@ PrefixColor 3@
        0AC8: 4@ = allocate_memory_size 1024
        0AB1: @DeleteColorCodesFromText 2 text 0@ memory_to_store_characters_as_text 4@
        0AC8: 5@ = allocate_memory_size 1024
        0AD3: 5@ = format "SERVER: You must enter the fish code first."            
        IF 0AB1: @IfTextContains 2 String1 0@ String2 5@ _Returned: Text 6@
        THEN
            0AC8: 7@ = allocate_memory_size 1024
            0AB1: @get_digits_to_print 2 text 6@ memory_to_store_digits_as_text 7@
            0AC8: 8@ = allocate_memory_size 1024
            0AD3: 8@ = format "/fishcode %s" 7@            
            0AB1: @get_samp_version_id 0 _returned: ID 9@
            0AB1: @process_chat_input 2 SampVersionID 9@ InputText 8@
            0AC9: free_allocated_memory 8@
            WAIT 15000                    
        END                        
    END
END

END
0A93: terminate_this_custom_script
Script_debug.cs
PHP:
{$CLEO .cs}
{$USE bitwise}
0000:

WHILE TRUE
WAIT 0

IF 0ADC:   test_cheat "2" 
THEN
    0AB1: @get_samp_version_id 0 _returned: ID 0@
    0AC8: 1@ = allocate_memory_size 1024
    0AD3: 1@ = format "SERVER: You must enter the fish code first. (/fishcode 123456)"
    0AB1: @Chatmsg 3 SampVersionID 0@ text 1@ color -1
END

END
0A93: terminate_this_custom_script
 

Attachments

  • Script.cs
    18.4 KB · Views: 4
  • Script_debug.cs
    4.5 KB · Views: 2

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
165
Location
Poland
aren't all these allocations leaking memory?
Probably yes. If you want, you can design a correct example, then I will learn a bit too, because at the moment it works, but it's not fully stable. (Prawdopodobnie tak. Jeśli chcesz możesz zaprojektować poprawny przykład, wtedy i ja się troszkę nauczę, bo w tej chwili to działa, ale nie jest w pełni stabilne.)
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,104
Solutions
5
Reaction score
882
Location
Lithuania
aren't all these allocations leaking memory?
Hi Monday,

Could you spare some time and explain everyone about memory allocation.
How much it needs to be allocated for text etc.. and how it should be used correctly.

Thank you.

Regards,
Parazitas.
 

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
165
Location
Poland
Fixed example by @Opcode.eXe , thx.
PHP:
{$CLEO .cs}
{$USE bitwise}
0000:

WHILE TRUE
WAIT 0

IF 0ADC:   test_cheat "1"
THEN
    0B12: 31@ = 31@ XOR 1
    IF 31@ == 1
    THEN
        0AD1: "~g~Script has been~n~turned on" 1000
    ELSE
        0AD1: "~r~Script has been~n~turned off" 1000
    END
END

IF 31@ == 1
THEN


    IF 0256:   player $PLAYER_CHAR defined
    THEN
        { ALLOCATE ALL MEMORY FOR USE}
        0AC8: 0@ = allocate_memory_size 1024
        0AC8: 1@ = allocate_memory_size 1024   
        0AC8: 4@ = allocate_memory_size 1024
        0AC8: 5@ = allocate_memory_size 1024 
        0AC8: 7@ = allocate_memory_size 1024
        0AC8: 8@ = allocate_memory_size 1024
        
        0AB1: @getChatString 1 ChatID 99 _Returned: Text 0@ PrefixText 1@ Color 2@ PrefixColor 3@
        0AB1: @DeleteColorCodesFromText 2 text 0@ memory_to_store_characters_as_text 4@
        0AD3: 5@ = format "SERVER: You must enter the fish code first."         
          
        IF
        0AB1: @IfTextContains 2 String1 0@ String2 5@ _Returned: Text 6@
        THEN
            0AB1: @get_digits_to_print 2 text 6@ memory_to_store_digits_as_text 7@
            0AD3: 8@ = format "/fishcode %s" 7@           
            0AB1: @get_samp_version_id 0 _returned: ID 9@
            0AB1: @process_chat_input 2 SampVersionID 9@ InputText 8@
            WAIT 15000                   
        END 
        
        { FREE ALL MEMORY AFTER USE}
        0AC9: free_allocated_memory 0@
        0AC9: free_allocated_memory 1@
        0AC9: free_allocated_memory 4@
        0AC9: free_allocated_memory 5@
        0AC9: free_allocated_memory 7@
        0AC9: free_allocated_memory 8@                   
    END
END

END
0A93: terminate_this_custom_script
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,125
Reaction score
151
Hi Monday,

Could you spare some time and explain everyone about memory allocation.
How much it needs to be allocated for text etc.. and how it should be used correctly.

Thank you.

Regards,
Parazitas.
Hi Parazitas,

The general idea is that whenever the programmer asks the computer to allocate some memory (e.g. by using "malloc" in C language, or 0AC8 opcode in CLEO), the computer will let the programmer to use part of memory, and the computer will not attempt to use that part for other purposes (until it's deallocated).
So the programmer should deallocate memory (e.g. by using "free" in C language, or 0AC9 opcode in CLEO) when it's no longer needed.
If the programmer keeps asking the computer for more memory, without giving it back, at some point there won't be any memory left.

Typically for text, at least 1 byte per 1 character should be allocated (+1 byte to store "0" value which marks the end of the text in memory). So to store "Happy Birthday" message, 15 bytes should be allocated (14 for text, and the additional byte to store "0").
If the text is likely to change during operation of the program, we should allocate as much bytes as the longest text can be (+1). In such case it's better to allocate too much, rather than to allocate not enough (if we allocate not enough, our text value may overwrite memory that is used for some other purpose, causing weird program behaviour or crashing it).

Regards,
Monday.
 
Top