WIP - Ferry Command

WIP - Ferry Command

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

WIP - Ferry Command

Post by Stealth870 »

EDIT: Download here.

I was looking but couldn't find a widget that already does this, though I'm sure it has been discussed before.

It should be possible to have it so that when you select a transport unit, a button appears to create a ferry point. Like in Supcom, when you hit the ferry button, you click on the map to create a destination.

So in Spring, I would suppose the LUA commands would go something like:

Code: Select all

If SelectedUnit = Transport:
Draw FerryButton

if FerryButton = "clicked":
Echo "Select Ferry Point"
coords = GetMapClickCoordinates()
DrawIcon(coords)

SetCommand("LOAD",radius_param)
DrawCircle(UnitPosition,radius_param)
SetCommand("REPEAT", 1)
or something like that. It would also be cool to have a way to capture Ctrl+Clicks, so that those clicks create move points, in case you want a more complicated ferry path, and it finishes with a normal click.
Last edited by Stealth870 on 26 Dec 2008, 18:14, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Request: Ferry Button

Post by aegis »

select the transport, turn on repeat.
click load, click and drag to select the area you want to ferry from
click unload, hold shift, then click and drag to select the area you want to ferry to
even with a widget, you would still need to specify all of these.

the transport will constantly ferry units from point A to point B

there is also a transport AI widget. it takes idle transports and makes them ferry units from nearby factories to the factory's destination
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Request: Ferry Button

Post by AF »

There are holes in that, such as transports missing movement points around enemy bases, overflying the enemy base and being blown up mid transit.

Or that setting the queue of commands up is extremely fiddly. You have to complete it before the first unit is picked up or the whole queue needs to be redone from scratch.

Then there's the fact that nobody knows the whole process can even be done until they're told, which is a rare occurance. And it takes so much time to set up properly, and if it needs modifying it has to be redone from scratch all over again =\

So please don't just dismiss this because you know of a hackish way of doing it with what we already have.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Request: Ferry Button

Post by aegis »

if you use W (wait), in the front and end of the queue, the transport won't pick up until all of the commands are issued :)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Request: Ferry Button

Post by AF »

Wouldn't it be so much easier if you had a single button called 'ferry' that did all this for you? Id rather click
  • ferry
than
  • wait
  • repeat on
  • area load command
  • move commands if theres a custom path
  • area unload command
  • a move command back to the original loading area (or the transport will not behave correctly after the first unit is loaded and unloaded)
  • turn wait off
Lets ban cakes because people can bake them if they have the right ingredients! There's no point in selling them, because theres already a way of making obtaining them involving flour and other stuff!
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

aegis wrote:select the transport, turn on repeat.
click load, click and drag to select the area you want to ferry from
click unload, hold shift, then click and drag to select the area you want to ferry to
even with a widget, you would still need to specify all of these.

the transport will constantly ferry units from point A to point B
That's the point, to cut out all the extra stuff at the end. In this case all you do is click the transporter, the button, and the destination. The widget is what sets a small radius and the repeat automatically. it's possible right?
aegis wrote:there is also a transport AI widget. it takes idle transports and makes them ferry units from nearby factories to the factory's destination
I would like more control. If I have a K-bot lab pumping out units that I want to send to the back of an enemies base, the transporter (with that widget) would just fly over the base instead of going around. Hence my last point of using Ctrl+Clicks for even more ferry path control. I think AF pretty much summed up the list of all the commands needed for the button. Should be simple right? If no one wants to do it, I'll try to.

