Page 1 of 2

Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 02:03
by knorke
I want to add a unit to a map, like Speedballs does with the superfusion.
The unit works when included in a game.
So I move over all the files from the unit to the map like this:

RoadMap4.sdd\
Ôö£ÔöÇÔöÇÔöÇmaps
Ôöé RoadMap4.smd
Ôöé Roadmap4.smf
Ôöé Roadmap4.smt
Ôöé
Ôö£ÔöÇÔöÇÔöÇobjects3d
Ôöé Van_White.s3o
Ôöé
Ôö£ÔöÇÔöÇÔöÇscripts
Ôöé tpcivvehicle.lua
Ôöé
Ôö£ÔöÇÔöÇÔöÇunits
Ôöé whitevan.lua
Ôöé
ÔööÔöÇÔöÇÔöÇunittextures
Van.dds

But on trying to spawn it:
[f=0000128] /give whitevan
[f=0000128] Couldnt find wreckage info whitevan
[f=0000128] whitevan is not a valid unitname

There is no error in infolog but if you want to see youself: http://pastebin.com/nKg3c9AC

Re: Adding units to maps (unit does not get found)

Posted: 21 Sep 2011, 02:07
by jK
BA does not use lua scripts?
Neither for UnitDefs nor LUS.

Re: Adding units to maps (unit does not get found)

Posted: 21 Sep 2011, 02:14
by knorke
BA :roll:
but just found out it actually is something else in the unitDef:
MovementClass = "Vehicle2x2",
That movedef does not exist in other games and so does not work.

How can I add new moveDefs via the map?
Can they be declared in the unitdef file, like with weapons?

Just copying in a gamedata\movedefs.lua overwrites the mods's movdefs.lua and breaks all non-building/flying units.
I want the map to work with "all" mods so can not use "KBOT2" or something.

Also should I just put the unitscript.lua thing into the map or would that not be good?

will a unitdef_post.lua overwrite the file from the mod?
too late today to test, testing tomorrow.

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 18:06
by knorke
Also should I just put the unitscript.lua thing into the map or would that not be good?
ok, appearently having a
Map.sdd\LuaRules\Gadgets\unit_script.lua
in the map is no problem with mods that already have it.

Now with the movedef thing...?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 19:31
by Jools
It's not a problem, but I imagine it could be if you have two units with the same name but different functions.

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 19:35
by smoth
probably because unlike scripts, movedefs are integral to pathing.

Knorke, make a new config map_movedefs.. customize modefs_post to add your defs as well..

as far as dealing with conflicts:

KnorkTank2x2 = def
KnorkWaffle4x5 = def

etc

that should resolve the issue. if you have issues let me know, I already dick with movedefs in gundam and can write something up for you tonight(about 6-7 hours from now)

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 20:38
by knorke
Jools wrote:It's not a problem, but I imagine it could be if you have two units with the same name but different functions.
yes, that is why its good to prefixes on the names of stuff, will do for this too later. but problem here is def. the movementclass thing.
Knorke, make a new config map_movedefs
putting a map_movedefs.lua had no result - it might as well not be there.
.. customize modefs_post to add your defs as well..
i could do that but if i put a movedefs_post.lua in the game (or map, same result) it seems to be ignored?
I tried an empty file with just
Spring.Echo ("movedefs_post.lua from GAME!")
and it prints nothing to infolog.txt

For unitdefs_post.lua that works with Spring.Echo ("unitdefs_post.lua FROM GAME!")
Not sure if movedefs_post simply can not echo or if it is not found.
Annoying stuff is annoying.
I am off now but probally later in lobbychat

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 21 Sep 2011, 21:09
by smoth
I may have done some extra work to add a _post ;)

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 03:03
by jK
defs.lua fails in many ways currently. engine patches are welcome.

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 03:34
by smoth
>:D really...
so if someone did something like the goober who added subdirectory support for unitdefs... it would be accepted?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 03:53
by knorke
jK wrote:defs.lua fails in many ways currently. engine patches are welcome.
does that imply it is currently not possible?
or just that it needs stupid workarounds?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 13:52
by jK
there is no way to w/o breaking future compatiblity

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 17:34
by knorke
hm, i think if the map breaks with next engine version i will just make a v2.
Unless 0.83 is released tommorrow I think it is worth it.
So how would it be done?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 17:43
by jK
you need to override defs.lua, currently no game does so afaik, so no game related data is lost (atm).

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 17:56
by knorke
Did not find a defs.lua in any game i looked at so that might work.

Not sure how to edit defs.lua though.
It seems there needs to be something like
DEFS.moveDefs = LoadDefs('moveDefs')
DEFS.moveDefs = LoadDefs('moveDefs_map')

