Mod Question Repository... Questions come in, answers go out
Moderator: Moderators
Re: Mod Question Repository... Questions come in, answers go out
And the full script, errors like that can be because of syntax issues.
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Code: Select all
[ 2172] [string "LuaGadgets/Gadgets/unit_script.lua"]:316: bad argument #1 to 'co_create' (Lua function expected)
[ 2172] stack traceback:
[C]: in function 'co_create'
[string "LuaGadgets/Gadgets/unit_script.lua"]:316: in function 'StartThread'
[string "scripts/kufact1.lua"]:26: in function <[string "scripts/kufact1.lua"]:25>
[ 2872] [string "LuaGadgets/Gadgets/unit_script.lua"]:316: bad argument #1 to 'co_create' (Lua function expected)
[ 2872] stack traceback:
[C]: in function 'co_create'
[string "LuaGadgets/Gadgets/unit_script.lua"]:316: in function 'StartThread'
[string "scripts/kufact1.lua"]:49: in function <[string "scripts/kufact1.lua"]:48>
And here's the animation script:
Code: Select all
local ground = piece "ground"
local ldoor = piece "ldoor"
local rdoor = piece "rdoor"
local building = piece "building"
local nano = piece "nano"
local pad = piece "pad"
local SIG_OPEN = 1
local SIG_CLOSE = 2
function script.Create(unitID)
end
function script.QueryBuildInfo() return pad end
function script.QueryNanoPiece() return nano end
function script.Activate()
SetUnitValue(COB.YARD_OPEN, 1)
SetUnitValue(COB.INBUILDSTANCE, 1)
SetUnitValue(COB.BUGGER_OFF, 1)
return 1
end
function script.StartBuilding()
StartThread(build_open)
end
local function build_open()
SetSignalMask(SIG_OPEN)
Signal(SIG_CLOSE)
Move(building, y_axis, 40, 40)
Sleep(250)
Turn(ldoor, z_axis, 1, 40)
Turn(rdoor, z_axis, -1, 40)
WaitForMove(building, y_axis)
WaitForTurn(ldoor, z_axis)
WaitForTurn(rdoor, z_axis)
end
function script.Deactivate()
SetUnitValue(COB.YARD_OPEN, 0)
SetUnitValue(COB.INBUILDSTANCE, 0)
SetUnitValue(COB.BUGGER_OFF, 0)
return 0
end
function script.StopBuilding()
StartThread(build_close)
end
local function build_close()
SetSignalMask(SIG_CLOSE)
Signal(SIG_OPEN)
Move(building, y_axis, -40, 40)
Sleep(250)
Turn(ldoor, z_axis, -1, 40)
Turn(rdoor, z_axis, 1, 40)
WaitForMove(building, y_axis)
WaitForTurn(ldoor, z_axis)
WaitForTurn(rdoor, z_axis)
end
function script.Killed(recentDamage, maxHealth)
return 0
end
Re: Mod Question Repository... Questions come in, answers go out
Local functions must be declared before you use them!SanadaUjiosan wrote:Code: Select all
function script.StartBuilding() StartThread(build_open) end local function build_open() ... end
Code: Select all
function script.StopBuilding() StartThread(build_close) end local function build_close() ... end
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Oooooh... so it does matter which order these things are in. Something led me to believe that wasn't the case.
Re: Mod Question Repository... Questions come in, answers go out
Code: Select all
canreclaim = true,
reclaimspeed = 10,
I had it working before with the builder tag, but after i added some features (Fly,transport) it didn't show up anymore.
Do i need any script or additional tag for it to work?
Re: Mod Question Repository... Questions come in, answers go out
Unfortunately builder and transport are mutually exclusive in the engine.
Re: Mod Question Repository... Questions come in, answers go out
ugh
Any chance that this can be changed engine wise?
*Looks at google summer projects*
Edit: Also it still isn't able to reclaim after removing that transportation, but it started moving differently with strafing runs and loopings!
Any chance that this can be changed engine wise?
*Looks at google summer projects*

