Help converting X3R AL script to X3TC - New code Posted, *Project Dropped*

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

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

TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Help converting X3R AL script to X3TC - New code Posted, *Project Dropped*

Post by TEKing66 »

Hi all,

First let me say that I am by no means a programmer and/or scripter.
But, I am willing to dabble in this and maybe even learn something along the way.

That said, this is an AL plugin I wrote, with a lot of help from people on this forum, for X3-Reunion. To get what I have now I opened the old X3R scripts in XML Notepad on my second monitor. The in X3TC opened up the Script editor and recreated them there, line for line. However, some things are not working correctly (see list below).

This is what it should do;
Check to see if the player has a satellite in the sector he is currently in.
If not, then a ship called "Satellite Deployment Services" sets out from the nearest Trading Center and places one at 0,10Km,0 of said sector. Then charges the player the averagecost of the Satellite + 20% of that cost (for a placement fee). Then returns to the Trading Center (I then destroy the ship just to cleanup). When the Player enters a new sector it starts all over again.

Edit - Previous problems are now resolved.

Edit - This is new
Here are some things I would like to achieve with this script.

1. Send the player a message asking if they want to sign up for the service. (not sure how I need to go about this, though I do have the message with buttons for 'yes' and 'no' in the 't' file).

2. Have the Script check the players credits to be sure they can afford the service. If he can but later runs low on funds have the service terminate. Then check at given intervals, if the player can afford it later remake the offer. (insure how to proceed here, but I believe this needs to be the first condition to be met at each interval of the script running)

3. Have the script check all player known sectors, and place Sats there is needed, maybe excluding hostile sectors known to the player. i.e. - have it maintain the players Sat network. (again here I am a little lost as to how to do this.)

After looking back at these task I would, I have made an astounding discovery!

I may be in over my head here :D

If anyone can help me figure this out it would be much appreciated.

Here are the scripts involved;

Edit - This is the current Code.

al.plugin.tek.SatDeployServices.xml - To register the AL Plugin

Code: Select all

Script al.plugin.tek.SatDeployServices
Version: 0
for Script Engine Version: 44

Description
Declare Satellite Deployment Services as AL plugin
Arguments
Source Text

001   * Load the text file.
002   load text: id=8971
003   
004   * Load the AL Script
005   al engine: register script='al.tek.SDS.Main'
006   
007   return null


al.tek.SDS.Main.xml - The Main Script

Code: Select all

Script al.tek.SDS.Main
Version: 0
for Script Engine Version: 44

Description
Main script fot the Satellite Deployment Services AL plugin.
Arguments
1: SDS.al.PluginID , Var/String , 'AL Plugin ID' 
2: SDS.al.Event , Var/String , 'AL Event' 
Source Text

