Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

[SA] Declare an array?


EAZYJ
 Share

Recommended Posts

Hello guys,

 

Here's what I'm trying to do, but I'm not very familiar with arrays yet. I wanted to make various spawn locations where enemies would come out of randomly:

 

Quote

 

$ENEMY_SPAWN_X[1] = 2498.4067 
$ENEMY_SPAWN_Y[1] = -1642.39
$ENEMY_SPAWN_Z[1] = 15.8359
$ENEMY_SPAWN_A[1] = 175.0

 

$ENEMY_SPAWN_X[2] = 2513.626 
$ENEMY_SPAWN_Y[2] = -1650.3113
$ENEMY_SPAWN_Z[2] = 13.3557
$ENEMY_SPAWN_A[2] = 135.0

 

$ENEMY_SPAWN_X[3] = 2524.5352
$ENEMY_SPAWN_Y[3] = -1658.4711
$ENEMY_SPAWN_Z[3] = 14.4935
$ENEMY_SPAWN_A[3] = 90.0

 

etc...

 

 

I have made the script to make them spawn already, now how do I declare that as an array because I get this message from Sanny Builder whenever I compile:

Quote

"Variable $ENEMY_SPAWN_X is not declared as an array"

 

The error is at this line:

Quote

80C2:  not sphere_onscreen $ENEMY_SPAWN_X[[email protected]] $ENEMY_SPAWN_Y[[email protected]] $ENEMY_SPAWN_Z[[email protected]] radius 2.0

 


Thanks for any help.


 

Link to comment
Share on other sites

The format shown below is required when using variables in the array index. In this example 8 is the number of elements in the array, and f denotes a float. 

80C2:  not sphere_onscreen $ENEMY_SPAWN_X([email protected],8f) $ENEMY_SPAWN_Y([email protected],8f) $ENEMY_SPAWN_Z([email protected],8f) radius 2.0

 

If you do not allocate these global variables carefully a cleo script using these arrays will severely corrupt your global variables. The array elements will bypass the protection Sanny usually offers to critical named CustomVariables. 

 

Arrays are tough to code in cleo scripts. Main.scm "owns" all global variables, and the 32 local variables available to cleo scripts doesn't leave much room for arrays of any size. Can you code this as a custom mission?

 

Added: The usual solution to conserving variable usage in a situation like yours is to use the random number with a jumptable/switch case format to assign the values to only 4 variables as needed.

 

Note: Local variables can be assigned custom names using the CONST..END construct. Inventing custom global variable names is very likely to cause corruption to saved data.

Edited by OrionSR
Link to comment
Share on other sites

I'm sorry for the intrusion. 
We could create arrays in cleo differently (without the use of global variables). It's quite safe way and pretty much popular by now:

Spoiler
0AC6: [email protected] = label @coordArray pointer

while true
    wait 0
    0209: [email protected] = random_int_in_ranges 0 3 //  0, 1, 2
    [email protected] *= 4 //  X, Y, Z, A ---> 4 elements 
    [email protected] *= 4 //  float ---> size 4
    0085: [email protected] = [email protected]  //  coordArray
    005A: [email protected] += [email protected]
    [email protected] += 0
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    //  example
    if 0248:   model #MALE01 available
    then
        if 856D: NOT  actor [email protected] defined
        then
            009A: [email protected] = create_actor_pedtype 4 model #MALE01 at [email protected] [email protected] [email protected]
            0173: set_actor [email protected] Z_angle_to [email protected]
            01C2: remove_references_to_actor [email protected]
        end
    else
        0247: load_model #MALE01
        //  038B: load_requested_models
    end
end


:coordArray
hex
  82 26 1C 45     //    0x451C2682  //  2498.4067   //  $ENEMY_SPAWN_X[0]   0   
  7B 4C CD C4     //    0xC4CD4C7B  //  -1642.39    //  $ENEMY_SPAWN_Y[0]   1   
  D9 5F 7D 41     //    0x417D5FD9  //  15.8359     //  $ENEMY_SPAWN_Z[0]   2   
  00 00 2F 43     //    0x432F0000  //  175.0       //  $ENEMY_SPAWN_A[0]   3   
                                                                    
  04 1A 1D 45     //    0x451D1A04  //  2513.626    //  $ENEMY_SPAWN_X[1]   4   
  F6 49 CE C4     //    0xC4CE49F6  //  -1650.3113  //  $ENEMY_SPAWN_Y[1]   5   
  F2 B0 55 41     //    0x4155B0F2  //  13.3557     //  $ENEMY_SPAWN_Z[1]   6   
  00 00 07 43     //    0x43070000  //  135.0       //  $ENEMY_SPAWN_A[1]   7   
                                                                    
  90 C8 1D 45     //    0x451DC890  //  2524.5352   //  $ENEMY_SPAWN_X[2]   8   
  13 4F CF C4     //    0xC4CF4F13  //  -1658.4711  //  $ENEMY_SPAWN_Y[2]   9   
  60 E5 67 41     //    0x4167E560  //  14.4935     //  $ENEMY_SPAWN_Z[2]   10  
  00 00 B4 42     //    0x42B40000  //  90.0        //  $ENEMY_SPAWN_A[2]   11  
