Skip to content

8 Unit Object

dreamness edited this page Mar 26, 2025 · 1 revision
m_2 = Ra3Map.load_map('m_2')

# Get unit objects' info
for o in m_2.get_objects():
    print(
        # unit object's unique id
          o.unique_id, 
        # unit's type, such as SovietMCV, etc.
          o.type_name, 
        # belongs to team, such as Player_1/teamPlayer_1, etc.
          o.belong_to_team_full_name, 
        # unit's script name
          o.object_name,
          o.x, o.y, o.angle,
          initial_health,
          enable,
          indestructible,
          unsellable,
          powered,
          recruitable_ai,
          targetable,
          sleeping,
          stance,
          experience_level
         )
    
# Add and Alter a lot of unit objects
u_index = 0
for x in range(1000, 2000, 100):
    for y in range(1000, 2000, 100):
        o = m_2.add_object('JapanAntiVehicleVehicleTech3', x, y)
        o.object_name = 'object_' + str(u_index)
        o.stance = 'AGGRESSIVE'
        # o.angle = 10
        o.belong_to_team_full_name = 'Player_1/teamPlayer_1'
        # o.powered = True
        o.experience_level = 2
        # o.initial_health = 200
        o.sleeping = False
        # o.targetable = False
        # o.recruitable_ai = False
        # o.unsellable = True

        u_index += 1

# Delete a unit object via unique_id
m_2.remove_object(m_2.get_objects()[0].unique_id)

# Alter a unit object
m_2.get_objects()[10].initial_health = 300


m_2.save()

Clone this wiki locally