Resource icon

Untagged Release Calculator

Status
Not open for further replies.

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
I'd like to share with you a calculator which makes calculations on maximum 4 numbers.

5Xyl1rE.jpg


Usage
Command:
/cc <formula>

Mathematical operators:
+ addition
- substraction
x and * multiplication
/ division

Examples of use:
/cc 2x2
/cc 2*2
/cc 2+2/2
/cc 2+2-2*2


Tested with
-Cleo 4.1
-Samp Functions 5.1
-MG Functions impossible 4.3
-SA-MP 0.3z R1


Limitations
-4 decimal spaces for fractions. (10/3 will give 3.333 instead of 3.33333333333333333333333333333333333333333333...)
-whole numbers input only (unability to do something like 1.1+1.1)
-no exponentiation/roots


Bugs
I had a crash while testing the dialog box but didn't remember the formula I used to analyse the problem. Please let me know if you have any crash, if anyone posted what exact formula causes the problem it would be great.


Additional info
The result keeps being displayed on the screen for 15 seconds after entering the command.


Source
http://pastebin.com/6QGDjQkt
 

Attachments

  • calculator.cs
    28.5 KB · Views: 810

Fu$10N

Expert
Joined
Mar 5, 2014
Messages
1,101
Reaction score
9
Nice mod  :urtheman:
I'm too lazy to calculate myself on rp servers. Now I will be even more lazy with this :me_gusta:
If you can make that  waiting time to be like 5 seconds, it would be even more perfect than now :somuchwin:
 

Rizkyw

Member
Joined
Nov 24, 2014
Messages
9
Reaction score
0
Nice Mod now i can win reaction test math more faster  :urtheman:
 

Broadcast

Active member
Joined
Feb 1, 2015
Messages
41
Reaction score
0
The Crash will happen once, not even more (with these requirements), so don't worry because of many mods/scripts you have inside of your CLEO folder.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
I did not release the code below because the usage of it could be nasty, spoiling the fun for players who actually solve the math riddles. Also there's no big value in the code itself which is messy. On the other side, saying very frankly I despise the samp community as a whole, I haven't seen a single server with moderate-high playerbase which would provide fair competitive gameplay, devs/admins spoil the game with great potential by allowing donations for in-game goods, as a result the one who pays the most real money "wins". Plus the fact that there's more cheaters than legit players. Anyway... the mod below solves math riddles automatically on some server (I forgot which one it was ;p)

Code:
{$CLEO}
{$INCLUDE SF}
0000:
repeat
wait 50
until 0AFA:  is_samp_available
0B34: samp register_client_command "activate" to_label @activate
0BE3: raknet setup_incoming_rpc_hook @on_new_chatline

//Settings:
11@ = 0 //delay