001   load text: id=8971
002   * load your t file
003   
004   * global plugin variable stores plugin state and variables
005   $SDS.plugin.Vars = get global variable: name=$SDS.al.PluginID
006   if not $SDS.plugin.Vars
007   * setup new data structure and init it
008   |$SDS.plugin.Vars =  array alloc: size=2
009   |set global variable: name=$SDS.al.PluginID value=$SDS.plugin.Vars
010   * data structure version
011   |$SDS.plugin.Vars[0] = 0
012   * plugin initially enabled needs TRUE set disabled on init = FALSE
013   |$SDS.plugin.Vars[1] = [TRUE]
014   end
015   
016   * handle plugin events
017   * init and reinit are run every time the game loads
018   if $SDS.al.Event == 'init' OR $SDS.al.Event == 'reinit'
019   |$SDS.Description = sprintf: pageid=8971 textid=2, null, null, null, null, null
020   |al engine: set plugin $SDS.al.PluginID description to $SDS.Description
021   |
022   * init and reinit are run every time the game loads
023   * interval is 1 minutes
024   |$SDS.Interval = 1 * 60
025   |al engine: set plugin $SDS.al.PluginID timer interval to $SDS.Interval s
026   |
027   else if $SDS.al.Event == 'isenabled'
028   |$SDS.Enabled = $SDS.plugin.Vars[1]
029   |return $SDS.Enabled
030   |
031   * Use this area to process special instructions when the plugin is toggled on
032   else if $SDS.al.Event == 'start'
033   |$SDS.plugin.Vars[1] = [TRUE]
034   |$SDS.Description = sprintf: pageid=8971 textid=2, null, null, null, null, null
035   |al engine: set plugin $SDS.al.PluginID description to $SDS.Description
036   |
037   * Use this area to process special instructions when the plugin is toggled off
038   else if $SDS.al.Event == 'stop'
039   |$SDS.Description = sprintf: pageid=8971 textid=2, null, null, null, null, null
040   |$SDS.plugin.Vars[1] = [FALSE]
041   |al engine: set plugin $SDS.al.PluginID description to $SDS.Description
042   |
043   * The event script is called every interval
044   else if $SDS.al.Event == 'timer'
045 @ |= [THIS] -> call script 'al.tek.SDS.Events' :  SDS AL Plugin ID=$SDS.al.PluginID  SDS plugin data=$SDS.plugin.Vars
046   end
047   return null
al.tek.SDS.Events.xml - The Event handler Script that does the work

Code: Select all

Script al.tek.SDS.Events
Version: 0
for Script Engine Version: 44

Description
Satellite Deployment Services event handler.
Arguments
1: SDS.al.PluginID , Var/String , 'SDS AL Plugin ID' 
2: SDS.plugin.Vars , Var/String , 'SDS plugin data' 
Source Text

001   * if plugin is disabled, dont do anything
002   $SDS.plugin.Enabled = $SDS.plugin.Vars[1]
003   
004   if $SDS.plugin.Enabled != 1
005   * put a shutdown script in here if needed
006   * put an unistall script in here if needed to remove added products etc
007   |set global variable: name='Satellite.Deployment.Services' value=null
008   |return null
009   end
010   
011   if $SDS.plugin.Enabled == 1
012   * call setup and start script here
013   |set global variable: name='Satellite.Deployment.Services' value=1
014 @ |= [THIS] -> call script 'al.tek.SDS.Deploy.Event' : 
015   end
016   
017 @ = wait 150000 ms
018   
019   return null
al.tek.SDS.Deploy.Event - Takes care of an event for the events script

Code: Select all

Script al.tek.SDS.Deploy.Event
Version: 0
for Script Engine Version: 44

Description
Handles the Advanced Satellite deployment event.
Arguments
Source Text

