GTA SA Main.scm coding Tutorial / english


startup for newbies

add code to stripped main


add a script to originally main


    IV. adding a thread into originally main.scm

    Open the source text of decompiled main.scm, remember to orig-main.txt of startup lesson

    Add new threads at the end of the mainpart
    The MAINPART ends where the MISSIONPART beginns
    These are the last lines of MAINPART of originally main.scm

    :MOB_GF_3609
    00BE: text_clear_all
    0051: return

    End of MAINPART
    Here can you place your modscript which is mostly just a normal thread
    Below of the last thread of MAINPART
    Above of the first mission script

    The MISSIONPART beginns where the MAINPART ends, at:

    //-------------Mission 0---------------
    // Originally: Initial 1
    
    :INITIAL
    03A4: name_thread 'INITIAL'
    

    Add first the code to initialize the added thread
    search for the create_thread codes list in orig-main.txt

    create_thread @ODDVEH 
    .....
    ..
    create_thread @TRAINSL 
    create_thread @OPENUP 
    create_thread @TRI
    and add it at the end
    create_thread @ODDVEH  
    .....
    .. 
    create_thread @TRAINSL  
    create_thread @OPENUP 
    create_thread @TRI
    create_thread @DEMOTEXT

    Add the new thread at the end of the mainpart,
    in example below a script to show the text "OK" by keypress Firebutton

    :MOB_GF_3609
    00BE: text_clear_all 
    return 
    
    
    :DEMOTEXT
    03A4: name_thread "DEMO"
    wait 1000
    
    :DEMOTEXT_1
    wait 0
    if
    0256:   player $PLAYER_CHAR defined
    004D: jump_if_false @DEMOTEXT_1
    if
    00E1:   key_pressed  0  17//----------- Fire button
    004D: jump_if_false @DEMOTEXT_1
    00BA: text_styled 'FEM_OK'  1000 ms  1
    004E: end_thread
    
    //-------------Mission 0---------------
    // Originally: Initial 1
    
    :INITIAL
    thread 'INITIAL'
    

    Compile the script and look to the compiler report
    adding code in the MAINPART of main.scm increase the data size of MAIN size
    the MAIN size have a limit of 200 000bytes (if it's higher, your game will become crazy)

    The modified source script of originally main will be compiled to main.scm and script.img
    The Extern Scripts will be archived in script.img

    Important: It needs always to run main.scm and script.img of same compiling result

    Changing script.img needs to quit the game
    For testing is it possible to keep the script.img and update the main.scm without quitting the game, but if you test external scripts like Basketball or Dance, will the game crash

     

     


    next lesson >> V. Structure of main.scm