How to change movedef on the fly?

How to change movedef on the fly?

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

User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

How to change movedef on the fly?

Post 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.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: How to change movedef on the fly?

Post by Silentwings »

Did you Spring.MoveCtrl.Enable first?
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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,
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: How to change movedef on the fly?

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: How to change movedef on the fly?

Post by smoth »

Best suggestion was to do a morph in the past. Iirc there have been no recent advances
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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...
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: How to change movedef on the fly?

Post 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!
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: How to change movedef on the fly?

Post by smoth »

It is not complete and has been collecting dust for like a year. iirc it is in my svn
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: How to change movedef on the fly?

Post 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?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: How to change movedef on the fly?

Post 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"
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: How to change movedef on the fly?

Post by FLOZi »

Imo it makes no sense for enable to be required, as that assigns ScriptMoveType
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post by Jools »

Well, then I have no idea of what I'm doing wrong. Has anyone successfully used this callin?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: How to change movedef on the fly?

Post 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
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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.
Last edited by Jools on 20 Mar 2014, 21:43, edited 1 time in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: How to change movedef on the fly?

Post by FLOZi »

No, they have to be used, so, not the problem. Tried upper and lower case strings? Ought to be lowercase.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: How to change movedef on the fly?

Post by FLOZi »

I'm pretty great but I'm no Leonard Euler. 8)
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: How to change movedef on the fly?

Post by Jools »

Edited wiki to reflect discovery.
Post Reply

Return to “Game Development”