001   * Setup for creating the Satelliet Deployment Services Ship.
002   * ***Gather the required information.
003   $SDS.Name =  read text: page=8971 id=2
004   $SDS.Abbrev =  read text: page=8971 id=1
005   $SDS.Exist.Sat.Flags = [Find.Nearest]
006   $SDS.Exist.Ship.Flag = [Find.Nearest]
007   $SDS.Flags = [Find.Nearest]
008   $SDS.Sector = [PLAYERSHIP] -> get sector
009   $SDS.SectorRace = $SDS.Sector -> get owner race
010   * See if a satellite owned by the Player exists in sector.
011   $SDS.Existing.Satellite =  find ship: sector=$SDS.Sector class or type=All Satellites race=Player flags=$SDS.Exist.Sat.Flags refobj=[PLAYERSHIP] maxdist=100000 maxnum=1 refpos=[PLAYERSHIP]
012   * If player owned Sat exist, do nothing and end.
013   if $SDS.Existing.Satellite != null
014   end
015   * If no Sat exists, then do check for delivery ship.
016   if not $SDS.Existing.Satellite == null
017   * Check to see if a ship is on the way to deploy a Sat.
018   |$SDS.Exist.Ship =  find ship: sector=$SDS.Sector class or type=Military Transport race=$SDS.SectorRace flags=$SDS.Exist.Ship.Flag refobj=[PLAYERSHIP] maxdist=100000 maxnum=1 refpos=[PLAYERSHIP]
019   |$SDS.Exist.Ship.Name = $SDS.Exist.Ship -> get name
020   * If not Sat, but a ship is found, then end.
021   |if $SDS.Exist.Ship.Name != null
022   |end
023   * If not Sat and no ship are found.
024   else if $SDS.Exist.Ship.Name == null
025   * *Find the nearest Trading Dock to the Player.
026   |$SDS.Start.Station =  find station in galaxy: startsector=$SDS.Sector class or type=Trading Dock race=$SDS.SectorRace flags=$SDS.Flags refobj=[PLAYERSHIP] serial=null max.jumps=5 num=1
027   * *Create the ship, Name it, Give it a Pilot and ad it to the Trading Dock.
028   |$SDS.Ship =  create ship: type=Military Transport owner=$SDS.SectorRace addto=$SDS.Start.Station x=0 y=0 z=0
029   |$SDS.Ship -> set name to $SDS.Name
030   |$SDS.PilotName = get random name: race=$SDS.SectorRace
031   |$SDS.Ship -> set pilot name to $SDS.PilotName
032   * Equip the ship for it's job.
033   |$SDS.Ship.Shield.Bays = $SDS.Ship -> get number of shield bays
034   |$SDS.Ship.Max.Shields = $SDS.Ship -> get max. shield type that can be installed
035   |= $SDS.Ship -> install $SDS.Ship.Shield.Bays units of $SDS.Ship.Max.Shields
036   |$SDS.Ship.Max.Engines = $SDS.Ship -> get max upgrades for upgrade Engine Tuning
037   |$SDS.Ship.Supertune = $SDS.Ship.Max.Engines * 2
038   |= $SDS.Ship -> install $SDS.Ship.Supertune units of Engine Tuning
039   |$SDS.Ship.Max.Rudder = $SDS.Ship -> get max upgrades for upgrade Rudder Optimisation
040   |= $SDS.Ship -> install $SDS.Ship.Max.Rudder units of Rudder Optimisation
041   |$SDS.Ship.Max.CargoBay = $SDS.Ship -> get max upgrades for upgrade Cargo Bay Extension
042   |= $SDS.Ship -> install $SDS.Ship.Max.CargoBay units of Cargo Bay Extension
043   |= $SDS.Ship -> install 1 units of Jumpdrive
044   |= $SDS.Ship -> install 500 units of Energy Cells
045   |= $SDS.Ship -> install 5 units of Advanced Satellite
046   * *Turn of the AI for the ship.
047   |$SDS.Ship -> set race logic control enabled to [FALSE]
048   * Jump to Player sector if required
049   |$SDS.Trade.Dock.Sector = $SDS.Start.Station -> get sector
050   |skip if $SDS.Sector == $SDS.Trade.Dock.Sector
051   ||= $SDS.Ship -> use jump drive: target=$SDS.Sector
052 @ |= $SDS.Ship -> move around 3000 ms
053   * *Move the ship into position: x= 0, y=1250, z=0
054 @ |$SDS.Deploy.Position = $SDS.Ship -> move to position: x=0 y=1250 z=0 with precision 10 m
055   |$SDS.Ship -> set command: [ACTION_IDLE]
056   * *Deploy the Advanced Satellite and give the Player control.
057   |$SDS.Deployed.Satellite =  create ship: type=Advanced Satellite owner=Player addto=$SDS.Sector x=0 y=1000 z=0
058   * Charge the Player, the minimum cost of the Sat + 10% surcharge.
059   |$SDS.Min.Sat.Cost = get min price of ware Advanced Satellite
060   |$SDS.Total.Sat.Cost = $SDS.Min.Sat.Cost + ( $SDS.Min.Sat.Cost / 10 )
061   |$SDS.Player.Charges = - $SDS.Total.Sat.Cost
062   |add money to player: $SDS.Player.Charges
063   * *Send the ship back to the Trade Dock.
064 @ |= $SDS.Ship -> move around 3000 ms
065   |skip if $SDS.Sector == $SDS.Trade.Dock.Sector
066   ||= $SDS.Ship -> use jump drive: target=$SDS.Trade.Dock.Sector
067 @ |= $SDS.Ship -> fly to station $SDS.Start.Station
068   * *And, just to cleanup, Destroy the ship.
069   |$SDS.Ship -> destruct: show no explosion=1
070   end
071   return null
Edit note - These two files remained unchanged.
This is my 't' file named 8971.xml (copied from XML Notepad Output window) -

