need some help
Moderator: Moderators
need some help
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
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
Re: need some help
I'd use Spring.GiveOrderToUnit and CMD.MOVE. You could use MoveCtrl to keep units in formation with a leader.
Re: need some help
using what command(s)? and how can i let the player lose lives when the units reach the final waypoint?quantum wrote:I'd use Spring.GiveOrderToUnit and CMD.MOVE. You could use MoveCtrl to keep units in formation with a leader.
Last edited by Hoi on 23 Jun 2008, 10:21, edited 1 time in total.
Re: need some help
there is a callin:
UnitCmdDone(unitID, unitDefID, unitTeam, cmdID, cmdTag)
UnitCmdDone(unitID, unitDefID, unitTeam, cmdID, cmdTag)
Re: need some help
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... }
?
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... }
?
Re: need some help
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.
Re: need some help
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 defenceKDR_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.
Re: need some help
ok, so atm this is my luafail:
ofc, it doesnt work, can anyone tell me why?
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
- Stealth870
- Posts: 166
- Joined: 13 Sep 2004, 00:25
Re: need some help
I think you need to put it in a "function widget:Initialize()"
Re: need some help
lern2program, kthxbai.Hoi wrote:ok, so atm this is my luafail:ofc, it doesnt work, can anyone tell me why?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
Re: need some help
@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:
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.
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
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.
Re: need some help
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 

Re: need some help
actually, it doesntArgh 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.
