Tuesday, April 07, 2015

Arma 3, Loot Spawn System

So the loot spawn system is what I initially worked on, due to curiosity more than anything to find out how loot spawns and how difficult it is to correctly calculate in world positions.


Loot spawn script
I then expanded upon that script whilst learning the Arma 3 code structure, etc and created my own custom loot spawn system (small preview of the code above).

Basically what my initiation system does is this...

It gathers ALL buildings on any given map within a radius from a center point (currently set for 6000m on the map Stratis). It then damages buildings and opens doors on buildings based on probability, so each and every game is random. You will no longer be able to know if someone is or has been in the area based on doors being closed! That's right... not every door opens.

It then reevaluates the buildings and gathers all possible available building positions (green circle markers), as well as calculates a number of random building positions outside of the building model (red circle markers), as well as gathers manually placed building positions (set by myself in another config file, yellow circle markers). This structure is static and dynamic at the same time, which makes for a more random outcome for possible loot positions.

The colored building markers are to show which buildings have default loot positions available (green), and those that don't (red). The other building colors of khaki green (with default loot positions) and black (without default loot positions) tell me that those are damaged buildings.

Possible loot spawn positions
(red = random outside, green = default inside, yellow = custom inside)
Once all the building positions on the map are calculated and acquired from the default config as well as a custom config, it then initiates the actual loot spawn and makes calculations based on map size, playable area and item/weapon probability.

Loot spawn positions vs actual spawned loot
The loot table is fully customizable and easily configurable to add in new items/weapons or increase/decrease probability of loot spawning in each possible position. The debug markers in the above screenshot show what spawned where, the quantity and how high the item is above the terrain/floor level.

Look Ma, no floating loot!
As you can see in the above screenshot, loot will spawn at ground level each and every time, no matter what building the loot is around or inside. Scripting calculations FTW!

I am in the process of also adding custom buildings/towns to the map Stratis, so that loot spawn points are not concentrated on the air field, marinas or camps. There will be town(s) in the south of the map, north of the map and east of the map... to keep things more in balance (similar to what the wasteland mission has), as well as "beefing up" the existing places.

I will post a proper video demonstration of the debug markers and actual in-game "loot mongering" to show everything in action.

I have tested this script over and over again, rid all the scripting errors, optimized the code structure, and am quite pleased with the outcome.

I am also able to easily swap the loot spawn system to any map I decide to throw at it with very little manual configuration... (map size and probability) and it will run flawlessly. I've tested the script on the maps, Stratis, Wake Island, Gorgona and a few others... every time... flawless.

I hope that gives some insight on the loot spawn system in which I have been working on for the last few weeks.

Dynamic coding/scripting FTW!

-soul.