I'm writing a game based quite heavily on Starcraft. I'm beginning with resource gathering scripts and while they're nowhere near finished I thought I'd upload them along with a few questions.
So far workers can be set to gather resources (gaia units). They will walk back and forth between the resource and the nearest hq ("mining" at the resource for a short while) giving the player resources.
The whole host of stuff that still needs doing includes only one worker mining a resource at a time, causing damage to the resources as they're mined (and making them immune to other damage), having workers mine nearby resources if their assigned resource is being mined and a whole host of other things. Also the code needs cleaning up, I haven't done any of the defining locals for performance and this is my first time with lua (I really hate the if then end syntax).
Notice that it needs some config in the form of resource, worker and hq lists, there are some sample values in there. If you can't get the workers to mine/return try increasing the radius it's taken from the center of the object (something which needs fixing) and if the model is too big they can't reach it.
As for my questions:
Is there an explicit way to make a unit invulnerable, or should I just look into armour?
Originally I used features instead of gaia units for resources. I wrote a little script that converts some features to gaia units to make things easier for me. I can't help thinking it doesn't really make too much difference but...
How often is FallbackCommand called? Should I use something called more often like Update?
Of course any other comments are appreciated.
Gatherable resources
Moderator: Moderators
Gatherable resources
- Attachments
-
- gathering.lua
- resource gathering
- (3.44 KiB) Downloaded 31 times
Re: Gatherable resources
Welcome to Spring!
Armor can make a unit invulnerable.
Armor can make a unit invulnerable.
Re: Gatherable resources
Hi and welcome!
Did not test your gadget but from looking at it, it seems good.
I made resource harvesting a while ago as well: http://springrts.com/phpbb/viewtopic.php?f=63&t=24238 (thread with some blabla and video. forum has some more threads on it i think)
It is now in conflict terra (with nicer graphics then in the video
)
code can be found here:
http://code.google.com/p/conflictterra/ ... mining.lua
That was basically my first Lua and so it turned out a bit messy.
Did not help that CT guys did not really know what they wanted but still wanted it now
Anyway, it works by given the miners a weapon with which they shot (="mine") the minerals, which are neutral gaiea units.
It basically does miner.cargo=miner.cargo+damage
units are set up in a way that the mining weapon can only damage rocks and rocks can only be damaged by miners.
unitdef tags to look up:
category
badtargetcagetory
unitchasecategory
damage classes
If I was to remake it, I would do some things different:
-custom commands instead of using "attack" (like you do)
-support for different resource types & dropoffs: ie wood must be brought to the sawmill, iron must be brought to smelter etc, ore truck can only transport ore but not wood etc.
Noticed you do:
workers[unitID]["loaded"]=true
so loaded is boolean. In my version I have it as number so miners can pause and then resume work etc. (but depends on game of course)
With http://answers.springlobby.info/questio ... munication gadgets and unit scripts can talk to each other, as you can think that is kinda usefull.
ie in my game (not CT, something else) I use this to hide/how a mineral in the claw of the mining vehicle.
If you have the minerals consist of multiple pieces and hide more pieces as the mineral gets mined, that also gives a nice effect.
Also the UnitDamaged can return a new value to overwrite the recieved damage.
ie
if blabla then return 0 --unit is invulnerable
(that also works for the unit script callin HitByWeapon)
ok, that was pretty much just a random rant but hopefully you can find some usefull pieces in it.
Did not test your gadget but from looking at it, it seems good.
I made resource harvesting a while ago as well: http://springrts.com/phpbb/viewtopic.php?f=63&t=24238 (thread with some blabla and video. forum has some more threads on it i think)
It is now in conflict terra (with nicer graphics then in the video

code can be found here:
http://code.google.com/p/conflictterra/ ... mining.lua
That was basically my first Lua and so it turned out a bit messy.
Did not help that CT guys did not really know what they wanted but still wanted it now

Anyway, it works by given the miners a weapon with which they shot (="mine") the minerals, which are neutral gaiea units.
It basically does miner.cargo=miner.cargo+damage
units are set up in a way that the mining weapon can only damage rocks and rocks can only be damaged by miners.
unitdef tags to look up:
category
badtargetcagetory
unitchasecategory
damage classes
If I was to remake it, I would do some things different:
-custom commands instead of using "attack" (like you do)
-support for different resource types & dropoffs: ie wood must be brought to the sawmill, iron must be brought to smelter etc, ore truck can only transport ore but not wood etc.
Noticed you do:
workers[unitID]["loaded"]=true
so loaded is boolean. In my version I have it as number so miners can pause and then resume work etc. (but depends on game of course)
With http://answers.springlobby.info/questio ... munication gadgets and unit scripts can talk to each other, as you can think that is kinda usefull.
ie in my game (not CT, something else) I use this to hide/how a mineral in the claw of the mining vehicle.
If you have the minerals consist of multiple pieces and hide more pieces as the mineral gets mined, that also gives a nice effect.
armour and weapon damage category can be used, yes.Is there an explicit way to make a unit invulnerable, or should I just look into armour?
Also the UnitDamaged can return a new value to overwrite the recieved damage.
ie
if blabla then return 0 --unit is invulnerable
(that also works for the unit script callin HitByWeapon)
Script in as a phyton or batch script? Because you can do it with Spring Lua as well, in unitdef_post.lua and featuredef_post.lua you can manipulate/create unitdef data.I wrote a little script that converts some features to gaia units to make things easier for me.
ok, that was pretty much just a random rant but hopefully you can find some usefull pieces in it.
Re: Gatherable resources
Better to use gadget:UnitPreDamaged imo so that the damage is never applied. Knorke covered pretty much everything else I would say, though I haven't looked at the code yet. Feel free to come pester me / other people on #lua and #moddev on the lobby, or by PM if I'm not around.Also the UnitDamaged can return a new value to overwrite the recieved damage.
Have you been reading my mind knorke? I am obsessing over a Settlers-type game for Spring.ie wood must be brought to the sawmill, iron must be brought to smelter etc,

Re: Gatherable resources
Thanks for the advice.
I'm planning on changing the loaded to a list of the types and amounts each worker is carrying, I'm also thinking of a custom resource system to allow for more than 2 types of resources.
The little script is a lua script, it doesn't mess with definitions, it just finds all of a certain feature type on the map, removes them and puts a unit in their place. I only really made it as I had a test map scattered with features.
Is there a way to modify default commands (i.e. make workers gather with just a right click)? I remember seeing something in the spring source and I didn't notice a lua call of any sort. I'll have to take a proper look.
I'm planning on changing the loaded to a list of the types and amounts each worker is carrying, I'm also thinking of a custom resource system to allow for more than 2 types of resources.
The little script is a lua script, it doesn't mess with definitions, it just finds all of a certain feature type on the map, removes them and puts a unit in their place. I only really made it as I had a test map scattered with features.
Is there a way to modify default commands (i.e. make workers gather with just a right click)? I remember seeing something in the spring source and I didn't notice a lua call of any sort. I'll have to take a proper look.
Re: Gatherable resources
Widgets can set default commands, S44 uses a widget by kdr_11k to do just that:
http://spring1944.svn.sourceforge.net/v ... iew=markup
http://spring1944.svn.sourceforge.net/v ... iew=markup