and somehow change LoadDefs to not override but add the loaded defs?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 18:50
by smoth
you don't need to.. to do what you need would take me 10 minutes. I looked at it this morning. but apparently a bigger change needs to happen so, I am waiting on JK to give me details on what he wants for the refactor. I will be working very very late today so I cannot look into it tonight.

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 22 Sep 2011, 21:53
by zwzsg
jK wrote:you need to override defs.lua, currently no game does so afaik, so no game related data is lost (atm).
I override defs.lua in all games I touch.

Mainly because I dislike having to split my "_post" .lua code between separate files for weapons, feature, weapons, and find it much more useful when, for units generated by code, the weapons and wrecks is generated along. Otherwise, I'd have to duplicate lots of code into three _post.lua files, and that'd be messy.

I use something like that: http://pastebin.com/asvGGZRM

That way anydefs_post.lua can contains code that modify all defs at once.

Except recently I added my special modoption to end all modopoptions, the one that let players rebalance anything from the battlerooms. And I felt it should be in a separate file cause it's mod agnostic, so defs.lua would need to look a bit like that: http://pastebin.com/zQS7WUi2

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 24 Sep 2011, 15:50
by smoth
[19:21:07] <smoth> is zwzsg's combined def what you wanted?
[19:22:13] <[LCC]jK> yup, he did 2 things I wanted
[19:22:29] <[LCC]jK> 1. he created the DEFS table before calling LoadDefs
[19:22:54] <[LCC]jK> 2. ye add that anydefs_post.lua (I would just name it defs_post.lua)
[19:23:06] <[LCC]jK> but 1. is bugged in his code
..
[19:23:25] <smoth> how should it work
[19:23:28] <[LCC]jK> he need to merge the results of LoadDefs
..
[19:24:01] <smoth> how should that be resolved?
..
[19:25:41] <[LCC]jK> so the code should look like this: table.merge(DEFS.unitDefs, LoadDefs('unitDefs'))
..
[19:26:04] <smoth> oh there is a table.merge?
[19:26:15] <smoth> I had no idea we had that
[19:26:40] <[LCC]jK> nah, but I wrote it like hundred times in my code ;)
[19:27:44] <[LCC]jK> function table:merge(table2)
[19:27:45] <[LCC]jK> for i,v in pairs(table2) do
[19:27:45] <[LCC]jK> if (type(v)=='table') then
[19:27:45] <[LCC]jK> local sv = type(self)
[19:27:45] <[LCC]jK> if (sv == 'table')or(sv == 'nil') then
[19:27:45] <[LCC]jK> if (sv == 'nil') then self = {} end
[19:27:45] <[LCC]jK> table.merge(self,v)
[19:27:45] <[LCC]jK> end
[19:27:45] <[LCC]jK> elseif (self == nil) then
[19:27:45] <[LCC]jK> self = v
[19:27:45] <[LCC]jK> end
[19:27:45] <[LCC]jK> end
[19:27:45] <[LCC]jK> end
..
[19:40:49] <[LCC]jK> problem with z's code is: issue #1 needs to get fixed (needs to use table.merge), 2nd needs better name than anydefs_post.lua (you won't be able to change that afterwards)
[19:41:00] <[LCC]jK> 3rd map needs to integrated
[19:41:22] <[LCC]jK> so z's code is like 20% of what needs to be done
[19:41:25] <smoth> mind if I copy paste these bits into the thread?
[19:41:31] <[LCC]jK> np
[19:41:40] <smoth> cool
..
[19:42:00] <[LCC]jK> in total the current code has these three issues:
[19:43:03] <[LCC]jK> 1. any _post.lua script should be able to create any type of defs (-> create DEFS table before calling LoadDefs & use table.merge)
[19:43:14] <[LCC]jK> 2. needs a new defs_post.lua
[19:43:23] <[LCC]jK> 3. needs map integration


so hey z, would it be trouble to make the 3 alterations?

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 24 Sep 2011, 16:50
by zwzsg
I don't really understand jK. He says 1. is bugged but I don't understand how. To be honest I barely understand what goes on in defs.lua. I just changed what seemed to be needed to be changed to let me have what I wanted, and I'm confident it somehow works, since I'm successfully using it to:
- Modify existing units and weapons
- Create new units and weapons

But of course, that it works doesn't mean it's perfect.

Re: Adding units to maps, unit does not get found cuz movedef

Posted: 24 Sep 2011, 19:08
by jK
you do

Code: Select all

DEFS.armorDefs   = LoadDefs('armorDefs')
that overrides anything in DEFS.armorDefs that was created in LoadDefs('unitDefs')