Use .ini to customize your script PART 2

Hello,This is the second part of .INI file making and using

first part> http://ugbase.eu/tutorials/13)use-ini-to-customize-your-script-part1-tut/

THIS PART ABOUT USING THE .INI IN CLEO SCRIPT


so here is our simple script:

Code:
{$CLEO}


0000: NOP


:main
wait 0
if and
056D:   actor $PLAYER_ACTOR defined
0AB0:   key_pressed 49 //1
0AB0:   key_pressed 50 //2
jf @main
0AD1: show_formatted_text_highpriority "You pressed key 1and 2" time 2000 0x0AD1
jump @main

now if we pressed key 1 and kay 2 we will display the massage saying "You pressed key 1 and 2"

BUT , we need to to change the key from time to time , and this is very damn hard , every one want his own key , and by .ini you give the people the chance to custom their version of your script , and this is useful in crypted scripts also


so now we need to read from .ini file and then do something with it , and we do it like this:


first this is our .ini check:

Code:
:INI  //OUR CHECK LABEL
wait 0
if
0AAB:   file_exists "CLEO\config.ini" // this will check if config.ini is in cleo folder
jf [member=45274]ini[/member] // if not then it will jump to ":INI" to loop again
0AF0: 1@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key1"   //1 
0AF0: 2@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key2"   //2    
jump @main //THE MAIN LABEL SCRIPT


now :
Code:
if
0AAB:   file_exists "CLEO\config.ini" // this will check if config.ini is in cleo folder
jf [member=45274]ini[/member] // if not then it will jump to ":INI" to loop again

with "IF" we check (condition statement)

and this where the file in "cleo" folder , we can change it as we want (we can change it's place , and it's name):
Code:
0AAB:   file_exists "CLEO\config.ini"[/color][/b]

BUT notice that we used " \ " instead of " / " , don't forget !
"CLEO\config.ini" means .INI folder in folder CLEO in your GTA folder

after this we add "jf [member=45274]ini[/member]" so if the folder is not exist we jump to ".INI" again until the file is found

NOW after this we add:
Code:
0AF0: 1@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key1"   //1 
0AF0: 2@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key2"   //2   

so now GTA will go to config.ini in CLEO folder in GTA folder , and go to section "ON" then look for the key "key1" and look what it is equal to , then it will get back to the script and continue the flow of the script by "jump @main"


now our .ini file must look like this :

Code:
; this is comment since it starts with semicolon ;
[ON]
key1=49
key2=50


so now key1 is equal to key 1(49) 
and key2 is equal key 2(50) 


and now key1 is registered as variable 1@ so we can use it in the script.
and key2 is registered as variable 2@ so we can use it in the script.

and now we can use these variables as key numbers
like so:

Code:
{$CLEO}

0000: NOP

:INI  
wait 0
if
0AAB:   file_exists "CLEO\config.ini" // this will check if config.ini is in cleo folder
jf [member=5120]Error[/member]// if not then it will jump to error label just to give you a warn that the folder is not exist
0AF0: 1@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key1"   //1 
0AF0: 2@ = get_int_from_ini_file "CLEO\config.ini" section "ON" key "key2"   //2    
jump @main //THE MAIN LABEL SCRIPT

:main //our main loop
wait 0
if and
056D:   actor $PLAYER_ACTOR defined
0AB0:   key_pressed 1@ //this means key 1
0AB0:   key_pressed 2@  //this means key 2
jf @main
0AD1: show_formatted_text_highpriority "You pressed key 1 and 2" time 2000 0x0AD1
jump [member=45274]ini[/member] //now this will jump again to :INI so it will loop and read keys after and after 
// i don't think we need to jump again at INI but it is better this way



:error  //this will give you a massage to warn you if config.ini is not in the folder you defined(cleo/config.ini)
 wait 0
 0AD1: show_formatted_text_highpriority "config.ini NOT FOUND IN YOUR CLEO FOLDER" time 2000 0x0AD1
jump [member=45274]ini[/member]

this is how .INI works , please ask me anything you didn't understand so i can explain more if i'm online , if not then there is many pro users can help you in the same moment if they are online .




integers: 1 , 2 , 3 , -21 , -5 , 124 ...etc
float: 1.0 , 2.3 , 3.75 , -21.02 , -5.146 , 124.9 ...etc
strings: this is string , word , letter , nigger , lol ..etc

strings are letters/words contain even numbers , but you have to know every sentence contain letter it is a string


PS: keys are integers

so now to get integer we use this opcode:
Code:
0AF0: 0@ = get_int_from_ini_file "cleo\config.ini" section "SectionName" key "intKey"

and for float we use this opcode:
Code:
0AF2: 0@ = get_float_from_ini_file "cleo\config.ini" section "SectionName" key "floatKey"

and for string we use this opcode:
Code:
0AF4: 0@v = read_string_from_ini_file "cleo\config.ini" section "SectionName" key "stringKey"


PS: and the "v" followed by a variable sign (@) is a string tag
so strings variables followed by V





[glow=green,2,300]TOTAL THANKS TO THE FOLLOWING MEMBERS:
[member=60]Opcode.eXe[/member]  -- what can i say bro , you are just crystal
[member=6677]TH3RM4L[/member] -- thank you very much dude  :)
they helped me to fix my issue in .ini  :)
[/glow]


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.
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: 14)Use ini to customize your script PART2- TUT

~quick update added to explain how to get strings/floats/integers and a bit more explanations for it
 
Top