IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
Forum Rules GTA Modification Forums

Please post mod releases in the Mod Showroom

GTAGarage.com
free mod hosting from GTANet, simply login with your GTAForums account details

GTAModding.com
GTANet's modding wiki

GTA Modding Chatroom
provided by irc.gtanet.com (Don't have an IRC client? Click here)


  Reply to this topicStart new topicStart Poll

 string ini

 
HeresOtis  
Posted: Friday, Apr 20 2012, 21:33
Quote Post


Mark Chump
Group Icon
Group: Members
Joined: Apr 29, 2011

XXXXX



Say if this is my .ini file:
CODE

[Vehicle]
Infernus
Sultan
Oceanic
Admiral

How do I store each of those vehicles in a string and then check if the player is driving one of those vehicles?
PM
  Top
 

 
Bad.boy!  
Posted: Friday, Apr 20 2012, 21:39
Quote Post


SA modder
Group Icon
Group: Members
Joined: Jun 20, 2010

nl.gif

XXXXX



You'd better use id numbers instead, because the game doesn't recognise "Infernus" or any other car as something.
About reading from ini, no idea.
PM
  Top
 

 
fastman92  
Posted: Friday, Apr 20 2012, 22:08
Quote Post


фастман92 | ف
Group Icon
Group: Members
Joined: Jul 28, 2009

pl.gif

XXXXX



@Bad.boy why not?
Just use the getModelIndexByName
http://gtag.gtagaming.com/forums/index.php...3572&#entry3572
Its little complex especially for beginers.
Users WebsitePMMSN
  Top
 

 
Deji  
Posted: Saturday, Apr 21 2012, 00:10
Quote Post


Coding like a Rockstar!
Group Icon
Group: Members
Joined: Dec 24, 2007

ja.gif

XXXXX



QUOTE (HeresOtis @ Friday, Apr 20 2012, 21:33)
Say if this is my .ini file:
CODE

[Vehicle]
Infernus
Sultan
Oceanic
Admiral

How do I store each of those vehicles in a string and then check if the player is driving one of those vehicles?

It depends how you code it. CLEO 4's ink opcodes work via the following formats:
CODE
[section]
valueName=value
Users WebsitePM
  Top
 

 
HeresOtis  
Posted: Saturday, Apr 21 2012, 00:23
Quote Post


Mark Chump
Group Icon
Group: Members
Joined: Apr 29, 2011

XXXXX



I just decided to use integers (the vehicle's ID). It works for me.
CODE
:isPlayerDrivingAppropriateVehicle
// if
//    0AB1: call_scm_func @isPlayerDrivingAppropriateVehicle 0
// then
if
   0AAB:  file_exists "CLEO\PoliceDB.ini"
then
   0AF0: 1@ = get_int_from_ini_file PoliceDB section "Vehicles" key "1"
   0AF0: 2@ = get_int_from_ini_file PoliceDB section "Vehicles" key "2"
   0AF0: 3@ = get_int_from_ini_file PoliceDB section "Vehicles" key "3"
   0AF0: 4@ = get_int_from_ini_file PoliceDB section "Vehicles" key "4"
   0AF0: 5@ = get_int_from_ini_file PoliceDB section "Vehicles" key "5"
   if or
       Actor.DrivingVehicleType($PLAYER_ACTOR, 1@)
       Actor.DrivingVehicleType($PLAYER_ACTOR, 2@)
       Actor.DrivingVehicleType($PLAYER_ACTOR, 3@)
       Actor.DrivingVehicleType($PLAYER_ACTOR, 4@)
       Actor.DrivingVehicleType($PLAYER_ACTOR, 5@)
   then
       0485: return_true
   else
       jump @DrivingPolice
   end
else
   :DrivingPolice
   if
       Actor.DrivingPoliceVehicle($PLAYER_ACTOR)
   then
       0485: return_true
   else    
       059A: return_false
   end
end
0AB2: ret 0
PM
  Top
 

 
Link2012  
Posted: Saturday, Apr 21 2012, 02:10
Quote Post


Wut?
Group Icon
Group: Members
Joined: Jan 30, 2011

ba.gif

XXXXX



I recommend you to check if player is in police vehicle, first, not later.
One condition will take less time than five conditions + ini reader.
PMMSN
  Top
 

 
Deji  
Posted: Saturday, Apr 21 2012, 02:52
Quote Post


Coding like a Rockstar!
Group Icon
Group: Members
Joined: Dec 24, 2007

ja.gif

XXXXX



And to optimise even further...

CODE
:isPlayerDrivingAppropriateVehicle
// if
//    0AB1: call_scm_func @isPlayerDrivingAppropriateVehicle 0
// then
if
   Actor.DrivingPoliceVehicle($PLAYER_ACTOR)
then
else
   if
      0AAB:   file_exists "CLEO\PoliceDB.ini"
   then
       0AF0: 1@ = get_int_from_ini_file PoliceDB section "Vehicles" key "1"
       0AF0: 2@ = get_int_from_ini_file PoliceDB section "Vehicles" key "2"
       0AF0: 3@ = get_int_from_ini_file PoliceDB section "Vehicles" key "3"
       0AF0: 4@ = get_int_from_ini_file PoliceDB section "Vehicles" key "4"
       0AF0: 5@ = get_int_from_ini_file PoliceDB section "Vehicles" key "5"
       if or
           Actor.DrivingVehicleType($PLAYER_ACTOR, 1@)
           Actor.DrivingVehicleType($PLAYER_ACTOR, 2@)
           Actor.DrivingVehicleType($PLAYER_ACTOR, 3@)
           Actor.DrivingVehicleType($PLAYER_ACTOR, 4@)
           Actor.DrivingVehicleType($PLAYER_ACTOR, 5@)
       then
       end
   end
end
0AB2: ret 0


0485 and 059A don't do anything but return true and false respectively. They may have been commands which used to actually perform a proper check, but were removed at some point and replaced to just return a default value. So while the name is valid, it can be misleading. A good way to show this:
CODE
// this statement is false
if and
   0485:   return_true
   059A:   return_false
then
end

// this statement is true
if or
   0485:   return_true
   859A:   not return_false
then
end


So they're just conditional commands which we use to forcefully set the condition result to make SCM Functions act like they can be used as conditions as a coding trick. Any other conditional command will also work, hence the reason the optimised code above works just as well.

It could be optimised more by using low-constructs (and thus, not having an empty "then" block). There's always a point, though, where a tiny bit of optimisation isn't worth making the code less neat.

This post has been edited by Deji on Saturday, Apr 21 2012, 02:54
Users WebsitePM
  Top
 

 
HeresOtis  
Posted: Saturday, Apr 21 2012, 03:45
Quote Post


Mark Chump
Group Icon
Group: Members
Joined: Apr 29, 2011

XXXXX



How can I use
CODE
0AF4: 0@v = read_string_from_ini_file "cleo\config.ini" section "SectionName" key "stringKey"
to get the next "stringKey" in the same SectionName?

And what's difference between 0@v and 0@s?

This post has been edited by HeresOtis on Saturday, Apr 21 2012, 03:47
PM
  Top
 

 
SilentPL  
Posted: Saturday, Apr 21 2012, 10:20
Quote Post


Senior File Manager
Group Icon
Group: Members
Joined: Feb 1, 2010

pl.gif

Member Award




0@v can handle up to 15 characters, and occupies 4 vars (in this case 0@, 1@, 2@ and 3@ are used). 0@s handles up to 7 chars and uses 2 variables (in this case, 0@ and 1@).

I think you can't make multiple keys with the same name in the same section though. At least, this opcode doesn't support that (manual file reading would handle it though).
Users WebsitePMMSNXbox Live
  Top
 

 
Wesser  
Posted: Saturday, Apr 21 2012, 10:33
Quote Post


The complexity simplifier, the efficiency optimizer
Group Icon
Group: Members
Joined: Aug 19, 2006

eu.gif

Member Award




To be more accurate, SCM string variables are respectively 8-byte and 16-byte long. They're usually one character less because of the null-terminator, which gives to the string a proper end as the next variable (or bytes) may be not null and so the string can be longer. tounge.gif
PMMSNPlayStation Network
  Top
 

 
HeresOtis  
Posted: Saturday, Apr 21 2012, 16:12
Quote Post


Mark Chump
Group Icon
Group: Members
Joined: Apr 29, 2011

XXXXX



Can I use the opcode above to read a random key in the .ini?
PM
  Top
 

 
HeresOtis  
Posted: Sunday, Apr 22 2012, 00:09
Quote Post


Mark Chump
Group Icon
Group: Members
Joined: Apr 29, 2011

XXXXX



What's the difference:
CODE
06D2: 5@v = "John Stockton" // @v = string   <--- This one uses ""
06D2: 5@v = 'John Stockton' // @v = string //  <--- This one uses ''
0AD0: show_formatted_text_lowpriority "Name: %s" time 2000 5@v

And if I use 5@v, can I use 6@ or 7@ to store the handle of a car or whatever I want to use those variables for?




PM
  Top
 

 
Link2012  
Posted: Sunday, Apr 22 2012, 00:30
Quote Post


Wut?
Group Icon
Group: Members
Joined: Jan 30, 2011

ba.gif

XXXXX



QUOTE
What's the difference:
CODE
06D2: 5@v = "John Stockton" // @v = string   <--- This one uses ""
06D2: 5@v = 'John Stockton' // @v = string //  <--- This one uses ''
0AD0: show_formatted_text_lowpriority "Name: %s" time 2000 5@v
 

The basic difference between " and ' is:
" can hold up to 128 chars, ' can hold up to 16 chars in San Andreas, and 8 chars in III/VC.
" only exists in SA

QUOTE
And if I use 5@v, can I use 6@ or 7@ to store the handle of a car or whatever I want to use those variables for?

If you do this, you will lose the string.
PMMSN
  Top
 

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG