Questions about mostly unitdefines help appreciated!

Questions about mostly unitdefines help appreciated!

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Tiberium
Posts: 18
Joined: 29 Jun 2012, 19:42

Questions about mostly unitdefines help appreciated!

Post by Tiberium »

Hi first want to say what an amazing game engine this spring is i only recently found out about this on the warzone 2100 project and played quite a few games and was impressed with the quality and complexity of the games made.

So if anyones got some free time could you help me with some questions about what can be done with this engine i assume a lot can be done with lua but ill ask anyway.

1. Can unit models be swapped in game but i dont mean an active unit lets say i have a factory and i build "TankBot" is it possible with lua to basically:
IF PlayerFaction=ARM then
ObjectName = "TankBota.s3o"
ELSE
ObjectName = "TankBotb.s3o"

So when built they have the correct model or is it best to just make doubles with different models.

2. Is it possible for random models? this cant be seperate unitdef for selection reasons.

3.In unit def what does the "side" tag actually do eg. Side = "Russia", as far as im aware even if im not the side if its added to a build menu i can still build it?

Thats all for now but after read that you prob deserve some cookies :P but any constructive replies will be a huge help even if speculation.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Questions about mostly unitdefines help appreciated!

Post by gajop »

Best if you ask what you want to do exactly. And honestly, as you seem to be lacking experience, it's best to avoid doing a grand project such as creating a game. For now you should toy with widgets/gadgets for your favorite game, or create some simple models.

Answers:
1) Question makes no sense, as you aren't capable of building some "abstract" unit def, you are building a concrete unit def which has a model. Not 100% sure on that, but unless you do a modification (see answer 2), you probably have only one model per unit def.

2) And what is this random model supposed to be? If you want to be able to change the model for a specific unit, you can check this thread: http://springrts.com/phpbb/viewtopic.php?f=23&t=28198, as it deals with technically modifiable models.

3) Sides aren't that important, and they probably don't restrict anything you can do with the engine. Don't concern yourself with them.
User avatar
Tiberium
Posts: 18
Joined: 29 Jun 2012, 19:42

Re: Questions about mostly unitdefines help appreciated!

Post by Tiberium »

Cheers for the advice gajob ill try and explain better

1)lets say im making a game and i have a tank its available for both factions but i want it to look different depending on what faction built it all other stats/weapons are the same is it possible to code in a way once the unit is built to check which art file it has to use first? from what your saying im guessing this cannot be dont with lua. I wanted other more practical uses like switching models to models textured in snow if the map is snowy for instance.

2) Thanks for that link and you are right i have absolutely no experience with lua but it seems easy enough to wing it im no noob to game creation or modelling. The random model isnt anything i just wanted to know if its possible before i begin making infantry dont want them to look the same.

3)Thanks mystery solved :-)
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Questions about mostly unitdefines help appreciated!

Post by knorke »

hi and welcome

1) Can not change the model tag of unitdefs at runtime.
But the 2-units-thing is very easy, in less than a dozen lines like you can remove a newly built unit and replace it with something else:

Code: Select all

function gaget:UnitCreated (...)
  if (some condition) then 
  Spring.DestroyUnit (originalUnit)
  Spring.CreateUnit (replacementUnit at same position)
end
switching models to models textured in snow if the map is snowy
Since you know before gamestart that the map will be snowy (unless you want dynamic weather but then this all gets very complex) you can swap the models before gamestart.
You can have a file gamedate\unitdefs_post.lua and that is run when the game is loading and in there you could have something like:

Code: Select all

for loop over all unitDefs do
  if (map is a snow map) then unitDef.model = "snow model"
end
2) Either see gajop's link but that is a very complicated and not yet finished way to do it. (basically forgett about it until more familiar with spring)
Very simple way is to have multiple pieces in the .s3o and randomly hide some via script.
eg

Code: Select all

--25% of tanks have no antenna:
if (math.random (0,100)<25) then Hide (antenna) end
3) it is not in here: http://springrts.com/wiki/Units-UnitDefs
:arrow: it does nothing.
side is a per-team thing only.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Questions about mostly unitdefines help appreciated!

Post by Pressure Line »

1)lets say im making a game and i have a tank its available for both factions but i want it to look different depending on what faction built it all other stats/weapons are the same is it possible to code in a way once the unit is built to check which art file it has to use first?
dont need to do anything special. just duplicate the model with different textures defined. and have the different faction's factories build the correct version.

eg in greenfactory.lua you have

Code: Select all

buildoptions =
	{
	"greentank"
	}
and in brownfactory.lua

Code: Select all

buildoptions =
	{
	"browntank"
	}
where browntank and greentank are just the same unitdef with different names and the model just has a different texture
from what your saying im guessing this cannot be done with lua.
quite the opposite in fact! texture swapping can only be done in lua
I wanted other more practical uses like switching models to models textured in snow if the map is snowy for instance.
this will need a lua script similar to the one posted in the thread linked before

edit:
knorke wrote:hi and welcome

1) Can not change the model tag of unitdefs at runtime.
But the 2-units-thing is very easy, in less than a dozen lines like you can remove a newly built unit and replace it with something else:

Code: Select all

function gaget:UnitCreated (...)
  if (some condition) then 
  Spring.DestroyUnit (originalUnit)
  Spring.CreateUnit (replacementUnit at same position)
end
you can't do Spring.CreateUnit in UnitCreated knorke
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Questions about mostly unitdefines help appreciated!

Post by knorke »

you can't do Spring.CreateUnit in UnitCreated knorke
ah right. it derps about recursion even if it is not evil endless recursion.
Was just to explain the basic idea.
It should work to have the script take note and create the unit one gameframe later.
User avatar
Tiberium
Posts: 18
Joined: 29 Jun 2012, 19:42

Re: Questions about mostly unitdefines help appreciated!

Post by Tiberium »

Thanks for the help & info ok this seems very possible now :-)

Pressure Line
the problem i was having was if the other teams factory was captured you could build units in their texture and not your own teams design. I'd hoped that the "side" tag would work so both tanks could be added to the factory and only the correct faction tank was buildable.

knorke
so from a code point of view the way is to let it spawn then kill it and respawn the correct version?

Im gonna have a mess around with this but great advice guys and thanks for pointing me in the right direction.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Questions about mostly unitdefines help appreciated!

Post by knorke »

removing buildoptions is not possible but you can hide/block the buildbuttons of factories (a bit more complicated because the buttons stuff is slightly stupid imo) which gives the same results.
you can also detect when a unit was captured and then do stuff.

really nothing what you wrote is impossible, just give it a try. :-)
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10454
Joined: 24 Jan 2006, 21:12

Re: Questions about mostly unitdefines help appreciated!

Post by PicassoCT »

knorke wrote:
you can't do Spring.CreateUnit in UnitCreated knorke
ah right. it derps about recursion even if it is not evil endless recursion.
Was just to explain the basic idea.
It should work to have the script take note and create the unit one gameframe later.
not entirely true. you are allowed spawning units, as long those aint factorys(with build entrys) or builders and dont call unit create themselves.

My decalfactory or buildanimation wouldnt work otherwise.


Ups: Forgot Disclaimer. Beeing Picasso, and everybody else here beeing longer and deeper into the Stuff, i might be wrong. Dont be mad if i am. Also dont invest to much time, following my advice. If some mod or dev is of other opinon, it is very likely to be more valid.
User avatar
Deadnight Warrior
Posts: 183
Joined: 08 Jun 2009, 17:59

Re: Questions about mostly unitdefines help appreciated!

Post by Deadnight Warrior »

knorke wrote:
switching models to models textured in snow if the map is snowy
Since you know before gamestart that the map will be snowy (unless you want dynamic weather but then this all gets very complex) you can swap the models before gamestart.
You can have a file gamedate\unitdefs_post.lua and that is run when the game is loading and in there you could have something like:

Code: Select all

for loop over all unitDefs do
  if (map is a snow map) then unitDef.model = "snow model"
end
Game.mapName and all other Game.xxx values are not available during the *_post stage, so you can't do that. Map options are, so if you're using a snow shader, which can be turned on/off, you might use that config param to determine weather conditions.
knorke wrote:removing buildoptions is not possible but you can hide/block the buildbuttons of factories (a bit more complicated because the buttons stuff is slightly stupid imo) which gives the same results
It's possible during the *_post stage, if you can find out what needs to be removed. Disabling buttons is not the proper solution as AIs don't use UI to give build orders and they can build disabled units/buildings. One can even make a widget that'll give direct build orders to a construction unit to build the disabled unit. Unit restrictions set in lobby are respected in any case.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Questions about mostly unitdefines help appreciated!

Post by Pressure Line »

you could just as easily destroy and re-create the factory if it gets captured so if a factionA player captures a factionB factory it is instantly destroyed and recreated as a factionA factory
Post Reply

Return to “Game Development”