end

 

or with the direct input of float data into the hex block (same method with a slightly different approach):

Spoiler
0AC6: [email protected] = label @coordArray pointer

while true
    wait 0
    0085: [email protected] = [email protected]
    [email protected] += 0
    0A8C: write_memory [email protected] size 4 value 2498.4067 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value -1642.39 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 15.8359 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 175.0 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 2513.626 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value -1650.3113 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 13.3557 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 135.0 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 2524.5352 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value -1658.4711 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 14.4935 virtual_protect 0
    [email protected] += 4                                      
    0A8C: write_memory [email protected] size 4 value 90.0 virtual_protect 0
    
    
    0209: [email protected] = random_int_in_ranges 0 3 //  0, 1, 2
    [email protected] *= 4 //  X, Y, Z, A ---> 4 elements
    [email protected] *= 4 //  float ---> size 4         
    0085: [email protected] = [email protected]  //  coordArray
    005A: [email protected] += [email protected]
    [email protected] += 0
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    [email protected] += 4
    0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
    //  example:
    if 0248:   model #MALE01 available
    then
        if 856D: NOT  actor [email protected] defined
        then
            009A: [email protected] = create_actor_pedtype 4 model #MALE01 at [email protected] [email protected] [email protected]
            0173: set_actor [email protected] Z_angle_to [email protected]
            01C2: remove_references_to_actor [email protected]
        end
    else
        0247: load_model #MALE01
        //  038B: load_requested_models
    end
end


:coordArray
hex
    //  user inputed data
end

 

This way we could use arrays for storing any type of data including handles of peds, vehicles, objects... all kinds of possibilities.
... just a thought. 
 

Link to comment
Share on other sites

Thanks a lot for the detailed explanations guys! Although I don't really have a high level in coding to get a hold of all of it but I can see the points you're making. Now I should mention that I am scripting my mission on the main.scm and I don't think I'll be having any cleo using an array but it's always good to know.

 

So would it be safer to switch to local variables then? By the way, another question: can I use those variables for the actors as well?

 

Here's what I'm trying to achieve (this is sketchy but it's mostly to give you an idea)

Quote

:SPAWNING_ON
wait 0
if
$SPAWNING == 1
jf @SPAWNING_ADJUST     
if
not $TOTAL_ENEMIES > 10
jf @SPAWNING_ADJUST
0209: [email protected] = random_int_in_ranges 1 11
if
80C2:  not sphere_onscreen $ENEMY_SPAWN_X([email protected],11f) $ENEMY_SPAWN_Y([email protected],11f) $ENEMY_SPAWN_Z([email protected],11f) radius 2.0
jf @SPAWNING_ADJUST                    
      
$ENEMY([email protected],15i) = Actor.Create(Mission1, #SWAT, $ENEMY_SPAWN_X([email protected],11f), $ENEMY_SPAWN_Y([email protected],11f), $ENEMY_SPAWN_Z([email protected],11f))
Actor.Angle($ENEMY([email protected],15i)) = $ENEMY_SPAWN_A([email protected],11f)
05E2: AS_actor $ENEMY([email protected],15i) kill_actor $PLAYER_ACTOR
04C4: store_coords_to $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0603: AS_actor $ENEMY([email protected],15i) goto_point_any_means $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 mode 6 use_car -1

 

[email protected] += 1

$TOTAL_ENEMIES += 1
 


:SPAWNING_ADJUST
wait 0
if
Actor.Dead($ENEMY([email protected],15i))
jf @SPAWNING_ON
Actor.RemoveReferences($ENEMY([email protected],15i))
[email protected] += -1
$TOTAL_ENEMIES += -1  
jump @SPAWNING_ON

 

Link to comment
Share on other sites

1 hour ago, EAZYJ said:

Now I should mention that I am scripting my mission on the main.scm

Well, mentioning it a bit sooner would have saved you warning, but objections withdrawn. You own the globals in your custom main.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.