Register Calendar Latest Topics

  Author   Comment  

Posts: 30
Reply with quote  #1 
So I'm working on a sandbox and thought I should put the code I'm working on out there for other people to use in their missions and sandboxes. Feel free to use whatever you want, but I'd a little credit in the docs. These snippets could also be attached to the code snippit sections on the Wiki as well. These snippets could also be modified and tweaked to change their behavior if you know what your doing. Any improvements/optimization or refactoring is appreciated and I'm sure others could use that information as well. They are also heavily commented for ease of understanding (I hope).

None of this would be possible without serious help from other members on the forum like ryleyra and Mike Substelny.

Snippit #1: Random Civilian Neutrals (v1.0) (Artemis v2.5.101)


So I was looking at the stock GM script "Module_3_bases" and liked how they had the buttons to spawn transports. But the more I thought about it, you would not spawn a transport in the middle of no-where unless it jumped, your bound to see units flying into and out of your window in a (for the most part) straight pass just minding their own business. I also thought it would be cool to have a broader variety and randomized units, so I got started on it.

Before we get into the code I wanted to say that the lack of being able to resolve a variable into a name on the "create" command makes this script huge and bulky with a lot of very simmiler and redundant code. Redundant code is something I try to avoid, but it looks like it was unavoidable due to that limitation. Some other code is repeated just because it makes the order of execution a lot easier to follow and organizes events into more "full" stacks. The second thing I want to complain about while I was making this was realizing the difference between "angle" in the create command (in radians) and the "angle" in the brain stack (degrees). These differences are not widely documented and it took some time and help to solve.

Anyway, now that I'm done ranting, we can talk about what this does! This script randomly selects between a "Science" ship, "Cargo" ship, "Transport" ship and "Luxury" Ship. (It uses the Hull IDs to determine the ship) There is a cap on each ship of 4,6,6 and 3 respectively. Each time you click the GM button, it randomly selects one of the 4 available types,  and spawns it, if one of the types runs out (reaches maximum), it will then go into a loop generating another hullID that could be available untill it finds one. The script then picks what side of the screen it will spawn on and a random bearing to head towards. The bearings are limited so they are not so steep that if a ship spawns near the edge it just trails to the other side quickly. The script also keeps ships from spawning right next to the corners to avoid that from happening as well. After all 19 random ships are spawned, the GM button disappears. There is also a clear button that removes all the ships and resets the Random button and variables for you to repeat the process. Each spawned ship has its own name so it can be controlled from other events easily. Also when the unit reaches its destination, it will despawn automatically. Pretty nice deal.

It would not be hard to change the caps, add more units or different types of units, or even add a timer so they spawn every few minutes even. Lots of possibilities!

You will need to adapt the GM buttons to fit your environment but for the most part this should be plug-and-play.


Previous Topic | Next Topic

Quick Navigation: