Lua mission scriptin

Lua mission scriptin

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

Moderator: Moderators

User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Lua mission scriptin

Post 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.
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

also, my lua aistartscripttest crashes with a c++ windows error, regardless of the AI set to apply to the teams
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post 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?
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

right, only RAI works with mission building for some reason.
now, to get the hang of unit ordering.
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

is there a way of limiting resources in LUA missions?
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post 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?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post 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...
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Post 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.
User avatar
Thor
NOTA Developer
Posts: 291
Joined: 05 Mar 2006, 10:26

Post 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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

It's impossible in current spring :/
User avatar
kujeger
Posts: 91
Joined: 07 Oct 2004, 14:46

Post by kujeger »

Maybe spawn a tiny invisible unit that drains massive amounts of energy/metal?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post 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)
}
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Post 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...
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

AF: AFAIK, all those functions do not exist.

Kujeger, that might work yeah, but it's a really hackish workaround...
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Post 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 :/ ...
User avatar
Thor
NOTA Developer
Posts: 291
Joined: 05 Mar 2006, 10:26

Post 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.
User avatar
1v0ry_k1ng
Posts: 4656
Joined: 10 Mar 2006, 10:24

Post by 1v0ry_k1ng »

sean, how would you maniulate that code to give sane resources then?
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Post 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 :o, 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 :P !). Wow ... where is Betalord :wink: ?
User avatar
Noruas
XTA Developer
Posts: 1269
Joined: 24 Feb 2005, 02:58

Post by Noruas »

As long as you let me do the Krogoth mission Ivory (:
Post Reply

Return to “Lua Scripts”