The Noob Zone: Scripts as tools.

The place to discuss scripting and game modifications for X²: The Threat.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

User avatar
giskard
Posts: 5230
Joined: Wed, 6. Nov 02, 20:31
xr

The Noob Zone: Scripts as tools.

Post by giskard »

Hello all.

Before I start id like to say there are a lot of scripters out there that know far more than I do on this subject. So if your one of them feel free to but in and post your own stuff or correct mine. As this thread is aimed at Noobs, all i ask is you keep it Noob friendly.

The entire 440003.xml stuff can be confusing when you first encounter it but after using it you will realise its actually pretty easy stuff. :)

Scripts as tools

Sometimes its best to write a script to do a job to allow you to test your work without playing an entire game, just to see if it works or not. The scripts need not be complex, in fact sometimes they can be straight forward scripts. So not to confuse you im not going to post anything complex here. Everything starts small so thats where im starting. If you want complex i'll show you my mission scripts sometime... ARGH! :)

I should warn you, im learning as i go my self so please do not expect me to know all the answers to all the questions at the moment.

Scripts generally.

Every script has something like the following header. Whilst this is important the lines containing the numbers are the real code that actually do the job. However, trying running a script without a header and see how far you get :)

Code: Select all

Script setneutral.script
Version: 0
for Script Engine Version: 24

Description
Sets the target to be neutral to the player.
Arguments
Source Text
All the scripting commands in the script editor are only available via a menu in the script editor. What you have to do is hunt down the correct command, select it and it will appear in your script automatically. You will probably have to name a variable or select an object such as PLAYERSHIP or SECTOR. Sometimes your taken to a real sector if you choose SELECT SECTOR or any of the SELECT commands that exist for some commands you have chosen.

Most scripts are made using a simple choose your command line, add the variables in the correct order system.

So if you had a command that basically say "Is the player in argon prime" then the command may look like this "Is the VAR in SECTOR". You just choose the meaning of the VAR and the name of the SECTOR.

Easy stuff isnt it. :)

I should warn you that recently Egosoft have stated that choosing a sector object in a script, whilst allowed, may result in your script not saving to your scripts folder. The reason is that your script may be used in a mod that does not have the object you listed in its universe. So a series of "check if exists" type commands may be needed first before you can save your script.

If it does save you will see it in your script folder, best check before quiting the script editor. Im not entirely sure of the best way to check and avoid this but ive seen a lot of commands that do that job so there will be a way.

A couple of my own tools

Here is a few scripts i wrote that allows me to test my mod in the game without worrying about playing the game to the point where a script will work, eg when rank requirements click in or when the test subject is your enemy. My advice is not to save your game after running this scripts. I use them purely as tools when testing other scripts and the galaxy editor.

Setting an object to neutral.

This script simply requires the player to run it, choose a target and press return. That target ship or factory will then be set to neutral to the player allowing you dock or do other things that you possibily could not do before. It does not really work in the Galaxy editor as everything is dockable there but it is useful in the game to stop you from being attacked when testing stuff. I use it primarily when working in my modified pirate sector, i run this script on the defenders so they dont attack me whilst im testing other scripts.

Im learning this X2 scripting lark my self so there may be reasons for not doing things the way I do them in my test scripts that I do not know about. However im posting these to show you how useful a few tool scripts can be when making a mod and giving you the reasons why i wrote them and use them to make point clear. They are also very good practice scripts :)

Code: Select all

Script setneutral.script
Version: 0
for Script Engine Version: 24

Description
Sets the target to be neutral to the player.
Arguments
Source Text

001   [THIS] -> set relation against [PLAYERSHIP] to Friend
002   return null
The THIS command is Very useful for testing purposes plus a few other things too. I use it for scripts that I want to run and then choose a object manually that it will apply too. Sort of a "you choose" command i suppose. Do not let the fact that most lines start with a variable or object name confuse you, even if it does not look right compared to other scripting languages. The line still runs without you having to call the object of variable again. Also sometimes you can replace the object or var with different more standard commands such as if or if not. Or in some cases remove a command completely. Figuring out what commands allow you do this in a menu driven script editor will be your hardest job.

Add credits script

Another script thats a real cheat script but sometimes required when you want to test out something you added to a factory but your credits are not enough to buy it is this one.

It gives you enough credits to buy anything you need to test.

Code: Select all

Script init.addcredits
Version: 1
for Script Engine Version: 24

Description
Adds Credits to the players account
Arguments
Source Text

001   add money to player: 1000000000
002   return null
Sometimes you may want to load xml file containing your ship and station names from the T directory in the X2 folder. The command to do this is straightforeward. A script that loads your names or descriptions for most things looks like this.

Load your object names script

Code: Select all

Script mynames
Version: 1
for Script Engine Version: 24

Description
loads my names from my 440445.xml file in t folder. 440445 is a file i created btw. my file is 440444.xml. Please avoid using that name:)
Arguments
Source Text

001   load text: id=445
002   return null
Notice the id= line only uses the last 3 digits of the 440445 file :)

(This is actually my init script for HU but ive removed all the Hu lines so not to confuse you if im have not confused you already lol, as soon as this script is loaded the names for my sector objects get loaded too.)

The 440445.xml file must exist before X2 is loaded. Once in the Galaxy editor you need only select the station you want and add an id that points to entry in your 440445 file

Your 440XXX.xml from the T directory.

