Satellite Deployment Services - Code trashing at your leasure!

The place to discuss scripting and game modifications for X³: Reunion.

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

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

Satellite Deployment Services - Code trashing at your leasure!

Post by TEKing66 »

This script is working, a little flakey here and there. But, working none the less. As this is my first script, I would like some input from people more experienced.

First, here is what I want it to do. Ask the player if they want to sign up for program. If they do, charge the average price of an Advanced Satellite + 30% and "Satellite Deployment Services" will place one for you.

I know it works up to two jumps from a trade dock, I'm starting my ship out from the nearest one. Once it leaves it flies out or if need be ju,ps to the sector to place the sat and "drops" it off. Then, it returns to the trade dock and goes away.


I need to work on the player input. (still figuring things out.)
I'm still testing, so still finding bugs. If you have some time to kill take a look and let me know if you might change something and way (that way I learn from my mistake).

There is a script being called, it creates my ship, names it, kits it out and returns it as a variable. I can post that, or any of the associated AL files that go with it, feel free to ask.

Here is me code so far......
and here it is after some changes to eliminate duplicate code.....

Code: Select all

Script al.tek.satdeployservices.timer
Version: 1
for Script Engine Version: 32

Creates a ship, names it and has it deploy Satellite.
1: al.PluginID , Var/String , 'AL Plugin ID' 
2: al.State , Var/String , 'AL State Array' 
3: Ship.ID , Var/String , 'Ship ID' 

 001 $AL.STATE.VERSION = 0
 002 $AL.STATE.ENABLED = 1
 003 
 004 if $al.State[$AL.STATE.ENABLED]
 005  load text: id=8971
 006  $Ship.ID =  read text: page=8971 id=2
 007  $sat = Advanced Satellite
 008  $sector = [PLAYERSHIP] -> get sector
 009  $race = $sector -> get owner race
 010  $flags = [Find.Nearest]
 011  $station = Trade Dock
 012  
 013  $pos =  array alloc: size=0
 014  append 0 to array $pos
 015  append 0 to array $pos
 016  append 0 to array $pos
 017  
 018 * See if satellite already exist.
 019  $satellite =  find ship: sector=$sector class or type=Nav. Satellite race=Player flags=$flags refobj=[PLAYERSHIP] maxdist=100000 maxnum=1 refpos=$pos
 020  
 021 * If no satellite exist, then order one to be setup.
 022  if not $satellite
 023   $pcredits = get player money
 024   $cost = get average price of ware Advanced Satellite
 025 * Total cost to install satellite is equal to the cost of the Sat plus 30%.
 026   $totalcost = $cost + ( $cost / 3 )
 027   if $pcredits < $totalcost
 028    $message = 'Not enought credits to have the satellite deployed for you.'
 029    play sample: incoming transmission 1361, from object $Ship.ID
 030    write to player logbook $message
 031   else if $pcredits >= $totalcost
 032    $totalcost = - $totalcost
 033    add money to player: $totalcost
 034    
 035 * Find the Trade Center to buy the Satellite from.
 036    $tradecenter =  find station in galaxy: startsector=$sector class or type=$station race=null flags=$flags refobj=[PLAYERSHIP] serial=null max.jumps=5
 037    $trade.dock.sector = $tradecenter -> get sector
 038    
 039 * Create the delevery ship.
 040    if not $deliveryship == $Ship.ID
 041     @ $deliveryship = [THIS] -> call script 'al.tek.SDS.ship.builder' :  Ship ID=$Ship.ID  Delivery Ship=$deliveryship  Trade Center=$tradecenter
 042     
 043 * Issue the command to fly to the deployment location.
 044     $deliveryship -> set race logic control enabled to [FALSE]
 045     
 046     skip if $sector == $trade.dock.sector
 047       = $deliveryship -> use jump drive: target=$sector
 048     @ = $deliveryship -> move around 3000 ms
 049     @ $Deploy.Location = $deliveryship -> move to position: x=100 y=500 z=0 with precision 10 m
 050     $deliveryship -> set command: [ACTION_IDLE]
 051 * Deploy the satellite.
 052     $sat =  create ship: type=Advanced Satellite owner=Player addto=$sector x=0 y=500 z=0
 053 * Then have him fly home.
 054     @ = $deliveryship -> move around 3000 ms
 055     skip if $sector == $trade.dock.sector
 056      = $deliveryship -> use jump drive: target=$trade.dock.sector
 057 *$Home.Sector = $deliveryship -> fly to sector $trade.dock.sector
 058     @ = $deliveryship -> fly to station $tradecenter
 059 * Destroy ship to cleanup.
 060     $deliveryship -> destruct: show no explosion=1
 061     set global variable: name=$Ship.ID value=$ShipID
 062    end
 063   end
 064  end
 065 end
 066 return null

Last edited by TEKing66 on Wed, 12. Dec 07, 18:54, edited 1 time 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.
eladan
Posts: 7168
Joined: Sat, 7. Jan 06, 16:01
x4

Post by eladan »

This is only to work in the sector the player is currently in? I hate to give you the runaround, but if that's the case, then it would be better if it was a command rather than an AL plugin. The AL plugin would be better for keeping a network of sats in place, but that doesn't appear to be what you're trying to do here(?)

You've duplicated a fair bit of code from 50-78 - you could fix that with a couple of 'skip if $sector == $trade.dock.sector' commands in front of the use jumpdrive commands.
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

It could be made to keep a network in place, hadn't really put much thought into that.

Will look into getting rid of the duplicate code. Thanks for the input.
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.
eladan
Posts: 7168
Joined: Sat, 7. Jan 06, 16:01
x4

Post by eladan »

Just for clarification, my assumption of what it's currently doing is that the AL plugin starts as disabled? You then have some command or message getting input from the player about putting a sat in sector? Which enables the AL plugin? Am I close?

If that's the case, what happens when the player changes sector? As coded currently, it will keep placing satellites in each sector the player passes through after the initial input, unless you have something in place to switch it off again.

That's pretty much why I was saying that if it's meant to place a sat once only, it would be better as a command - AL plugins are more useful for keeping a process in place rather than for one off situations.

Hope that gives some idea why I said that?
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

At the moment, it is starting enabled. I need to add to code to get user input.
Once that is in, I am wanting the player to be asked if they want to sign up on the program. If yes then keep the script enabled, if no disable it.

It currently places a satellite in the sector that the player is in, when he enters a new sector a satellite gets placed there, and on and on. The check at the first of the script looks to see if a satellite is already there, if not then it goes to work.

If I wanted it to maintain a satellite network. Would I need to build a list of sectors known to the player? Then, have it check for satellites in the sectors on this list?
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
Carlo the Curious
Posts: 16999
Joined: Mon, 5. Mar 07, 22:03
x4

Post by Carlo the Curious »

Minor comment - if I remember rightly Nav Sat Mk2 is a child of Nav Sat, so a find on Nav Sat should find either/both.
TEKing66
Posts: 601
Joined: Thu, 10. Nov 05, 18:44
xr

Post by TEKing66 »

Hey guys, I've made the suggested changes. Thanks for the tip Carlo, I took out the second sat check and it works like it did with it. No need to check for both types.
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³: Reunion - Scripts and Modding”