Unit producing buildings, how do they work?

edited March 2015 in Questions

tl;dr: I'm trying to control a unit created by a building which was built in hammer.

I started working on my mod from scratch and now struggling with the problems I had half a year ago once again.

There is a solution that I don't like very much so I want to find a new method. For the sake of making mappers' jobs easy and understanding every little bit about the spawner code I want to abandon my old code.

I'm working on a mode which needs to have a single player in badguys team and rest in the goodguys team. Therefore, you can modify the code to work for any badguys player or specifically for the first player of badguys. This single player in badguys is called the master. The master will be able to spawn units(minions) from the buildings on the map and control them at will. I want community to be able to build maps for the mode so I want to keep their job as simple as possible.

Spawner Building

This little happy guy below will be the minion spawner and its unit.txt file

In hammer, there is "Entity Tool" which can create units and buildings, I want to use it. So, I pick either "npc_dota_base" or "npc_dota_building"

This is how "npc_dota_base" looks like. enter image description here

I'm making 2 changes on this:
1. Unit Name -> minion_spawner
2. Team Number -> DOTA_TEAM BADGUYS

After compilation, as you can see below. I can't use the skills of the spawner enter image description here This was expected, as I didn't set the owner anywhere. However, this would be the ideal way of placing these spawners for me as they require very little effort to set them up. Gotta think about mappers! :D

This is how "npc_dota_building" looks like. enter image description here enter image description here some unrelated options enter image description here enter image description here

I'm making 4 changes on this:
1. World Model -> models/props_gameplay/pumpkin_bucket.vmdl
2. Team Number -> Bad Guys
3. Player Owner -> Player 1
4. Unit Name -> minion_spawner

After compilation, I can spawn my minions with this building as you can see below. enter image description here But it allows mappers to change the model and requires 2 extra steps.
Also, I cannot control the minion created by the spawner as I'm not the owner of this newly created unit.
I would love to handle the building ownership process with lua or kv, just to keep the mappers job simpler.

Spawn Ability

At this part it starts to get more tricky for me.
The old method I was using had a separate entity on map located in front of the spawner and created units there.
Instead of that, I want to find a point in front of the spawner so I checked some of the ability library. I'm confident that I can handle the spawn position no matter if we use kv or lua to spawn the unit.
Back to the spawning, personally I prefer using "SpawnUnit" but I can't control ownership in there. I'm assuming that, I need to set the ownership from a hook to onNPCSpawned, but I don't want it to be called every single time even when another unit is created.
Therefore, we need to use "CreateUnitByName" in Lua by Runscript. This is also fine. Since I'm the owner of the building, I just have to get the owner of the building and set the unit's owner as myself and use SetControllableByPlayer on the unit. Then I thought, why don't I make this code more efficient if I'm using Lua and use a single function to spawn different kind of minions from different abilities. Somehow, I need to send the unit name from kv but I couldn't do that. Then I gave up and decided to have individual functions for each ability. But I failed at that, too.

Most of the modders here probably worked on building skills and had a similar problem. Future modders will have the same problem as well. Would you be kind enough to guide me through this? Every little bit helps!

Thank you,
Lemon

Help this tiny little fucker find his way to mama! enter image description here

Comments