0ADA

From GTAMods Wiki
Jump to navigation Jump to search

GTA III Vice City San Andreas (with CLEO)


Description
Reads formatted text from the file
Syntax
0ADA: [var] = scan_file [file] format "[string]" ( [any] ... )
Parameter
[file]
The handle of the file
[string]
Formatted text specifying how to read the file (see fscanf for explanation)
[var]
Variable to store the number of data assigned
[any]
Variables to assign the data (any data type)

This CLEO opcode reads formatted text from the file and assigns the data to variables. In Sanny Builder it is important that you disable case converting in order for the opcode to work as expected. In "Options..." under the "Formats" tab in the "Case converting" box, select "As is". Additional calls to this opcode while the same file is still opened starts the reading at the position where it last left off rather than the beginning.

Example

The following example reads an XYZ coordinate point from a file. Upon success, press button 17 (ATTACK key) to teleport to the point.

const
FILE_HANDLE = 0@
X_POS = 1@
Y_POS = 2@
Z_POS = 3@
NUM_SCANNED = 4@
end

if
    0AAB:   file_exists "input"
then
    0A9A: FILE_HANDLE = openfile "input" mode 0x72  // r
    0ADA: NUM_SCANNED = scan_file FILE_HANDLE format "%f %f %f" X_POS Y_POS Z_POS
    0A9B: closefile FILE_HANDLE
    if
        NUM_SCANNED == 3
    then
        while true
            wait 10
            if
                00E1:   player 0 pressed_button 17  // attack key
            then
                while 00E1:   player 0 pressed_button 17  // attack key
                    wait 0
                end
                0055: put_player $PLAYER_CHAR at X_POS Y_POS Z_POS
            end
        end
    end
end

The input file contains the following line:

10.0 20.0 30.0

Keywords

read, scan, file, format