(Someone should clean up that Lua wiki, make it nice with examples and stuff, that's why I asked here first because it looked a little too complicated. :P)
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Request: Ferry Button

Post by very_bad_soldier »

Stealth, i know its not the same, but do you know the Transportation Assist Lua? I use it nearly every game, its great. You set the rally point of your factory to some point and let transporters guard the factory, its quite easy. You can find it in this pack: http://spring.cn20070661.p-client.net/s ... hp?id=1017

EDIT:
Scratch it, you are talking about water arent you? :mrgreen:

@Matt:
Hm, indeed it is. Thanks.
Someone upped that Transport widget:
http://spring.cn20070661.p-client.net/s ... hp?id=1095
Last edited by very_bad_soldier on 19 Jun 2008, 22:06, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Request: Ferry Button

Post by aegis »

Stealth, you can assign waypoints to a factory... they should carry over to the transport assist.
User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Re: Request: Ferry Button

Post by LordMatt »

soldier ur link is messed up. I think it would be nice if someone wrote a gadget for the ferry button. It would be included in BA if made.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

All right, so I took a shot at this but I'm getting stuck. Here's what I have so far:

Code: Select all

function widget:GetInfo()
  return {
    name      = "Ferry",
    desc      = "Adds '/luaui ferry' to create a ferry point with a transport",
    author    = "mastastealth",
    date      = "Jun 16, 2008",
    license   = "Creative Commons",
    layer     = 0,
    enabled   = false  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:Initialize()
  widgetHandler:AddAction("ferry", FerryUnits)
end
        

function FerryUnits()
  print("Ferrying")
  local transport = Spring.GetSelectedUnits()
  transport = transport[1]
  local CurrentX, CurrentY, CurrentZ = Spring.GetUnitPosition(transport)

  Spring.GiveOrderArrayToUnitArray(Spring.GetSelectedUnits(),
  {	--Start Command List
	{	--First Wait
		CMD.WAIT, {},{}
	},
	{	--Then Load Units
		CMD.LOAD_UNITS, {CurrentX,CurrentY,CurrentZ,200},{}
	},
	{	--Then Unload Units
		CMD.UNLOAD_UNIT, {CurrentX+500,CurrentY+500,CurrentZ+500},{}
	},
	{	--Stop Waiting?
		CMD.WAIT, {},{}
	},
  }
  )
 
  return true
end
This is just to test it out, so right now its a manually written command with a preset Unload point. Problem is with the waiting. As suggested above I tried using a CMD.WAIT at the start and end of the order array, but when it's like that the Unload Command is kinda ruined. The transport flies over a unit, but just hovers there and holding shift shows me it was set to Wait mode, with the unload point ready. Without the waits it really doesnt do anything (I guess because it is told to unload before it even has anything loaded).
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Re: Request: Ferry Button

Post by ILMTitan »

Waits won't work because there is nothing that will auto-cancel them, like there is for ground units being unloaded.

What I believe you need to do is to turn on repeat by issuing CMD.REPEAT, (1), () at the start of the array.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Hmm. Ok, taking out the ending WAIT, and changing the first to REPEAT (with the 1 parameter) does the same thing. Holding shift I can see the unload spot given, but the transport just kinda moves over the unit, but never actually loads anything. I know the command by itself works.
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Request: Ferry Button

Post by Licho »

Similar feature is in CA, you can get widget from SVN repository svn://svn.caspring.org/

Here is description of basic features:
http://trac.caspring.org/wiki/FeatureTransportAi

Idle transports ferry units to waypoints of their factories and also there is "embark" and "disembark" command on units which calls transport for them.
User avatar
sillynanny
Posts: 125
Joined: 20 Jun 2008, 14:26

Re: Request: Ferry Button

Post by sillynanny »

Also the order must be LOAD-UNLOAD-MOVE, with the move order targetting some safe point like the load area. This will make idle transports wait at the move target, instead of waiting at the unload which is often hot.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Licho wrote:Similar feature is in CA, you can get widget from SVN repository svn://svn.caspring.org/

Here is description of basic features:
http://trac.caspring.org/wiki/FeatureTransportAi

Idle transports ferry units to waypoints of their factories and also there is "embark" and "disembark" command on units which calls transport for them.
Ah, I never knew what that dis/embarking stuff was. Ok, cool.

So at least there's already something about 95% capable of what I want, but can you guys please stop giving me alternatives now? Even if this widget already exists, don't tell me, and just help me learn some Lua. How 'bout it? :mrgreen:
sillynanny wrote:Also the order must be LOAD-UNLOAD-MOVE, with the move order targetting some safe point like the load area. This will make idle transports wait at the move target, instead of waiting at the unload which is often hot.
But after an unload a transport automatically moves back to the loading area, and will wait there if it doesn't find anything. I've tried this using the actual commands I'm trying to execute via Lua, which is:

Load (radius)
Unload
Repeat

It waits in the Load radius, not unload. My main problem is something seems to be getting rid of the loading command in Lua. Also, why doesn't wait work? If I press "W" in Spring, do the above 3 commands, and then press "W" again, it works fine. Why is it that executing it all via lua (CMD.WAIT, CMD.LOAD_UNITS, CMD.UNLAOD_UNIT, CMD.WAIT) doesn't? Is the command I'm using (GiveOrderArrayToUnitArray) not the right one? How do I add it to the "order queue"?
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Request: Ferry Button

Post by Tribulexrenamed »

Load
Move (waiting area)
Unload
Repeat
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Request: Ferry Button

Post by Gota »

Again.Why do you fight this?
a Ferry widget would be great.
Anodsupcoms ferry system is excellent IMO
its just right.Not too much micro but not too outomatede and out of control.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Ok, Sillynanny, my apologies, you were right. I finally figured out how to use the CMD.INSERT, which gives me the proper method of adding in the commands (as if I were clicking them with the Shift key) and I noticed that the transport did wait at the UNload point, so I have to add a move command to go back to the loading point.

So I have the very basics of a ferry widget done. It now loads a radius of 200, flies off 800 to the SE, then goes back and repeats. :P

So the next step is to have it ask me for the unload area, by allowing me to do the final command in the list. The mouse should turn into an Unload cursor, but behave different in that if I were to Shift+Click on the map, it would be intercepted as a move command instead of multiple unload points. Only the normal click will set the unload point, and the normal click should not delete any previous shift+clicks. Is that possible?

After that would be to create a nice button for it, and lastly (though optionally) a little code to draw some nice beacons at the loading and unloading areas. Yay!

EDIT: Now that I think about it, it would probably be easier to have it so when the command is issued (or eventually, the button is pressed) it tells you to set the Unload Zone, optionally creating waypoints along the way. The transport will be set to wait, then the mouse would be set to the Move command and you set all the points. As soon as you do a normal click, the widget will simply replace the last move command in the queue to an unload command.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Request: Ferry Button

Post by FLOZi »

/me suckles Stealth's lua teet.

We are always in need of more lua monkeys in S44, you know. :wink:
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Re: Request: Ferry Button

Post by ILMTitan »

My thought on that would be to have it ferry from the current location (or where ever it is when it gets to the ferry in the queue) to the location given by the command, not that I know a whole lot about how the lua interface works.
Post Reply

Return to “Lua Scripts”