0AC8: 31@ = allocate_memory_size 64
0AC8: 30@ = allocate_memory_size 64
0AC8: 29@ = allocate_memory_size 64
0AC8: 28@ = allocate_memory_size 64
0AC8: 25@ = allocate_memory_size 124 //formula
0AC8: 26@ = allocate_memory_size 64 //result
0AC8: 22@ = allocate_memory_size 64 //answer
27@ = 0 //27@ = switcher
0AC8: 16@ = allocate_memory_size 260 //chatline with formul

 
while true
wait 0
    if and
    27@ == 1
    24@ == 1
    then
    24@ = 0
    //0AB1: @GETCHATENTRYTEXT 1 id 99 to 0@  
    samp.GetChatString(99, 16@, 0, 0, 0)
    //0AF8: samp add_message_to_chat 0@ color -1


        //
        //4 numbers
        //  
    
        if or
        //0AD4: $nefolosit = 0@ format "%d%c%d%c%d%c%d" 1@ 31@ 2@ 30@ 3@ 29@ 4@
        0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB88}»{FFFFFF}] Calculate '%d%c%d%c%d%c%d' and type /ans <answer> [Prize: $%d and %d score]" 1@ 31@ 2@ 30@ 3@ 29@ 4@ 9@ 10@
        0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB00}»{FFFFFF}] Calculate '%d%c%d%c%d%c%d' and type /ans <answer> [Prize: $%d and %d score]" 1@ 31@ 2@ 30@ 3@ 29@ 4@ 9@ 10@                            
        then
        0AD3: 31@ = format "%c" 31@
        0AD3: 30@ = format "%c" 30@
        0AD3: 29@ = format "%c" 29@
         
        0085: 5@ = 1@ // result
        0085: 6@ = 2@ // num2
        0085: 7@ = 3@ // num3
        0093: 1@ = integer 1@ to_float
        0093: 2@ = integer 2@ to_float
        0093: 3@ = integer 3@ to_float
        0093: 4@ = integer 4@ to_float
        0093: 5@ = integer 5@ to_float
        0093: 6@ = integer 6@ to_float
        0093: 7@ = integer 7@ to_float
            if 0AB1: @p_3 3 31@ 30@ 29@
            then
            0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
            0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
            0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@  
            else  
                if 0AB1: @n_2 2 30@ 29@
                then
                0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
                0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
                0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@
                else                
                    if 0AB1: @p_n 2 30@ 29@
                    then
                    0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@
                    0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
                    0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@
                    else
                        if 0AB1: @p_n 2 29@ 30@
                        then
                        0AB1: @do_maths 3 num 3@ num2 4@ operator 29@ _returnedNum 3@
                        0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
                        0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
                        else
                            if 0AB1: @p_2 2 30@ 29@
                            then
                            0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@
                            0AB1: @do_maths 3 num 2@ num2 4@ operator 29@ _returnedNum 2@
                            0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
                            else
                            0AF8: samp add_message_to_chat "Error: Unknown order of operations (the script is incorrect)" color -1            
                            end
                        end
                    end
                end
            end
         
        0AD3: 25@ = format "%.0f %s %.0f %s %.0f %s %.0f" 1@ 31@ 6@ 30@ 7@ 29@ 4@
            //if 0AB1: @decimal_check_result 1 5@
            //then    
            //0AD3: 26@ = format "%0.4f" 5@
            //else
            //0AD3: 26@ = format "%.0f" 5@
            //end  
        0092: 5@ = float 5@ to_integer
        0AD3: 22@ = format "/ans %d" 5@ 
        //wait 11@
        0AF9: samp say_msg 22@       
        else         
            //
            //3 numbers
            //
            if            
            0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB00}»{FFFFFF}] Calculate '%d%c%d%c%d' and type /ans <answer> [Prize: $%d and %d score]" 1@ 31@ 2@ 30@ 3@ 9@ 10@           
            then                   
            0AD3: 31@ = format "%c" 31@
            0AD3: 30@ = format "%c" 30@
            0085: 4@ = 1@ // result
            0085: 5@ = 2@ // num2
            0093: 1@ = integer 1@ to_float
            0093: 2@ = integer 2@ to_float
            0093: 3@ = integer 3@ to_float
            0093: 4@ = integer 4@ to_float
            0093: 5@ = integer 5@ to_float
            
            //0AD3: 25@ = format "Formula detected: %.0f %s %.0f %s %.0f" 1@ 31@ 5@ 30@ 3@
            //0AF8: samp add_message_to_chat 25@ -1
           
                if 0AB1: @p_2 2 31@ 30@
                then
                0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
                0AB1: @do_maths 3 num 4@ num2 3@ operator 30@ _returnedNum 4@
                else      
                    if
                    0AB1: @no_priority 1 30@ //no
                    then
                    
                   // 0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
                        
                        if 0C29: 15@ = string1 31@ string2 "+"  
                        then
                        005B: 4@ += 2@  // (float)
                        else
                            if 0C29: 15@ = strcmp string1 31@ string2 "-"
                            then
                            0063: 4@ -= 2@  // (float)
                            else
                                if or
                                0C29: 15@ = string1 31@ string2 "x"
                                0C29: 15@ = string1 31@ string2 "*"
                                then                  
                                006B: 4@ *= 2@  // (float)
                                else
                                    if 0C29: 15@ = string1 31@ string2 "/"
                                    then
                                    0073: 4@ /= 2@ // (float)
                                    end
                                end
                            end
                        end
                        
                        if 0C29: 15@ = string1 30@ string2 "+"  
                        then
                        005B: 4@ += 3@  // (float)
                        else
                            if 0C29: 15@ = strcmp string1 30@ string2 "-"
                            then
                            0063: 4@ -= 3@  // (float)
                            else
                                if or
                                0C29: 15@ = string1 30@ string2 "x"
                                0C29: 15@ = string1 30@ string2 "*"
                                then                  
                                006B: 4@ *= 3@  // (float)
                                else
                                    if 0C29: 15@ = string1 30@ string2 "/"
                                    then
                                    0073: 4@ /= 3@ // (float)
                                    end
                                end
                            end
                        end
                          
                    
                   // 0AB1: @do_maths 3 num 4@ num2 3@ operator 30@ _returnedNum 4@                     
                    
                    
                    
                    
                    else
                    0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@          
                    0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
                    end        
                end
               
            

                //if 0AB1: @decimal_check_result 1 4@
                //then    
                //0AD3: 26@ = format "%0.4f" 4@
                //else
                //0AD3: 26@ = format "%.0f" 4@
                //end  
                
            //0AD3: 25@ = format "Formula detected: %.0f %s %.0f %s %.0f" 1@ 31@ 5@ 30@ 3@
            //0AF8: samp add_message_to_chat 25@ -1
                
            0092: 4@ = float 4@ to_integer
            0AD3: 22@ = format "/ans %d" 4@ 
            wait 11@    
            0AF9: samp say_msg 22@  
            //0AF8: samp add_message_to_chat 22@ -1
            else
            //
            //2 numbers
            //
                if or
                0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB88}»{FFFFFF}] Calculate '%d%c%d' and type /ans <answer> [Prize: $%d and %d score]" 1@ 31@ 2@ 9@ 10@
                0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB00}»{FFFFFF}] Calculate '%d%c%d' and type /ans <answer> [Prize: $%d and %d score]" 1@ 31@ 2@ 9@ 10@
                then                           
                0AD3: 31@ = format "%c" 31@
                0085: 4@ = 1@ // result
                0093: 1@ = integer 1@ to_float
                0093: 2@ = integer 2@ to_float
                0093: 4@ = integer 4@ to_float
                0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
                 
                0AD3: 25@ = format "%.0f %s %.0f" 1@ 31@ 2@
                    //if 0AB1: @decimal_check_result 1 4@    
                    //then            
                    //0AD3: 26@ = format "%0.4f" 4@
                    //else
                    //0AD3: 26@ = format "%.0f" 4@
                    //end
                0092: 4@ = float 4@ to_integer
                0AD3: 22@ = format "/ans %d" 4@ 
                //wait 11@ 
                0AF9: samp say_msg 22@
                else
               // printf "Expected chatline is not the same as the servers' one" 5000
                end    
            end
        end
    end