Code: Select all

<language id="44">
<page id="8971" title="Satellite Deployment Services" descr="">
 <t id="1">S.D.S.</t>
 <t id="2">Satellite Deployment Services</t>
 <t id="10">Satellite Deployment Services is offering you the service of deploying an Advanced Satellite in every sector you enter. Once you accept our agreement, the service will start sending out ships to a central location in any sector you enter, once there they will deploy a new Advanced Satellite for you. If you currently have a satellite in that sector you will not be charged and no action will be taken. \n\n The fee(s) for this service includes the cost of the satellite and an installation and maintenance fee of 30% of the cost of said satellite. Charges for setting a new satellite are made prior to satellite deployment. Once the Satellite is deployed it becomes your property and your responsibility.</t>
 <t id="11">Would you like to accept the agreement with Satellite Deployment Services?</t>
 <t id="12">Satellite Deployment Services is offering you the service of deploying an Advanced Satellite in every sector you enter. Once you accept our agreement, the service will start sending out ships to a central location in any sector you enter, once there they will deploy a new Advanced Satellite for you. If you currently have a satellite in that sector you will not be charged and no action will be taken. \n\n The fee(s) for this service includes the cost of the satellite and an installation and maintenance fee of 30% of the cost of said satellite. Charges for setting a new satellite are made prior to satellite deployment. Once the Satellite is deployed it becomes your property and your responsibility.\n\nShall we sign you up on our service?\n\n[select value="1"]Yes, sign me up[/select]\n[select value="2"]No, not today![/select]\n</t>
 </page>
 </language>
This is my 't' file named 8971-L044.xml (copied from XML Notepad Output window)

Code: Select all

<language id="44">
<page id="8971" title="Satellite Deployment Services" descr="">
 <t id="1">S.D.S.</t>
 <t id="2">Satellite Deployment Services</t>
 <t id="10">Satellite Deployment Services is offering you the service of deploying an Advanced Satellite in every sector you enter. Once you accept our agreement, the service will start sending out ships to a central location in any sector you enter, once there they will deploy a new Advanced Satellite for you. If you currently have a satellite in that sector you will not be charged and no action will be taken. \n\n The fee(s) for this service includes the cost of the satellite and an installation and maintenance fee of 30% of the cost of said satellite. Charges for setting a new satellite are made prior to satellite deployment. Once the Satellite is deployed it becomes your property and your responsibility.</t>
 <t id="11">Would you like to accept the agreement with Satellite Deployment Services?</t>
 <t id="12">Satellite Deployment Services is offering you the service of deploying an Advanced Satellite in every sector you enter. Once you accept our agreement, the service will start sending out ships to a central location in any sector you enter, once there they will deploy a new Advanced Satellite for you. If you currently have a satellite in that sector you will not be charged and no action will be taken. \n\n The fee(s) for this service includes the cost of the satellite and an installation and maintenance fee of 30% of the cost of said satellite. Charges for setting a new satellite are made prior to satellite deployment. Once the Satellite is deployed it becomes your property and your responsibility.\n\nShall we sign you up on our service?\n\n[select value="1"]Yes, sign me up[/select]\n[select value="2"]No, not today![/select]\n</t>
 </page>
 </language>
Last edited by TEKing66 on Wed, 11. Nov 09, 19:48, edited 4 times in total.
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

seems your getting the page id for the text file from a global varible, but your not setting that varible anywhere, so it wont exist
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

Ah-Hah!

Thanks Cycrow, can always count on you for a answer.

I'll make that change and post back if any other issues.
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

Well Cycrow that caught one problem. :)

But, I have another big bug somewhere. when I load my save game that I have for testing this. The script is creating 4 ships and two of them drop off satellites. I believe I my have a timing issue somewhere, or the correct variable isn't being passed along?

Could some one maybe confirm this?
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

OK, I have decided to cut this down into baby steps.

The code below should be doing two checks.
1: to see if a Satellite owned by the player exists.
2: to see is a ship is on the way to deliver on.

Now the only way I want it to continue with the script is for both checks to turn up 'null'. If either one fails this condition I want the script to just end.

Could someone please help me with this.

This is new code written from scratch. And every thing was working until I added the check for the existing ship.

Code: Select all

Script al.tek.SDS.Deploy.Event
Version: 0
for Script Engine Version: 44

Description
Handles the Advanced Satellite deployment event.
Arguments
Source Text

001   * Setup for creating the Satelliet Deployment Services Ship.
002   * ***Gather the required information.
003   $SDS.Name =  read text: page=8971 id=2
004   $SDS.Abbrev =  read text: page=8971 id=1
005   $SDS.Exist.Sat.Flags = [Find.Nearest]
006   $SDS.Exist.Ship.Flag = [Find.Nearest]
007   $SDS.Flags = [Find.Nearest]
008   $SDS.Sector = [PLAYERSHIP] -> get sector
009   $SDS.SectorRace = $SDS.Sector -> get owner race
010   * See if a satellite owned by the Player exists in sector.
011   $SDS.Existing.Satellite =  find ship: sector=$SDS.Sector class or type=All Satellites race=Player flags=$SDS.Exist.Sat.Flags refobj=[PLAYERSHIP] maxdist=100000 maxnum=1 refpos=[PLAYERSHIP]
012   * If player owned Sat exist, do nothing and end.
013   if $SDS.Existing.Satellite != null
014   * If no Sat exists, then do check for delivery ship.
015   else if $SDS.Existing.Satellite == null
016   * Check to see if a ship is on the way to deploy a Sat.
017   |$SDS.Exist.Ship =  find ship: sector=$SDS.Sector class or type=Military Transport race=$SDS.SectorRace flags=$SDS.Exist.Ship.Flag refobj=[PLAYERSHIP] maxdist=100000 maxnum=1 refpos=[PLAYERSHIP]
018   |$SDS.Exist.Ship.Name = $SDS.Exist.Ship -> get name
019   |write to player logbook $SDS.Existing.Satellite
020   |write to player logbook $SDS.Exist.Ship
021   * If not Sat, but a ship is found, then end.
022   |if $SDS.Exist.Ship.Name != null
023   |end
024   * If not Sat and no ship are found.
025   |if $SDS.Exist.Ship.Name == null
026   * *Find the nearest Trading Dock to the Player.
027   ||$SDS.Start.Station =  find station in galaxy: startsector=$SDS.Sector class or type=Trading Dock race=$SDS.SectorRace flags=$SDS.Flags refobj=[PLAYERSHIP] serial=null max.jumps=5 num=1
028   * *Create the ship, Name it, Give it a Pilot and ad it to the Trading Dock.
029   ||$SDS.Ship =  create ship: type=Military Transport owner=$SDS.SectorRace addto=$SDS.Start.Station x=0 y=0 z=0
030   ||$SDS.Ship -> set name to $SDS.Name
031   ||$SDS.PilotName = get random name: race=$SDS.SectorRace
032   ||$SDS.Ship -> set pilot name to $SDS.PilotName
033   * *Turn of the AI for the ship.
034   ||$SDS.Ship -> set race logic control enabled to [FALSE]
035   * *Move the ship into position: x= 0, y=1250, z=0
036 @ ||$SDS.Deploy.Position = $SDS.Ship -> move to position: x=0 y=1250 z=0 with precision 10 m
037   ||$SDS.Ship -> set command: [ACTION_IDLE]
038   * *Deploy the Advanced Satellite and give the Player control.
039   ||$SDS.Deployed.Satellite =  create ship: type=Advanced Satellite owner=Player addto=$SDS.Sector x=0 y=1000 z=0
040   * *Send the ship back to the Trade Dock.
041 @ ||= $SDS.Ship -> fly to station $SDS.Start.Station
042   * *And, just to cleanup, Destroy the ship.
043   ||$SDS.Ship -> destruct: show no explosion=1
044   |end
045   end
046   return null
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.
User avatar
LV
Sith Lord
Posts: 8255
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by LV »

