Activate & Deactivate with the same key

Hello,today i will explain how to activate and deactivate with the same key

this is our code:

Code:
{$CLEO}


0000: NOP                                 


:first //our label
wait 0
if and //our conditions
056D:   actor $PLAYER_ACTOR defined
0AB0:   key_pressed 49    // 1
0AB0:   key_pressed 50    /// 2                      
then
0B12: 0@ = 0@ XOR 1  // this will activate the cheat and deactivate if you pressed the keys again- explain below
if   //now to check if 0@ is equal to 1 (1 means activated, 0 means not activated)                       
0@ == 1  // we use to equal sign " == " when we check using "IF"
then
//here we put our codes that will run when  our script is active
actor.SetImmunities($PLAYER_ACTOR, 1 , 1 , 1 , 1 , 1)
0AD1: show_formatted_text_highpriority "GOD-MODE - ON" time 2000 0x0AD1
else //below this will run if we pressed the keys again (when it is not active)
if //we can add conditions too
056D:   actor $PLAYER_ACTOR defined // this is just to give you idea , no need to check if it is defined because we already did in the first place 
then
// here our codes will run when the script is not active
actor.SetImmunities($PLAYER_ACTOR, 0 , 0 , 0 , 0 , 0)
0AD1: show_formatted_text_highpriority "GOD-MODE - OFF" time 2000 0x0AD1
end // remember end comes from in to out ( first end will close last then in the script)
end
end
jump @first

Q/do i need to put "0@ = 0"  after "0000: NOP" ?
A/NO, no need , do not add 0@ = 0 after 0000: NOP

Q/do i need to put "0@ = 0"  at the end of the script (just before "jump @first")  ?
A/NO , no need , do not add 0@ = 0 at the end of the script ( before "jump @first")


now this is the magical code that will disable and enable with the same key/keys

Code:
0B12: 0@ = 0@ XOR 1
this means if we pressed 1+2 it will make 0@ = 1
but if we pressed 1+2 again it will make 0@ = 0

and after that we add our check :

Code:
if
0@ == 1 
then

this is a simple of XOR code:
Code:
:START
wait 0
if 
key_down 49 //1
then 0B12: 0@ = 0@ XOR 1 
if  
0@ == 1  
then
//do stuff here

end
end
jump @START

above we make the code
Code:
then 0B12: 0@ = 0@ XOR 1
it is the same as
Code:
then 
0B12: 0@ = 0@ XOR 1
there is no difference


that's it , this is how you activate/deactivate with the same key



thanks for following my tutorials.
if i helped you please hit the thanks button and the little heart(rep.) under my name so you can make me more trusted for users so they can reach me easily.
 

NoJustNo

Active member
Joined
Jul 26, 2014
Messages
178
Reaction score
0
Re: 11) activate & Deactivate with the same key -TUT

Was Looking for this!!!  :yesyes:
 

@WZ

Active member
Joined
Aug 3, 2014
Messages
25
Reaction score
1
Re: 11) activate & Deactivate with the same key -TUT

gj  :iknowwhatyoudid:
 
Top