Page 1 of 2

How to change movedef on the fly?

Posted: 19 Mar 2014, 21:52
by Jools
I want to change the pelican movedef to be a kbot when iut's on land, and hover when it has transformed to move on water. I made the relevant lua callin from the unit script, and now I only need to find out how to actually chnage the movedef. I found the following callin:
Spring.MoveCtrl.SetMoveDef
( number unitID, number moveDefID | string moveDefName ) -> boolean success
But it doesn't work. The success variable returns false and no movedef is changed. I tried to use both the number moveDefID and string moveDefName as arguments. Anybody knows what I'm doing wrong?

There is no lua error or similar in infolog, it just doesn't work.

Re: How to change movedef on the fly?

Posted: 19 Mar 2014, 22:32
by Silentwings
Did you Spring.MoveCtrl.Enable first?

Re: How to change movedef on the fly?

Posted: 19 Mar 2014, 23:28
by Jools
I tried that too, here's the function:

Code: Select all

function PelicanTransform(unitID,unitDefID,teamID)
		local success1 = Spring.MoveCtrl.Enable(unitID)
		local success = Spring.MoveCtrl.SetMoveDef(unitID,16)
		local success2 = Spring.MoveCtrl.Disable(unitID)
		Echo("Pelican transformed:",success,success1,success2,Spring.MoveCtrl.GetTag(unitID))	
end
I just get "Pelican transformed: false, nil, nil". It still doesn't work.

16 is the hover2 movedef in xta:
[16] = {
name = "HOVER2",
footprintX = 2,
footprintZ = 2,
maxSlope = 21.0,
slopeMod = (enableSlopeMods and EngineDefaultSlopeMod(21.0)) or 0.0,
crushStrength = 10.0,

Re: How to change movedef on the fly?

Posted: 19 Mar 2014, 23:47
by Silentwings
Idk then, maybe don't do it all on the same frame. I don't know if the effects of move control would even last after you disable it.

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 16:04
by smoth
Best suggestion was to do a morph in the past. Iirc there have been no recent advances

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 16:49
by Jools
Yeah, that would work. Does morphing change the unitID and does it technically kill the unit first, thereby increasing kill count? The morph gadget is such a large piece of code...

But I thought there had been advances with this new function that could set movedata/movedefs on the fly...

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 17:18
by smoth
Morph gadget is old code was writing my own more modern version and it is much smaller so far thanks to all the new stuff

Also the kill counter would obviously need to be revised oh wait you guys are relying on the in engine one lol glhf!

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 17:30
by Jools
smoth wrote:Morph gadget is old code was writing my own more modern version and it is much smaller so far thanks to all the new stuff
Share and enjoy?
smoth wrote: Also the kill counter would obviously need to be revised oh wait you guys are relying on the in engine one lol glhf!
Depends on who you mean by "you guys". XTA has own alternative counter that filters out incomplete units or units that have no attackerteam*, so I guess it would filter out morphed deaths. But most people regard the engine provided stats as those that have the best fidelity.

*actually it doesn't filter out, but put these in an own category.

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 17:43
by smoth
It is not complete and has been collecting dust for like a year. iirc it is in my svn

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 17:46
by FLOZi
smoth wrote:Best suggestion was to do a morph in the past. Iirc there have been no recent advances
94.0:

- add MoveCtrl.SetMoveDef(number unitID, number moveDefID | string moveDefName) --> boolean

95.0:

- fix possible bug in MoveCtrl.SetMoveDef

Did you try using the moveDefName string instead of a number, Jools?

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 17:50
by smoth
There were recent advances! Woot

Can it do tank to hover/boat because i think he really wants to Chang the unit "type"

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 18:06
by Jools
Yes, I tried with string also, same thing. Maybe the enable needs to be set when unit is created and not in same frame as Silentwings wrote. But doesn't that prevent the user from controlling unit?

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 18:08
by FLOZi
Imo it makes no sense for enable to be required, as that assigns ScriptMoveType

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:28
by Jools
Well, then I have no idea of what I'm doing wrong. Has anyone successfully used this callin?

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:35
by FLOZi
Jools wrote:Well, then I have no idea of what I'm doing wrong. Has anyone successfully used this callin?
Does any other unit use the movedef you are trying to switch to?

https://github.com/spring/spring/blob/d ... l.cpp#L744

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:41
by Jools
Yes, it's a common movedef. The movedef used when pelican reforms into a kbot is KBOTSF2, it's used also by Fido, Maverick and The Can. The one used when pelican transforms into a hover is also used by Arm Skimmer and Core Scrubber (hovercraft scouts), and also some xtaids units.

They have to be unique? I thought the whole point with having movedefs in a table in gamedata was to reuse them for many units.

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:43
by FLOZi
No, they have to be used, so, not the problem. Tried upper and lower case strings? Ought to be lowercase.

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:46
by Jools
Hey, it works when I put the string in lowercase! You da man!

I just used the same case as it was defined in movedefs table first, which is uppercase. In fact, a lot of TA era stuff is in upper case. I guess linux wants stuff in lowercase.

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 21:48
by FLOZi
I'm pretty great but I'm no Leonard Euler. 8)

Re: How to change movedef on the fly?

Posted: 20 Mar 2014, 22:07
by Jools
Edited wiki to reflect discovery.