Quantcast

Jump to content

» «
Photo

string ini

12 replies to this topic
HeresOtis
  • HeresOtis

    The SCM Undergrad

  • Feroci Racing
  • Joined: 29 Apr 2011
  • United-States

#1

Posted 20 April 2012 - 09:33 PM

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?

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci Racing
  • Joined: 20 Jun 2010
  • None

#2

Posted 20 April 2012 - 09:39 PM

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.

fastman92
  • fastman92

    фастман92 | ف

  • Members
  • Joined: 28 Jul 2009
  • None

#3

Posted 20 April 2012 - 10:08 PM

@Bad.boy why not?
Just use the getModelIndexByName
http://gtag.gtagamin...3572
Its little complex especially for beginers.

Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#4

Posted 21 April 2012 - 12:10 AM

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

HeresOtis
  • HeresOtis

    The SCM Undergrad

  • Feroci Racing
  • Joined: 29 Apr 2011
  • United-States

#5

Posted 21 April 2012 - 12:23 AM

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

LINK/2012
  • LINK/2012

    LIVIN' IN CODE

  • Feroci Racing
  • Joined: 30 Jan 2011
  • Brazil

#6

Posted 21 April 2012 - 02:10 AM

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.

Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#7

Posted 21 April 2012 - 02:52 AM Edited by Deji, 21 April 2012 - 02:54 AM.

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.

HeresOtis
  • HeresOtis

    The SCM Undergrad

  • Feroci Racing
  • Joined: 29 Apr 2011
  • United-States

#8

Posted 21 April 2012 - 03:45 AM Edited by HeresOtis, 21 April 2012 - 03:47 AM.

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?

Silent
  • Silent

    Moderating Cookie Monster

  • Feroci Racing
  • Joined: 01 Feb 2010
  • Poland
  • Most Helpful [GTA] 2013
    Most Helpful [Modding] 2013
    Most Talented [Modding] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Best Vehicle 2013 "III Aircraft"
    Most Helpful [Modding] 2012
    Modder of the Year 2012

#9

Posted 21 April 2012 - 10:20 AM

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).

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci Racing
  • Joined: 19 Aug 2006
  • Unknown

#10

Posted 21 April 2012 - 10:33 AM

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

HeresOtis
  • HeresOtis

    The SCM Undergrad

  • Feroci Racing
  • Joined: 29 Apr 2011
  • United-States

#11

Posted 21 April 2012 - 04:12 PM

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

HeresOtis
  • HeresOtis

    The SCM Undergrad

  • Feroci Racing
  • Joined: 29 Apr 2011
  • United-States

#12

Posted 22 April 2012 - 12:09 AM

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?





LINK/2012
  • LINK/2012

    LIVIN' IN CODE

  • Feroci Racing
  • Joined: 30 Jan 2011
  • Brazil

#13

Posted 22 April 2012 - 12:30 AM

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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users