your code may be correct but there's a few variables not needed from what i read

to find the sat

Code: Select all

001   ||$sat =  find ship: sector=$defined.sec class or type=Adv Sat race=$Sector.owner flags=null refobj=null maxdist=null maxnum=null refpos=null

in your code i have no idea where 'All Satellites' comes from you should be searching for ship type/adv sat

also flag find nearest to PLAYERSHIP means your ship must be in that sector.

ref object not needed if your just checking a sector for a playersat

max distance (needs to be from an object) so again must be within 10k of your ship for your code to work.

maxmum : use only for returning arrays for a search e.g. you have 5 sats in the sector, otherwise leave as null

refposition : does not work defining an object and also not needed.

search for the military transport is along the same lines.
LV's TC Scripts
Readme's For All My Scripts


I felt a great disturbance in the forum, Like millions of voices cried out in terror, then were silenced

si tacuisses, philosophus mansisses
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

the problem is your calling the timer script in the wrong place.

u have it in the "isenabled" event, which is called when ever the game updates the AL setting displays. That event is for returning the station of the plugin.

you need to add

Code: Select all

else if $al.Event == 'timer'
above where you call al.tek.satdeployservices.timer
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

Thanks LV, There is still a lot that I need to learn about this.

Edit -
The 'All Satellites' came from 'Select Object Class"
there are 3 options related to sats;
Navigational Relay Satellite
Advanced Satellite
All Satellites

Your info here takes me a step further.

I'd like to get this to either offer the service at a station or comm the player with an offer. Though at the moment I'm not sure which script I should put that in. I am thinking some where in the events script, or a script called by the events script.

My scripts for this project have changed from the original post. The following list are the names of my current working scripts with a description of my understanding of what each does;

1. al.plugin.tek.SatDeployServices

This declare Satellite Deployment Services as AL plugin.
It is where the .main script is loaded anlong with an relative 't' files.

2. al.tek.SDS.Main

Main script fot the Satellite Deployment Services AL plugin.
It tells the AL plugin is it should start or stop and keeps track of that state.

3. al.tek.SDS.Events

This handles any events the script makes happen and can call additional scripts if needed.

4. al.tek.SDS.Deploy.Event

This is an event that the scripts causes to happen. This code could have been placed with in my 'al.tek.SDS.Events' script. I decided to call it as an additional script as I may have others like this, i.e. another totally independant event that could be happening at the same time


Edit:
Thanks again Cycrow. I have completely re-written these scripts.
And it is working at this point. I will edit the original post to reflect the new code. Once I reworked the .main script using the AL Plugin templates things started to happen as expected.
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

Hey guys thanks for the help. It was much appreciated.

But, due to a discovery I made this evening I will be abandoning this project. The name of the in-game "service" this script would offer is already in use by another scripter. And it appears a good bit of what I was hoping to accomplish as well.

I apologize to all for any inconvenience.
And I apologize to TECSG, I wasn't aware that he was using the name "Satellite Deployment Services" in his Salvage Claim Software Mk.1 script package. This is called out in his t file 7074-L044 ID 25.

Again, my apologies to all.

Moderators you can lock this thread if needed.
My mods for X3TC & X3AP

Been with the X-series from the beginning. If it happens in the X_Universe I've been there done that several times over.

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”