Smiths & Legends - Game Mechanics Mondays (18th Dec 2023)

Smiths & Legends

Smiths & Legends is a top-down co-op blacksmithing RPG. Craft recipes within the time limit with your friends while defending your shop from monsters. Go through the 60+ levels, fight monsters and bosses, and level up your party!

[i]Welcome to "Game Mechanic Mondays!" where we'll be covering in-depth how things were actually programmed in [b]Smiths & Legends[/b]! Unreal Engine operates a visual scripting language called Blueprints. This generates C++ for you, by letting you select stuff from drop-downs and linking them together in a process flow. There was also a [b]strange bug[/b] that took a little while to fix - skip to the bottom to see details on what it was! [/i] [b]Episode 1 - How does enemy spawning work?[/b] Today I'm going to explain how [b]Smiths & Legends[/b] spawns monsters infinitely in each level. [img]{STEAM_CLAN_IMAGE}/42414937/741efc545b3a57326974ba17a610f18d81a22844.png[/img] The first step runs an Event called Server_MainEnemySpawn. This runs only on the server because you want the server to be the one tracking variables rather than individual clients in multiplayer. You don't want each client spawning their own enemies or that might spawn way too many and [i]somebody[/i] ([i]or their computer[/i]) is gonna die! We start with two variables to keep track of how many enemies to spawn in each wave - "Enemy Count Current" and "Enemy Count Start". Current will be changing throughout the level, while Start is set somewhere else based on the number of players. To begin, we set Enemy Count Current to the same value as Enemy Count Start, and then go into a function called "Spawn Mushtump". [i]Mushtump is the name of the enemy, because they are tree stumps with a mustache.[/i] Inside the "Spawn Mushtump" function: [img]{STEAM_CLAN_IMAGE}/42414937/98ac801d164fe719a8d215b2f43f71157fc64a76.png[/img](click to zoom) We first check using a "Branch" that the value of "Enemy Count Current" is not zero. If it's not zero we go to "Switch on Int" and if it is zero we run an event called "Server Spawn Next Wave" (more on this later). [img]{STEAM_CLAN_IMAGE}/42414937/51fcd994e353dc28871d18fe0cd94e27e06d8950.png[/img](click to zoom) "Switch on int" is a function that does different things depending on which number goes in to "Selection". In our case we're choosing a random integer between 1 and "Enemy Count Current" - which is used to determine which level Mushtumps spawn, randomly each time. We then reduce the "Enemy Count Current" by the level of the Mushtump. Finally, we add a delay of 1.5 seconds for a gap between enemy spawns, and loop the whole thing back to the Branch to check if "Enemy Count Current" is zero. What might happen here for example - if there's 2 players, the value of Enemy Count Current is 2, so this system has a chance of spawning either two level 1 Mushtumps, or one Level 2 Mushtump. [i]Would you rather fight 1 giant Mushtump or 100 smaller Mushtumps?[/i] So what happens once it's spawned enough enemies? "Enemy Count Current" will be zero and the loop will identify this and run Server_NextEnemyWave: [img]{STEAM_CLAN_IMAGE}/42414937/db6e9a4cb617718646eae96a0117ebce537a3787.png[/img] This starts by running a function called "Increase Enemy Count": [img]{STEAM_CLAN_IMAGE}/42414937/ce4025142f53c5c8b91ec33030209c43e5341e46.png[/img] All this does is increase the "Enemy Count Start" by a set number called "Enemy Count Increase" and resets the "Enemy Count Current" to this value. This is also based on the number of players, so the enemy count increases faster with more players. [img]{STEAM_CLAN_IMAGE}/42414937/64610c9bbecf68f097fd0f2e4bce5b720e40b713.png[/img] Finally... After increasing the enemy count, we have a set "Enemy Wave Delay" then start spawning more Mushtumps. This loop continues infinitely - making each wave harder than the last... until the players complete the level or the shop is destroyed! [b]The bug[/b] After the wave looped a couple of times, the Mushtumps would stop spawning! Can any of you figure out what was the problem? Sound off in the discussion below or on social media! Don't forget to join the Discord channel! We'll post our fix next Monday! [url=https://discord.gg/MFD9rJE9C5]Discord[/url] [url=https://www.instagram.com/p/C05QJWbt0o3/]Instagram[/url] [url=https://twitter.com/AnsarincGames]Twitter/X[/url] [url=https://www.facebook.com/SmithsLegends]Facebook[/url] [img]{STEAM_CLAN_IMAGE}/42414937/c1ca97b1e7a11f1e6365f1598909bfca94b8a479.gif[/img]