WIP - Ferry Command - Page 2

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

Re: Request: Ferry Button

Post by Stealth870 »

:lol: Flozi, even a monkey could Lua better than me. I'm just trying to get the hang of this stuff.

Anyway, here's my code so far, I really would like some help on figuring out how to do the CommandCheck() function:

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    cmd_ferry.lua
--  brief:   Adds a command to create a ferry point with a transport.
--  author:  Brian "Mastastealth" Franco.
--
--  Copyright (C) 2007.
--  Licensed under the terms of the Creative Commons Attribution-Noncommercial 2.5 Colombia License.
-- In other words, do what you want and give me credit please. :P
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

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 CommandCheck()
  local transport = Spring.GetSelectedUnits()
  transport = transport[1]
  transportcommands = Spring.GetUnitCommands(transport)
  local SpeedX,SpeedY,SpeedZ = Spring.GetUnitVelocity(transport)
  
	while table.getn(transportcommands) < 1 and SpeedX > 0 or SpeedY > 0 or SpeedZ > 0 do
		
	return true
	end

	return true
  end
		
function FerryUnits()
  local transport = Spring.GetSelectedUnits()
  transport = transport[1]
  local CurrentX, CurrentY, CurrentZ = Spring.GetUnitPosition(transport)

  Spring.GiveOrderToUnit(transport,
  CMD.WAIT,{},{}
  );
  
  Spring.Echo("Set Unload Point. Use Shift to create waypoints, then hit W when you're done.");
  
  CommandCheck();
  
  --THE FOLLOWING WILL BE REPLACED to insert a repeat and load 
  --at the start of the command queue, replace the final move command
  --to an Unload Command, and add a move back to loading point
  --at the end!!
  
  -- Spring.GiveOrderArrayToUnitArray(Spring.GetSelectedUnits(),  
  -- {	--Start Command List
	-- {	--Let's repeat the following...
		-- CMD.INSERT,{-1,CMD.REPEAT,CMD.OPT_SHIFT,1},{"alt"}
	-- },
	-- {	--Load 'em up!
		-- CMD.INSERT,{-1,CMD.LOAD_UNITS,CMD.OPT_SHIFT,CurrentX,CurrentY,CurrentZ,200},{"alt"}
	-- },
	-- {	--Unload
		-- CMD.INSERT,{-1,CMD.UNLOAD_UNIT,CMD.OPT_SHIFT,CurrentX+800,CurrentY+100,CurrentZ+800},{"alt"}
	-- },
	-- {	--Move back to loading area
		-- CMD.INSERT,{-1,CMD.MOVE,CMD.OPT_SHIFT,CurrentX,CurrentY,CurrentZ},{"alt"}
	-- },
  -- }
  -- ); 
 
  return true
end
If you can't tell, what I'm trying to do is continue looping inside CommandCheck until 2 things happen. The command queue actually HAS something in it (move commands) and that the unit is moving (doing this by checking velocity). The second criteria would be a lot easier if I could just check directly if the unit is on Wait mode or not, but I can't find any Lua functions for that. Either way, how do I keep the FerryUnit function from continuing until the CommandCheck is fulfilled? I tried a while loop, and had it "do" "nil", but then the widget doesn't load, so I guess I'm doing something wrong.
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Re: Request: Ferry Button

Post by Warlord Zsinj »

For me, the best parts of the ferry system were:

- You could add extra transports to the transport route whenever you wanted very easily (in supcom you could just tell the transport to assist the ferry beacon)

- The beacon was a part of the gameworld, which meant you could easily see where the transport route was, and you could easily add and subtract units/factories from the ferry route

I hope both of these will be possible in what you're coding, stealth.

Having no actual ability to code in lua whatsoever, all I can say is good luck, I really hope to see this get done.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Beacon is definitely part of the plan. And I'm sure the transport assisting is possible, but whether I can code it or not is a different story. :lol: It should be possible to get a copy of the main transports command queue and route and give it to other transport so they all have the same ferry route, but all this mouse interaction stuff is what seems to have me stuck.
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Request: Ferry Button

Post by Gota »

Any progress?
UAF
Posts: 96
Joined: 02 Jan 2008, 19:25

Re: Request: Ferry Button

Post by UAF »

Consider me a supporter of the idea, I actually use ferry routes in games (With the repeat command method, and I draw a little circle in the loading area :-) ). So this will be useful for me (and others too probably)
User avatar
FrOzEnTaCo
Posts: 81
Joined: 02 Jul 2008, 05:52

Re: Request: Ferry Button

Post by FrOzEnTaCo »

AF wrote: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!

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

Re: Request: Ferry Button

Post by Stealth870 »

Well, I actually have improved quite a bit in my Lua knowledge after attempting this, though it was more focused on this L├âÔÇôVE game engine. However, I started college again and I never really have the will power to get to coding anything. :P I will probably get to it again once 0.77 is out, and I start playing Spring again. :roll:
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Request: Ferry Button

Post by Tribulexrenamed »

Gota wrote:Any progress?
u piss me off so much. Was going to post something like a ferry button I made, but posts like this just make it not worth sharing. If there is a way of sharing this widget with others without giving it to Gota, ill take it.
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Request: Ferry Button

Post by Gota »

ah..
What is it now?
this thread was dead on like the 3rd page.
I just asked cause i really need it and if someone is workign on it ill make plans accordingly.
Iv seen people rez posts 6 months old asking if anyone is doing work on it or has something half done.
WHAT IS YOUR PROBLEM?
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Anyway, decided to have a look at this once again.

EDIT: Scratch everything I said, I figured it out. I got a basic ferry widget working. I'm gonna try to make a button on the menu so you don't have to type in the command, and then release it. :D

Anyone got any pointers on how to add a simple button to the command list of a unit?
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Request: Ferry Button

Post by Gnomre »

AFAIK that requires a luarule gadget
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Request: Ferry Button

Post by lurker »

Not since some layout function modifications. Look at the retreat widget.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Request: Ferry Button

Post by Stealth870 »

Hmm...but the retreat widget depends on CA's GUI layout stuff right? There's no way to add a normal button via Spring options or anything. Guess I'll have to draw an external button or something.

Anyway I've attached what I have. Right now it's very simple:

Type /luaui ferry with transport selected (thought it does it with any unit, just don't be silly :P)
Hold shift and create the transport route
Hit W to release transport
Current position is used and loading zone, last waypoint converts to unload zone.

That's pretty much it for now. Next up is:
-Make a button
-Create a graphic on the map to show zones
-Make graphic clickable by other transports, to copy the routes and have multiple transports assist one route.
Attachments
cmd_ferry.lua
Ferry widget
(2.8 KiB) Downloaded 123 times
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

Re: WIP - Ferry Command

Post by dizekat »

I have made transport assist widget where you can set transport to guard unit, then transport will be helping that unit move around. It glitches however (because unloading is not always possible on the exact target location, and because there is very many special cases, a lot of commands may result in unit moving), so I didn't release it.
Post Reply

Return to “Lua Scripts”