My Blog

Procedural Terrain Generation in GTA San Andreas

Recently, while searching for something I created long ago, I stumbled upon a lot of fond memories from a game I used to play frequently during my childhood. This game, Grand Theft Auto: San Andreas, specifically the unofficial multiplayer modification called San Andreas Multiplayer, played a significant role in how I learned to code in various languages and gained knowledge about linux, websites, certificates, servers, and more.

An impression photo of the rural areas in Grand Theft Auto: San Andreas. In multiplayer this was even more barren because the mod removed a lot of vegetation because they were not synced between players and could cause issues.

I spent much of my childhood playing this game, and I’d estimate that I dedicated over 10,000 hours to both coding for it and playing. Occasionally, I reminisce about the wonderful memories, the friends I made, the projects I worked on, and everything I learned during that time.

Although I loved the game, I always felt that the rural areas didn’t quite feel as rural as they could have. I wanted denser forests and more areas to explore. Moreover, after playing on the map for over ten years, I knew it inside out, leaving nothing new to discover.

One of my final projects was a roleplaying server, where players could create virtual characters and build a life within the game. They could join any organization, whether governmental, legal, or illegal, get jobs to earn money, buy houses, businesses, and vehicles, and even start virtual families or make friends.

I aimed to create a truly interactive world where players could collect unique materials, learn skills, and craft items. I drew inspiration from another game I enjoyed, 7 Days to Die, which had these features. This led me to think about implementing a procedural terrain generator.

The first challenge was dealing with the existing world, which already had trees, vegetation, rocks, and other elements. Fortunately, there was a function called RemoveBuildingForPlayer that allowed me to remove parts of the existing map. By setting the position to 0, 0, 0 and the range to 6000, I could remove an object from the entire map.

A generated bitmap with the colours representing the different biomes, some static, some dynamic. Each dot on this map is also an object placed in-game.

Then, I generated a layout of biomes across the map. Some biomes had to be hardcoded due to specific terrain conditions in the game, while others were procedurally generated using noise algorithms to add variation and realism. Based on this biome layout, I placed biome-specific objects in a grid pattern across the map. By the final stages, this system generated over 200,000 objects, creating forests, deserts, and other unique environments.

This volume of objects is quite impressive for such an old game, which was originally designed to handle only a few thousand additional objects at most. To circumvent this limit, I implemented a streamer—a system that only keeps nearby objects loaded in memory and dynamically unloads them when the player moves out of range. This allowed me to achieve the massive object count without overloading the game.

Although I never fully finished covering the map, I imagine that the object count would have reached a million if I had. Unfortunately, my limited experience with 3D modeling also presented a challenge. I managed to edit a single object in-game, but it wasn’t perfect. Creating custom models was out of my skill set at the time. If I could have added my own objects, rather than relying on the game’s default assets, it would have taken this project to an entirely new level of immersion.

Here are some of the photos and videos I have been able to dig up from this project:

Leave a Reply

Your email address will not be published. Required fields are marked *