Page 1 of 2
Lua mission scriptin
Posted: 09 Feb 2007, 16:17
by 1v0ry_k1ng
is there a handy guide and command list for making the lua single player missions somewhere? im pretty poor at coding but it dosnt look to complex. sorry if there is already a thread, if there was I couldnt find it.
Posted: 09 Feb 2007, 16:39
by 1v0ry_k1ng
also, my lua aistartscripttest crashes with a c++ windows error, regardless of the AI set to apply to the teams
Posted: 09 Feb 2007, 16:52
by Tobi
Posted: 09 Feb 2007, 18:43
by 1v0ry_k1ng
I knew most of that but cheers, i didnt have the list :D
Im making a set of 5 missions to help people get the hang of XTA, i was inspired by Thors pro NOTA missions.
any idea why adding AI crashes it?
Posted: 09 Feb 2007, 19:06
by 1v0ry_k1ng
right, only RAI works with mission building for some reason.
now, to get the hang of unit ordering.
Posted: 09 Feb 2007, 19:19
by 1v0ry_k1ng
is there a way of limiting resources in LUA missions?
Posted: 09 Feb 2007, 20:00
by 1v0ry_k1ng
is it possible to have several units of the same name, ie
self.myboi = units.Load("ARM_COMMANDER", float3(350, 16, 250), 0, false)
self.myboi = units.Load("ARM_JETHRO", float3(350, 16, 250), 0, false)
If I have self.myboi a move order, would they both move or would windows explode?
Posted: 09 Feb 2007, 20:08
by Tobi
I think you can set the commanders' metal & energy storage values to something low when the mission starts.
EDIT: as for your 2nd question. I think there would be 2 units created, of which only the last one would move if you give it a command.
Use different variables to be able to reference both of them...
Posted: 10 Feb 2007, 00:05
by SeanHeron
I have been working on a tutorial a few weeks ago, but haven´t got it to a releasable stage yet. I thought it might be helpful for you though, so I´ve uploaded it now:
http://spring.unknown-files.net/file/23 ... orial.lua/
As you will certainly notice quickly enough if you try it, its directed towards people who have no prior RTS experience (which I guess is highly unrealistic for anybody playing spring, but whatever :D ).
Also the bits I made will probably not be commented very well :/ . But feel free to ask if you want to know why, how I´m doing something (not that I´m doing much...)
Edit:
On giving multiple units orders, I don´t know if the way you wrote does or does not work, what I know does work is the way its done in missiontest.lua (where I ripped most of my script from) :
Code: Select all
-- Enemy stuff
local first = {
units.Load("CORe_AK", float3(1200, 80, 200), 1, false),
units.Load("CORe_AK", float3(1200, 80, 300), 1, false),
units.Load("CORe_AK", float3(1200, 80, 400), 1, false),
units.Load("CORe_AK", float3(1200, 80, 500), 1, false),
units.Load("CORe_AK", float3(1000, 80, 200), 1, false),
units.Load("CORe_AK", float3(1000, 80, 300), 1, false),
units.Load("CORe_AK", float3(1000, 80, 400), 1, false),
units.Load("CORe_AK", float3(1000, 80, 500), 1, false)
}
local c = Command()
c.id = Command.PATROL
c:AddParam(1100)
c:AddParam(80)
c:AddParam(1000)
for i = 1, table.getn(first) do
first[i]:GiveCommand(c)
end
Thus putting all the units you want as a group in an array, and then just having it loop the orders though for the whole array with the "for i = 1, ..." if I understand the code correctly.
Edit: P.S. , I think your XTA guide rocks, and think its great you want to make an ingame tutorial. While I probably don´t have much time to spare in the next week or two, I would generally gladly give you a hand on making the an in game guide.
Posted: 10 Feb 2007, 06:10
by Thor
Can someone show how to limit resources? I haven't been able to get it to work, although admittedly my coding ability is not very good either. I hope it is possible. The kinds of missions that can be done without letting the player build anything are pretty limited.
Posted: 10 Feb 2007, 11:09
by Tobi
It's impossible in current spring :/
Posted: 10 Feb 2007, 14:06
by kujeger
Maybe spawn a tiny invisible unit that drains massive amounts of energy/metal?
Posted: 10 Feb 2007, 18:53
by AF
A little bit of pseudocode to add in the update function
Code: Select all
a = getEnergy()
if(a > Energylimit){
b = a-EnergyLimit
AddEnergy(-b)
}
Posted: 10 Feb 2007, 23:17
by SeanHeron
Thor, what exactly do you mean by limiting resources ? Do you mean limiting as in: not start with the crazy (but usefull for testing purposes) 200 k metal and 1000 k storage you get at the moment, but rather the standard 1000 each of metal and energy ? Cause than it might be an idea to have a look at the cmdrscript.lua . If you run that you start with the regular resources I think. No idea how its done though :/. Just let me check...
Posted: 10 Feb 2007, 23:51
by Tobi
AF: AFAIK, all those functions do not exist.
Kujeger, that might work yeah, but it's a really hackish workaround...
Posted: 11 Feb 2007, 01:08
by SeanHeron
Ok I was wrong, the cmdrscript starts with loads of resources as well. However I did find this:
Code: Select all
class_<UnitDef>("UnitDef")
.def_readonly("name", &UnitDef::name)
.def_readonly("humanname", &UnitDef::humanName)
.def_readwrite("metalstorage", &UnitDef::metalStorage) // readwrite so we can set commander's metalstorage at start of game
.def_readwrite("energystorage", &UnitDef::energyStorage), // readwrite so we can set commander's energystorage at start of game
in the Luabinder.cpp
I´ve tried playing around with it, but I don´t really know how I would have to implement it. The bad news is, that I don´t have the impression that loosing your com means loosing your starting storage, as it does in normal games, so maybe this isn´t going to work anyhow :/ ...
Posted: 11 Feb 2007, 01:12
by Thor
Sean, yes, all I want is to start with 1000 resources. I've looked at cmdrscript.lua but can't find anything to do with it.
Posted: 11 Feb 2007, 01:54
by 1v0ry_k1ng
sean, how would you maniulate that code to give sane resources then?
Posted: 11 Feb 2007, 13:12
by SeanHeron
Thats not actually code to put in a script, thats from the c++ file in which the lua commands and classes are defined (I think, to be honest I don´t have much of an idea either). As stated above I haven´t managed to actually use /get working the function: metalstorage, as I´m not much of a coder myself :/. I just happened to have seen the comment in the code, and its obviously about what you (and me for that matter) want to get to make "building" missions possible.
Edit: well [edit: expletive deleted] me

, forget all of the stuff I said above and check out
this thread.
I was about to say apparently, cause I still can hardly believe it but I just tried, and You can call different startscripts from the script.txt (used by the lobby) ! That means you can easily start with 1000 1000 res, or do just about anything else thats possible with the lobby as well *Jaw drop*. The only thing missing is lobby support... But by using a manually edited script.txt, and starting spring via a shortcut with the argument script.txt it works fine (in easyspeak that is: make a shortcut to the spring.exe, open its properties, and then change its target to "[wherever you have spring]\Spring\spring.exe script.txt " . Then use the shortcut and viola

!). Wow ... where is Betalord

?
Posted: 12 Feb 2007, 02:26
by Noruas
As long as you let me do the Krogoth mission Ivory (: