Difference between revisions of "Development:Quests & Campaigns"

From VsWiki
Jump to: navigation, search
m (Python Scripting)
m (Getting Objects)
Line 27: Line 27:
 
* <code>self.station = unit.getUnitByName('MiningBase')</code> - get the mining base
 
* <code>self.station = unit.getUnitByName('MiningBase')</code> - get the mining base
 
* <code>self.vessel= unit.getUnitByName('Ox')</code> - get an Ox ship
 
* <code>self.vessel= unit.getUnitByName('Ox')</code> - get an Ox ship
 +
* <code>self.gf = VS.launch("Charlotte the Harlot","Robin","privateer","unit","default",1,1,(1000,10,3000),'')</code> - creates one ship of type "Robin", being of the faction "privateer", at position (1000,10,3000), which will behave like "default" and show up in the HUD as "Charlotte the Harlot"
  
 
==Getting Properties==
 
==Getting Properties==

Revision as of 17:08, 28 March 2008

thumb_arrow_up.png Development

This page may contain SPOILERS of missions and other content of the game. Please do not read this if you want to play the game from the beginning and without knowledge you shouldn't have yet ;)

This page is meant to provide a platform for campaign/mission programmers to merge their ideas and best practices...

Python Scripting

Scripting Basics

VS has a lot of different ways of doing one thing. Just pick the most appropriate one for the job. It supports campaigns, missions, independent fixers, quests, etc., all of them having their specific ways of hooking them up into the game.

Quests are run inside of "random_encounters.py". If it returns 1 or True, it will keep going. If it returns 0, False or None (python returns None if you don't say what to return) then the quest will stop Execute()ing and be deleted until you jump into that system again or reload.

Each script requires at least those 2 elements:

  • def __init__ (self): - here you initialize your script variables
  • def Execute (self): - this part is executed each simulation frame; this is the place for writing the actions of the adventure.

Most of the python bindings (to the c++ engine) are listed in data4.x/modules/stub/VS.py and commented in HowTo:Edit_Missions:Python:Bindings:Python

Getting Objects

FIXME Improve/expand it.

In the script you will require to reference the objects of the universe. Here are some examples to get you started:

  • self.player = VS.getPlayer() - that's you
  • self.planet = unit.getUnitByName('Atlantis') - get planet Atlantis
  • self.station = unit.getUnitByName('MiningBase') - get the mining base
  • self.vessel= unit.getUnitByName('Ox') - get an Ox ship
  • self.gf = VS.launch("Charlotte the Harlot","Robin","privateer","unit","default",1,1,(1000,10,3000),) - creates one ship of type "Robin", being of the faction "privateer", at position (1000,10,3000), which will behave like "default" and show up in the HUD as "Charlotte the Harlot"

Getting Properties

Once you have referenced the appropriate object, you want to get information about it. Again, some commented examples follow:

  • self.starttime = VS.GetGameTime() - get the time since the start of the game. This is not the universe time (star date).
  • self.planet.isDocked(self.player) - verify if the player is docked to the planet. Note that you need to 'read' the meaning from right to left in this case.
  • self.station.getDistance(self.player) - The distance to the center of an object. Note that when landed on a planet, the distance is the actual planet radius.

Comminucations

Sending messages through the comm is fairly easy:

  • VS.IOmessage (0,self.vessel,"all","Hi buddy.") - make the vessel send a message to all through the comm immediately (the first 0) when the script line is executed.
  • VS.IOmessage (10,self.player,"all","Do I know you?") - makes the player send a public message through the comm 10 seconds after the script line is executed.

More Topics

FIXME Improve/expand it.

Flight Groups

You can use "flightgroup directives" to give units specific orders (which is cool if you want to generate two drones and make one blow up another)

The list of is in C++ (undocumented) but I've decided to look through the code. This should probably go to the wiki sometime

H,h (help) -- leader of flightgroup requests help. B,b (break and attack) -- default, everyone attacks like normal A,a (attack target) -- attack their current targets lowercase k -- something undocumented, says something about capships. Probably it's an order to take out capship turrets with priority, or it's a pure bomber order to attack capships and ignore fighters. F,f (flagship?) -- Ship being escorted. I would imagine that it's an order to attack a ship being escorted by the hostile faction. Alternatively, it could be an order to fly in formation. L,l -- undocumented, like F but has complicated formation rules. Could be a shortcut for "Leave" - ships heading out. E,e -- half of this is copy and pasted from L but I have no idea. I'd say it is "escort", escort a designated ship. P,p (protect)-- I want to help out

You can also add a "." to the end to ensure that the unit will not change targets on its own. Also, a capital letter overrides the AI script, and lower case will allow it to be changed.

Unfortunately I don't see any codes for acting like a sitting duck... You could try something like making it target itself, or making it target NULL (which you get by calling the constructor VS.Unit() ) and then using something like "A."

Or, just try doing a "B." and having it target you, and make sure it is friendly... then it might just fly near you.

I believe you can get it to fly places by having it target them and then force it to do unit.setFgDirective("B.") which I think forces it to act like normal and fly to this target.

Quests, Missions, Campaigns & Adventures

The first major campaign written (Jenek)

See also the forum thread (comments & feedback) when this mission was first put into SVN. FIXME Improvements/expend it?

See also