44 means its an english xml, 0XXX are the id of the script. So if your German, just replace the 44 with the german code which i believe is 49. If you want to support german players too, just make a copy of your script and rename it to 490XXX.xml and drop it in the T folder. It would help if you got somebody to translate the your names and text into german too. :)

No further changes need be made to support other languages so why not support them ?

Now theres pinned post in this forum already explaining these files far better than i can, so have a read of that.

You will find it at this link.
http://www.egosoft.com/x2/forum/viewtopic.php?t=22519
It can be a little technical but it explains this file in a lot more detail than i am doing.

For now I'll post an example that ive been using that works for me. Im figuring this out as i go along so there may be some errors. However this works and the bottom part containing the author bits works too when writen to the log of the player using one of the log commands that accepts the text id as an arguement. BTW Author lines below simply puts the name between the author tags at the top of the message you send to the players log.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<language id="44">

<page id="17" title="Boardcomp. objects" descr="Quad line groups for ware factory pairs or twins (spoken by Boardcomputer)">
 <t id="6000">Pirate Equipement Dock</t>
 <t id="6001">Pirate Shipyard</t>
 <t id="6002">Pirate Wharf</t>
 <t id="6003">The Big Ban Burger bar (Joke ok)</t>
</page>

<page id="121" title="Mission text" descr="Hostile Universe Missions">
 <t id="7000">[author]Nemesis Captain[/author]Paranid Nemesis calling any pilot in Range. We are in need of assistance. Navigation is down, all systems failing. We are caught in some kind of Temporal Storm and are unable to find our way out. The ship has taken heavy damage. Please Assist</t>
 <t id="7001">[author]Nemesis Captain[/author]Pilot of approaching Vessel, please lead us out of this storm, we are unable to Navigate. If you guide us to Paranid Prime you will be rewarded.</t>
 <t id="7002">[author]Nemesis Captain[/author]The Paranid Navy thanks you Pilot. We are greatful for your timely assistance. Please accept this reward of 250,000 credits for your efforts and the best wishes of our Duke.</t>
 <t id="7003">[author]Nemesis Captain[/author]Systems failed... Ships Engines going Critical.....ARGH!!!!!....STATIC...communication has been lost.</t>
 <t id="7004">[author]Dan[/author]Hello Julian, Dan here. The Paranid Authorities sent us a report about the Nemesis you encountered. Appearantly it's on board computer stated it had been lost for only day but the Paranid Authorities have been looking for it for weeks. Looks like you solved one mystery and created another. Well done Julian. </t>
</page>

</language>
I just want to highlight one of the Author lines for you because i think its a cool idea when writing log entries to use them. Here is the format that i found works.

Code: Select all

<t id="7000">[author]Name of person sending the message[/author]Your message goes here.</t>
The id=number part contains the id number you need to remember. In the galaxy editor you can select an object, press N and enter that number. That object will then be given the name that appears after the id number above or in the case of messages it associates the id number with a piece of text so when ever that id is used, the text will appear.

If anybody spots any problems with my scripts here please let me know. I only use the top scripts for testing stuff but it would still be nice to get them right :)

Giskard
This signature has been stolen by the well known Teladi Signature Thief X Siggy.
Howlingmad
Posts: 1252
Joined: Wed, 6. Nov 02, 20:31
x3

Post by Howlingmad »

TMG. :roll:
What no sig or avatar. I wonder why?:(
User avatar
giskard
Posts: 5230
Joined: Wed, 6. Nov 02, 20:31
xr

Post by giskard »

The mad goners strike again :)

Giskard
This signature has been stolen by the well known Teladi Signature Thief X Siggy.
Howlingmad
Posts: 1252
Joined: Wed, 6. Nov 02, 20:31
x3

Post by Howlingmad »

giskard wrote:The mad goners strike again :)

Giskard
We are everywhere, you cannot escape from us! :D
What no sig or avatar. I wonder why?:(
User avatar
Argonaught.
Posts: 1827
Joined: Wed, 6. Nov 02, 20:31
x4

Post by Argonaught. »

Yay...someones doing a noob tutorial of their scripting......nice one Giskard :thumb_up: ....How many of these tutorials will you be providing? I'll be copying them all :) :thumb_up:
[MOD]X3TC No Fog / [MOD]X3AP No Fog / [MD]X3TC Menagerie Shipyard / [MD]X3AP Menagerie Shipyard
<==<<Argonaught>>==>

XBTF>XT>X2TT>X3R>X3TC>X3AP>X4F

I lurk alot for the most part now
:thumb_up:
User avatar
giskard
Posts: 5230
Joined: Wed, 6. Nov 02, 20:31
xr

Post by giskard »

I just woke up and realised the gap between actually writing a script and reading the existing docs is a big scarey one so I thought id post something simple to spur on those who are sitting on the fence :)

I would not want to cover advanced topics my self yet, not good enough for that to be honest.

BTW i lost my mission script again, got it working, better than ever. It saved ok part way through, I edited it and my ship went through a jumpgate whilst the script editor was up DUH.

Dont ask me how :)

Probably one of those keys that controls the ship is also used elsewhere in the editor. Or perhaps it was when i alt tabbed to the desktop and it set my speed to max and i didnt notice.

Giskard
This signature has been stolen by the well known Teladi Signature Thief X Siggy.

Return to “X²: The Threat - Scripts and Modding”