Edit: Also it still isn't able to reclaim after removing that transportation, but it started moving differently with strafing runs and loopings!
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
I've poked around a little bit looking at how transports work, but I think I'll just have to flat-out ask.
Have the lua commands for transporting units been changed? The wiki mentions that the "current" setup wasn't ideal and that it was subject to change. I ask because although I try the different approaches it lists, they all seem to do th e same in-game, which is lower to the ground and drop each unit one at a time.
Also, is there a way to hide the passenger? I noticed in BA the boat transport has a crane that puts the passenger in the hull. Does the passenger disappear, or is the hull just large enough to hide any unit it can pick up?
And lastly, is it possible to have multiple link points on the transport? Like units sticking to the transport in 2 parallel rows of points?
Have the lua commands for transporting units been changed? The wiki mentions that the "current" setup wasn't ideal and that it was subject to change. I ask because although I try the different approaches it lists, they all seem to do th e same in-game, which is lower to the ground and drop each unit one at a time.
Also, is there a way to hide the passenger? I noticed in BA the boat transport has a crane that puts the passenger in the hull. Does the passenger disappear, or is the hull just large enough to hide any unit it can pick up?
And lastly, is it possible to have multiple link points on the transport? Like units sticking to the transport in 2 parallel rows of points?
Re: Mod Question Repository... Questions come in, answers go out
I think ground transports and air transports differ in some way, ground transports can pick units up and hide them in the script while air transports have that hardcoded IIRC.
Re: Mod Question Repository... Questions come in, answers go out
Without looking, did you try the transportUnloadMethod unitDef tag?SanadaUjiosan wrote:I've poked around a little bit looking at how transports work, but I think I'll just have to flat-out ask.
Have the lua commands for transporting units been changed? The wiki mentions that the "current" setup wasn't ideal and that it was subject to change. I ask because although I try the different approaches it lists, they all seem to do th e same in-game, which is lower to the ground and drop each unit one at a time.
Units are hidden by AttachUnit to -1 instead of a valid pieceAlso, is there a way to hide the passenger? I noticed in BA the boat transport has a crane that puts the passenger in the hull. Does the passenger disappear, or is the hull just large enough to hide any unit it can pick up?
Yes, just make the empty points in the s3o and AttachUnit to each point in turn as a unit is loaded. SWIW air transports do this for example (and some S44 boats).And lastly, is it possible to have multiple link points on the transport? Like units sticking to the transport in 2 parallel rows of points?
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Ah, yep, that did it. Thanks for pointing that out.Without looking, did you try the transportUnloadMethod unitDef tag?
I've tinkered with this for a while and I haven't been able to figure out how to set it up. Whatever I do just gives me the same error message.Units are hidden by AttachUnit to -1 instead of a valid piece
Here is what the infolog says:
Code: Select all
[ 1025] [string "scripts/btransportcarrier.lua"]:26: attempt to call global 'AttachUnit' (a nil value)
[ 1025] stack traceback:
[string "scripts/btransportcarrier.lua"]:26: in function <[string "scripts/btransportcarrier.lua"]:25>
Code: Select all
local body = piece "body"
local door = piece "door"
local flare1 = piece "flare1"
local flare2 = piece "flare2"
local flare4 = piece "flare3"
local flare3 = piece "flare4"
local link = piece "link"
local link_false = -1
local SIG_AIM = 1
local SIG_AIM_SEC = 2
local SIG_AIM_THIR = 4
local SIG_AIM_FOUR = 8
function script.Create(unitID)
end
local function RestoreAfterDelay(unitID)
Sleep(2500)
Turn(body, y_axis, 0, math.rad(90))
end
local function hide_passenger()
AttachUnit (link_false, passengerID)
end
local function open_door()
Turn (door, x_axis, -0.5, 2)
Sleep(2500)
Turn (door, x_axis, 0, 5)
end
local function close_door()
Turn (door, x_axis, -0.5, 2)
Sleep(2500)
Turn (door, x_axis, 0, 5)
end
function script.QueryWeapon1() return flare1 end
function script.QueryWeapon2() return flare2 end
function script.QueryWeapon3() return flare3 end
function script.QueryWeapon4() return flare4 end
function script.AimFromWeapon1() return body end
function script.AimFromWeapon2() return body end
function script.AimFromWeapon3() return body end
function script.AimFromWeapon4() return body end
function script.AimWeapon1( heading, pitch )
Signal(SIG_AIM)
SetSignalMask(SIG_AIM)
Turn(body, y_axis, heading, math.rad(90))
Turn(body, x_axis, 0, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(body, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.AimWeapon2( heading, pitch )
Signal(SIG_AIM_SEC)
SetSignalMask(SIG_AIM_SEC)
Turn(body, y_axis, heading, math.rad(90))
Turn(body, x_axis, 0, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(body, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.AimWeapon3( heading, pitch )
Signal(SIG_AIM_THIR)
SetSignalMask(SIG_AIM_THIR)
Turn(body, y_axis, heading, math.rad(90))
Turn(body, x_axis, 0, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(body, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.AimWeapon4( heading, pitch )
Signal(SIG_AIM_FOUR)
SetSignalMask(SIG_AIM_FOUR)
Turn(body, y_axis, heading, math.rad(90))
Turn(body, x_axis, 0, math.rad(60))
WaitForTurn(body, y_axis)
WaitForTurn(body, x_axis)
StartThread(RestoreAfterDelay)
return true
end
function script.FireWeapon1()
Sleep(30)
end
function script.FireWeapon2()
Sleep(30)
end
function script.FireWeapon3()
Sleep(30)
end
function script.FireWeapon4()
Sleep(30)
end
function script.BeginTransport(passengerID)
StartThread(open_door)
StartThread(hide_passenger)
end
function script.QueryTransport(passengerID)
return link
end
function script.EndTransport(each)
StartThread(close_door)
end
function script.Killed(recentDamage, maxHealth)
return 0
end
Re: Mod Question Repository... Questions come in, answers go out
AttachUnit is not localised by default, so you have to call Spring.UnitScript.AttachUnit, or localise it in your script yourself
edit: looking at your script, is this an air or ground transport?
Code: Select all
local AttachUnit = Spring.UnitScript.AttachUnit
AttachUnit(-1, unitIDofTransportee)
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
It is an air transport. Why, is there something odd in it?
Re: Mod Question Repository... Questions come in, answers go out
No, I'm just not as familiar with the air transport functions. 

- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Well, defining the AttachUnit worked, or at least I think it did. Error has changed. Now it's saying bad UnitID. I tried different variations, but none seemed to work. I tried passengerID, unitID, passengerunitID, and I think another, but I don't remember what it was.FLOZi wrote:Code:
local AttachUnit = Spring.UnitScript.AttachUnit
AttachUnit(-1, unitIDofTransportee)
Re: Mod Question Repository... Questions come in, answers go out
That's because passengerID is local to BeginTransport. Either put the AttachUnit call at the end of the open_door function, and pass the passengerID to it, or, probably the better way;
Note that I'm calling the open_door function immediately rather than in it's own thread, that means that the open_door() will execute first before moving on to the AttachUnit call. Generally speaking, you should keep the number of Threads to a minimum, you only need to use them when functions have to run at the same time as others.
Code: Select all
function script.BeginTransport(passengerID)
open_door()
AttachUnit(-1, passengerID)
end
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Well, the error went away...
But, the passenger unit is not disappearing.
I stupidly tried using 0 and 1 instead of -1, but it didn't do anything.
But, the passenger unit is not disappearing.
I stupidly tried using 0 and 1 instead of -1, but it didn't do anything.
Re: Mod Question Repository... Questions come in, answers go out
As KDR mentioned, there are differences between gorund and air trans, probably it does not work for air trans, because what it actually does is place the unit at -1000 units in the y axis of the transport, which obviously might not work right for aircraftSanadaUjiosan wrote:Well, the error went away...
But, the passenger unit is not disappearing.
I stupidly tried using 0 and 1 instead of -1, but it didn't do anything.

What you can do, however, is use some more fanciful lua. Call Spring.SetUnitNoDraw(passengerID, true) when the unit is attached, and Spring.SetUnitNoDraw(passengerID, false) when the unit is dropped.
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Mod Question Repository... Questions come in, answers go out
Success!
Sort of... getting it to hide the passengers was easy, but to make them reappear was a hassle. I was trying to use the Unload Drop method, (1), but I couldn't find a way to get the passenger ID to work. So I went with the Unload Land Flood (2) and now it does what I want it to do. I'd prefer to use the cool drop from the air feature, but something is better than nothing.
Thanks a ton Flozi for your help and patience!
Sort of... getting it to hide the passengers was easy, but to make them reappear was a hassle. I was trying to use the Unload Drop method, (1), but I couldn't find a way to get the passenger ID to work. So I went with the Unload Land Flood (2) and now it does what I want it to do. I'd prefer to use the cool drop from the air feature, but something is better than nothing.
Thanks a ton Flozi for your help and patience!
Re: Mod Question Repository... Questions come in, answers go out
For some reason gnome bugged me on MSN instead of posting himself
gnomre says:
but still
he was having problems with the drop method and passenger ID
he just needs to cache and loop
unless it's transporting a billion units at a time it shouldn't be a very cpu consuming loop