Difference between revisions of "Development:Python:Functions"

From VsWiki
Jump to: navigation, search
 
m (Flight Groups)
Line 81: Line 81:
  
 
The following directives are available:
 
The following directives are available:
* H, h (help) -- leader of flightgroup requests help.
+
<code><pre>
* B, b (break and attack) -- default, everyone attacks like normal
+
* H, h (help) - "Help me out!" - leader of flightgroup requests help for self.
* A, a (attack target) -- attack their current targets
+
* B, b (break and attack) - default, everyone attacks like normal.
* 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.
+
* A, a (attack target) - attack their current targets.
* 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.
+
    // a is now used for AI, for backward compatibility. do not use for player.
* L, l -- undocumented, like F but has complicated formation rules. Could be a shortcut for "Leave" - ships heading out.
+
* K, k - "Attack my target!"
* E, e (escort) -- half of this is copy and pasted from L but I have no idea. I'd say it is "escort", escort a designated ship.
+
* F, f (formation) - "Form on my wing." - it is an order to fly in formation.
* P, p (protect) -- I want to help out
+
* L, l (lalala) - "Get in front of me and prepare to be tractored in."
 +
* E, e (eject) - "I am ejecting! Record the current location of my ship."
 +
    ... "Then get over here and pick me up!"
 +
* P, p (protect) - "Defend my target!" - request for help me out defending my target.
 +
</pre></code>
 +
 
 +
some details to "L,l" and "E,e":
 +
 
 +
L, l > "Get in front of me and prepare to be tractored in."
 +
// this order is only valid for cargo wingmen, other wingmen will not comply
 +
// if i am a cargo wingman, get into a dockable position facing me
 +
// if i am a cargo wingman and so is the player, get into a dockable position with the leader facing it
 +
// if i am the capship, go into defensive mode
 +
// if i'm not a cargo wingman, just form up somewhat loosely facing in the same direction as the leader
 +
 
 +
E, e > "I am ejecting! Record the current location of my ship." ... "Then get over here and pick me up!"
 +
should work pretty much the same as L, l
 +
// this order is only valid for cargo wingmen, other wingmen will not comply
 +
// if i'm not a cargo wingman, IT'S NOT MY PROBLEM.
  
 
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 the flight group to fly to 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.
 
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 the flight group to fly to 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.

Revision as of 09:52, 28 August 2008

Useful Python Functions

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.

There are many other useful functions coded in python and distributed through various other classes.

  • data4.x/modules/Vector.py contains vector manipulation functions
  • data4.x/modules/universe.py has functions related to the current and adjacent systems
  • data4.x/modules/unit.py provides some unit properties, methods, and actions
  • data4.x/modules/launch.py is useful for spawning units in almost any place
  • data4.x/modules/faction_ships.py allows for a fine creation of ship lists by type and faction, e.g. for spawning.

Some of the functions that might be of help when writing quests and adventures are discussed in the following.

Game Properties and Actions

  • self.starttime = VS.GetGameTime() - get the time since the start of the game. This is not the universe time (star date).

Getting Units

In the script you will require to reference the ships and other 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.object = unit.getUnitByName('Jump_To_Nethuuleil')<code> - get the jump point
  • <code>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"
  • ships = VS.getUnitList() - get a list of all objects in the current system
  • self.jump = universe.getRandomJumppoint() - get a random jump point
  • self.vessel.GetTarget() - get the vessel's targeted unit

Unit Properties

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

  • 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.
  • vec = self.player.Position() - assign the player's position vector to a variable
  • self.vessel.getName() - gets the unit name, e.g. "Llama"
  • self.vessel.getName() - returns the full name of the vessel

System Properties

  • VS.getSystemName() - get the name of the current system the player is in
  • VS.getNumUnits() - get the number of units in the current system. This includes ships, navpoints, cargo, planets, stations, and the sun.

Communications

Sending messages through the comm is fairly easy:

  • VS.IOmessage (0,"Oxen","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,"You","all","Do I know you?") - makes the player send a public message through the comm 10 seconds after the script line is executed.

You can even set your own color for the messages with a html color code:

  • VS.IOmessage (20,"Oxen","You","#8080FFYou don't remember me?") - prints the comm message in light blue.
    • self.txtColor="#8080FF"
    • VS.IOmessage (30,"Oxen","Privateer",self.txtColor+"I can hardly believe this") - you can even define a color variable and add it to each line.

As far as the communications go, there is a variable in cockpit that holds what the VDU screen shows as possible options. Unfortunately the communications system is not scriptable at the moment.

Comm animations can be called from your quest script and will be shown on the Comm VDU:

  • self.player.commAnimation("com_questname_animationname.ani")

The animation files must be placed in a corresponding folder data4.x/animations/com_questname_animationname.ani and the animation definition file named equally com_questname_animationname.ani.

News

Note that we should eventually make the news reports line up with the quests... :-) I have some ideas how to do that. Basically you can call

VS.IOmessage ("game","news","A drone was sighted in the delta prime...blah blah blah")

and then people will see it in the game when they click on GNN likewise if you send it to

VS.IOmessage ("game","bar","A drone was sighted in the delta prime...blah blah blah")

then you can hear it when you talk to the bartender :-)

More Topics

FIXME Improve/expand it.

Flight Groups

  • ship.getFlightgroupName() - returns the name of the flight group for the ship


You can use "flight group 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 directives is in C++ (undocumented).

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

The following directives are available:

* H, h (help) - "Help me out!" - leader of flightgroup requests help for self.
* B, b (break and attack) - default, everyone attacks like normal.
* A, a (attack target) - attack their current targets.
     // a is now used for AI, for backward compatibility. do not use for player.
* K, k - "Attack my target!"
* F, f (formation) - "Form on my wing." - it is an order to fly in formation.
* L, l (lalala) - "Get in front of me and prepare to be tractored in."
* E, e (eject) - "I am ejecting! Record the current location of my ship."
     ... "Then get over here and pick me up!"
* P, p (protect) - "Defend my target!" - request for help me out defending my target.

some details to "L,l" and "E,e":

L, l > "Get in front of me and prepare to be tractored in." // this order is only valid for cargo wingmen, other wingmen will not comply // if i am a cargo wingman, get into a dockable position facing me // if i am a cargo wingman and so is the player, get into a dockable position with the leader facing it // if i am the capship, go into defensive mode // if i'm not a cargo wingman, just form up somewhat loosely facing in the same direction as the leader

E, e > "I am ejecting! Record the current location of my ship." ... "Then get over here and pick me up!" should work pretty much the same as L, l // this order is only valid for cargo wingmen, other wingmen will not comply // if i'm not a cargo wingman, IT'S NOT MY PROBLEM.

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 the flight group to fly to 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.

For some directives to work, you must set the appropriate target and adjust the relation between the factions to either hostile (e.g. attack) or friendly (escort, protect). Here's a snippet to get you started:

    self.aggressor.SetTarget(self.victim)
    VS.AdjustRelation(self.aggressor.getFactionName(),self.victim.getFactionName(),-1,-1)
    self.aggressor.setFgDirective("A.")

See Also