need some help

need some help

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

Moderator: Moderators

Post Reply
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

need some help

Post by Hoi »

ok so im making a mod, starting with lua, what i need to do is let waves of units spawn like every 5 mins(sometimes 10, whatever) they need to follow a path round the map and the player needs to stop them, if they make it to the final waypoint, the player will lose lives, it would be great if they move in formation, the commands that i need and can find are:


Spring.CreateUnit

Spring.SetUnitMoveGoal or Spring.GiveOrderToUnit or CMD.PATROL or
the command listed here http://spring.clan-sy.com/wiki/Lua_PathFinder ??

Spring.SetUnitPosition?


please respond and correct/ suggest what you think or know i miss
User avatar
quantum
Posts: 590
Joined: 19 Sep 2006, 22:48

Re: need some help

Post by quantum »

I'd use Spring.GiveOrderToUnit and CMD.MOVE. You could use MoveCtrl to keep units in formation with a leader.
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

quantum wrote:I'd use Spring.GiveOrderToUnit and CMD.MOVE. You could use MoveCtrl to keep units in formation with a leader.
using what command(s)? and how can i let the player lose lives when the units reach the final waypoint?
Last edited by Hoi on 23 Jun 2008, 10:21, edited 1 time in total.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: need some help

Post by jK »

there is a callin:

UnitCmdDone(unitID, unitDefID, unitTeam, cmdID, cmdTag)
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

for formations i could use
Spring.GetUnitsInRectangle

( number xmin, number zmin, number xmax, number zmax [,number teamID] )
-> nil | unitTable = { [1] = number unitID, etc... }

Spring.GetUnitsInBox

( number xmin, number ymin, number zmin,
number xmax, number ymax, number zmax [,number teamID] )
-> nil | unitTable = { [1] = number unitID, etc... }

Spring.GetUnitsInSphere

( number x, number y, number z, number radius [,number teamID] )
-> nil | unitTable = { [1] = number unitID, etc... }

Spring.GetUnitsInCylinder

( number x, number z, number radius [,number teamID] )
-> nil | unitTable = { [1] = number unitID, etc... }

?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: need some help

Post by KDR_11k »

If you still have that many questions I'd suggest getting the Lua reference and the wiki and writing a few simple gadgets to get used to it and worry about making tower defence later.
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

KDR_11k wrote:If you still have that many questions I'd suggest getting the Lua reference and the wiki and writing a few simple gadgets to get used to it and worry about making tower defence later.
ive done the basic lua tutorials but i havnt made something yet so ill try to make somthing first, and im not really making tower defence
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

ok, so atm this is my luafail:

Code: Select all

function gadget:GetInfo()
  return {
    name      = "The spawner",
    desc      = "Spawns stuff",
    author    = "Hoi",
    date      = "30-6-2008",
    license   = "none",
    layer     = 0, 
    enabled   = true  --  loaded by default?
  }
end

-------------------------
if (gadgetHandler:IsSyncedCode()) then

local function Spring.CreateUnit("corcom",0, 0, 0, "s",16)
end
ofc, it doesnt work, can anyone tell me why?
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: need some help

Post by Stealth870 »

I think you need to put it in a "function widget:Initialize()"
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: need some help

Post by FLOZi »

Hoi wrote:ok, so atm this is my luafail:

Code: Select all

function gadget:GetInfo()
  return {
    name      = "The spawner",
    desc      = "Spawns stuff",
    author    = "Hoi",
    date      = "30-6-2008",
    license   = "none",
    layer     = 0, 
    enabled   = true  --  loaded by default?
  }
end

-------------------------
if (gadgetHandler:IsSyncedCode()) then

local function Spring.CreateUnit("corcom",0, 0, 0, "s",16)
end
ofc, it doesnt work, can anyone tell me why?
lern2program, kthxbai.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: need some help

Post by Argh »

@Hoi:

Basically, it's like this. All functions in Lua must be closed- they have a start and an end.

In Spring, the special Sync loop for Gadget code is still considered a function, and must be ended.

Moreover, you cannot use Spring.CreateUnit(), which is a call-out (a special line of code that communicates to Spring directly, telling the game engine to do something useful) as a function. It's calling a function within Spring, but Lua needs to have instructions about when and under what conditions to call it.

Here, let's look at doing this on the first game frame, via the GameFrame Call-in(a Call-In is a function that is run either every sync frame, for sync code, as fast as possible, if unsynced).

I'm not going to get into how to do this via fancier methods, this is just to get you a little more familiar with basic concepts here:

Code: Select all

function gadget:GetInfo()
  return {
    name      = "The spawner",
    desc      = "Spawns stuff",
    author    = "Hoi",
    date      = "30-6-2008",
    license   = "none",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

-------------------------
if (gadgetHandler:IsSyncedCode()) then ------ SYNCED CODE HERE

	function gadget:GameFrame(f)
		if f == 1 then
			Spring.CreateUnit("corcom", 0, 0, 0, "s", 16)
	
		end
	end

else  ---- END SYNCED CODE HERE
end ---- END THE GADGET HERE
That code should spawn a corcom at 0,0,0 in the worldspace, facing South, and assigned to Team 16, on Frame 1 of sync time.

Obviously, if you wanted this to be assigned to a specific player's Team, you'd have to use a different method.

As you can see, I've added quite a few things to this code. Firstly, I've added the correct Call-In, GameFrame, and have named the first argument, "f".

The Call-Ins all have different arguments- these are fixed things that Spring uses in these functions, and must have certain values (for example, if a Call-In expects a Unit's name, you must pass it a string). You can have additional arguments past those, of course- for example, with GameFrame, you could have (f,g) where g is some variable you've set the value of somewhere else in your code, and then you could use that if-->then to evaluate the values of both variables.

Secondly, I added the if-->then loop, to evaluate whether it's game frame 1 or not. If you didn't do that, every frame a new corcom would be spawned- not ideal! However, if you wanted to spawn one every 600 frames, you could just use this code, with very minor changes to increment the value of f that we're looking for each time.

The most important thing I added was the "else" and "end". They look kind've funky like that, but they're totally necessary. Each Gadget may have both Sync and UnSync code in it. That's why every Gadget starts with an if-->then.

If you have any unsync Call-Ins / Call-Outs you need to make (read the Wiki documentation about which are which- Call-Ins are documented in API.txt, which is a file in the LuaUI folder of Spring {should be Wiki'd, imo, I didn't even know it existed until somebody pointed it out})... you need to make them after the "else" in Gadgets, but before the final "end".

That final end closes the entire loop of the function. Without it, Spring doesn't know how to terminate the operations, and the Lua won't compile, let alone run.

Hope that helped clear things up a bit. You've really, really, really gotta sit down with the Lua Reference 5.1, read Lua sourcecode from other game designers around here, and study the Wiki hard, though, if you're going to make any headway. Nobody is going to write your code for you. Trust me, I understand how frustrating it is, if you're new to programming... but you're just going to have to do it, because once we're past simple loop stuff, you're on your own around here.
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

i read that, but it is really hard to start with, i dont really know what im doing, but now i have something were i can work from thanks, i hope i will get it to work now and more :o
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: need some help

Post by Hoi »

Argh wrote:@Hoi:
That code should spawn a corcom at 0,0,0 in the worldspace, facing South, and assigned to Team 16, on Frame 1 of sync time.
actually, it doesnt :? but what you wrote helped me and i will be able to write something like that myself in a few days orso (i hope)
Post Reply

Return to “Lua Scripts”