Mission development Guide: Difference between revisions

From Spring
Jump to navigationJump to search
Gamer17 (talk | contribs)
Gamer17 (talk | contribs)
Line 68: Line 68:


===Scripting your mission===
===Scripting your mission===
Now open up your txt to start scripting
The setup function only runs once, the first frame when the game starts and never again. That's where you want to put in all the code for loading the starting units and bases
At center of your mission script is the update function. It gets called by the game 30 times per second. You call all the other functions from this function.  A lot of the missions run on a time counter.
EX.
----
-- This function is executed every simulated frame (30 times/sec)
function Blank:Update()
    -- Perform initialization
    if self.state == 0 then
        self.state = 1
        self:Setup()
       
        print("Welcome")
    end
   
    -- Run SlowUpdate once every second
    if math.mod(gs.frameNum, 30) == 0 then
        self:SlowUpdate()
    end
   
    -- Do some stuff a bit later
    if gs.frameNum == 30*10 then
  print("Their moving to attack us ")
    end
    if gs.frameNum == 30*20 then
        self:SetupDelayed()
    end
    if gs.frameNum == 30*60 then
        self:MoveTanks()
    end
    if gs.frameNum == 30*75 then
        self:Airsupport()
    end
end
----

Revision as of 13:01, 31 May 2007


Getting started

First download this template

Then open it up in notepad and save it as a txt file

Load up spring from spring.exe in your spring folder. Now choose mission builder from the list.

Push enter and type: .cheat

                   .nocost

These will allow you to build your mission a lot faster

Now build up a friendly base with all the units you want, and an enemy base with all the units you want for them.

Then select all of the players units and base, then push enter and type: .savesel 0

Now do the save thing foe the enemy, but type: .savesel 1

Lastly push enter and type: .savefeatures

Once you save the units, quit Now open up the file infolog thats in spring folder.

It'll have the code for loading the units in there. Don't open up spring again before you copy it out or you'll lose everything.

You should see lines like this

units.Load("CORAK", float3(15400, 85, 2450), 0, false) units.Load("CORAK", float3(12650, 40, 2054), 0, false) units.Load("CORAK", float3(13444, 60, 2045, 0, false)

Now cut out the unit loading code paste it into the Template:Setup() function

It should look like this:

-- Create a bunch of units for this simple mission function Blank:Setup()

units.Load("arm_solar_collector", float3(472.0, 45.2, 280.0), 0, false)

units.Load("arm_metal_extractor", float3(328.0, 40.7, 360.0), 0, false)

units.Load("arm_commander", float3(469.7, 42.5, 441.7), 0, false)

units.Load("arm_wind_generator", float3(288.0, 40.1, 2768.0), 1, false)

units.Load("arm_light_laser_tower", float3(1920.0, 44.4, 2176.0), 1, false)

units.Load("arm_light_laser_tower", float3(1776.0, 43.9, 2208.0), 1, false)

units.Load("arm_vehicle_plant", float3(528.0, 74.0, 3664.0), 1, false)

Now to test it

Push Ctrl+H and find Blank, then replace it with the name you want for your mission.

To change this txt file back to lua:

Go to save as

Change the name to "whatever.lua" without the qutoes

Then change the type to "All Files"

If it opens and all the units spawn, then you are ready to start making your mission.

Scripting your mission

Now open up your txt to start scripting

The setup function only runs once, the first frame when the game starts and never again. That's where you want to put in all the code for loading the starting units and bases

At center of your mission script is the update function. It gets called by the game 30 times per second. You call all the other functions from this function. A lot of the missions run on a time counter.

EX.


-- This function is executed every simulated frame (30 times/sec) function Blank:Update()

   -- Perform initialization 
   if self.state == 0 then 
       self.state = 1 
       self:Setup() 
       
       print("Welcome") 
   end 
   
   -- Run SlowUpdate once every second 
   if math.mod(gs.frameNum, 30) == 0 then 
       self:SlowUpdate() 
   end 


   -- Do some stuff a bit later 
    if gs.frameNum == 30*10 then 
  print("Their moving to attack us ") 
    end 
    if gs.frameNum == 30*20 then 
       self:SetupDelayed() 
    end 
    if gs.frameNum == 30*60 then 
       self:MoveTanks() 
    end 
    if gs.frameNum == 30*75 then 
       self:Airsupport() 
    end 

end