end

 
:activate
0B12: 27@ = 27@ XOR 1
if 27@ == 1
then
0AD1: show_formatted_text_highpriority "activated" time 700 
else
0AD1: show_formatted_text_highpriority "deactivated" time 700
end
samp.CmdRet

:on_new_chatline
0BE5: raknet 23@ = get_hook_param PARAM_PACKETID
if 23@ == RPC_ScrClientMessage
then
24@ = 1
end
0BE0: raknet hook_ret true

:getChatEntryText
0AF7: samp 1@ = get_base
1@ += 0x212A6C
0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
1@ += 0x136
0@ *= 252 // size of stChatEntry
005A: 1@ += 0@ // (int)
1@ += 28
0AB2: 1 1@

 
//0AB1: @do_maths 3 num num2 operator _returnedNum
:do_maths
//0AF8: samp add_message_to_chat 2@ -1

if 0C29: 3@ = string1 2@ string2 "+"  
then
005B: 0@ += 1@  // (float)
else
    if 0C29: 3@ = strcmp string1 2@ string2 "-"
    then
    0063: 0@ -= 1@  // (float)
    else
        if or
        0C29: 3@ = string1 2@ string2 "x"
        0C29: 3@ = string1 2@ string2 "*"
        then                  
        006B: 0@ *= 1@  // (float)
        else
            if 0C29: 3@ = string1 2@ string2 "/"
            then
            0073: 0@ /= 1@ // (float)
            else
            0AF8: samp add_message_to_chat "Unrecognized uperator" -1
            0AF8: samp add_message_to_chat 2@ -1           
            end
        end
    end                    
end
0AB2: ret 1 0@
 
//if 0AB1: @ 1
:p_3
31@ = 0
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
31@++
end
 
if or
0C29: 15@ =  string1 1@ string2 "x"
0C29: 16@ =  string1 1@ string2 "*"
0C29: 17@ =  string1 1@ string2 "/"
then
31@++
end
 
if or
0C29: 15@ =  string1 2@ string2 "x"
0C29: 16@ =  string1 2@ string2 "*"
0C29: 17@ =  string1 2@ string2 "/"
then
31@++
end
 
if 31@ == 3
then
0485:  return_true
else
059A:  return_false
end
0AB2: ret 0
 
:p_2
//0AF8: samp add_message_to_chat 0@ -1
//0AF8: samp add_message_to_chat 1@ -1

31@ = 0
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
31@++
end
 
if or
0C29: 16@ =  string1 1@ string2 "x"
0C29: 17@ =  string1 1@ string2 "*"
0C29: 15@ =  string1 1@ string2 "/"
then
31@++
end
 
if 31@ == 2
then
0485:  return_true
else
059A:  return_false
end
0AB2: ret 0
 
 
:n_2
31@ = 0
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
31@++
end
 
if or
0C29: 15@ =  string1 1@ string2 "x"
0C29: 16@ =  string1 1@ string2 "*"
0C29: 17@ =  string1 1@ string2 "/"
then
31@++
end
 
if 31@ > 0
then
059A:  return_false
else
0485:  return_true
end
0AB2: ret 0
 
 
:p_n
31@ = 0
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
31@++
end
 
if or
0C29: 15@ =  string1 1@ string2 "x"
0C29: 16@ =  string1 1@ string2 "*"
0C29: 17@ =  string1 1@ string2 "/"
then
wait 0
else
31@++
end
 
if 31@ == 2
then
0485:  return_true
else
059A:  return_false
end
0AB2: ret 0
 
 
//if 0AB1: @is_priority 1
:priority
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
0485:  return_true
else
059A:  return_false
end
0AB2: ret 0
 
//if 0AB1: @not_priority 1
:no_priority
if or
0C29: 15@ =  string1 0@ string2 "x"
0C29: 16@ =  string1 0@ string2 "*"
0C29: 17@ =  string1 0@ string2 "/"
then
059A:  return_false
else
0485:  return_true
end
0AB2: ret 0
 
//if 0AB1: @decimal_check_result 1
:decimal_check_result
0092: 1@ = float 0@ to_integer
0093: 1@ = integer 1@ to_float
if or
0025:   1@ > 0@  // (float)
0025:   0@ > 1@  // (float)
then
0485:  return_true
else
059A:  return_false
end
0AB2: ret 0

Lines worth editing are:
-the ones that start with: 0AD4: 12@ = 16@ format "{FFFFFF}[{FFBB88}»{FFFFFF}] Calculate
-the ones that start with: 0AD3: 22@ = format "/ans %d"
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
If you leave the delay set to 0 and it automatically posts a correct answer within 0.15 sec then I may risk a statement that the vigilance of some players could be increased :p
 
Status
Not open for further replies.
Top