Get free amount on stations

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

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

Post Reply
Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Get free amount on stations

Post by Nicoman35 » Tue, 1. Jul 14, 14:47

I have a question regarding this command:

Code: Select all

$free.amount = [THIS] -> get free amount of ware $ware in cargo bay
For ships this works ok, but:
If I want to have the free amount of a ware on a station (in this case the Xenon hub), the amount shows always 20 to me. Even if the hub is able to store 100+ of a ware, like 5MW shields.
Anyone knows why?

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Tue, 1. Jul 14, 15:22

It works fine on factories. Docks, it gets a little funny.

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Tue, 1. Jul 14, 18:44

Yea, docks gets funny. Any way to get correct amount?

User avatar
JSDD
Posts: 1378
Joined: Fri, 21. Mar 14, 20:51
x3tc

Post by JSDD » Tue, 1. Jul 14, 18:54

... in case the ""get-amount"-instruction returns the correct amount, you could do something like this:

Code: Select all

$Amount.On.Station = $Station -> get amount of $Ware in cargo bay
while $Station -> add 1.000.000 units of $Ware
end
$Amount.Max = $Station -> get amount of $Ware in cargo bay
$Amount.To.Remove = $Amount.On.Station - $Amount.Max
= $Station -> add $Amount.To.Remove units of $Ware
return $Amount.Max
To err is human. To really foul things up you need a computer.
Irren ist menschlich. Aber wenn man richtig Fehler machen will, braucht man einen Computer.


Mission Director Beispiele

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Tue, 1. Jul 14, 23:18

Many thanks, JSDD! Here is my tested and working version:

Code: Select all

if [THIS] -> is of class [Ship]
$free.amount = [THIS] -> get free amount of ware $ware in cargo bay
else
$Amount.On.Station = [THIS]-> get amount of ware $ware in cargo bay
while [THIS] -> add 100000 units of $ware
end
$Amount.Max = [THIS]-> get amount of ware $ware in cargo bay
$free.amount = $Amount.Max - $Amount.On.Station
= [THIS] -> add $free.amount units of $ware
end
The variable $free.amount will contain the free amount of a certain ware no matter if a ship or a station is examined. Once again, many thanks!! :thumb_up:

User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 » Wed, 2. Jul 14, 02:03

Nicoman35 wrote:Many thanks, JSDD! Here is my tested and working version:

Code: Select all

if [THIS] -> is of class [Ship]
$free.amount = [THIS] -> get free amount of ware $ware in cargo bay
else
$Amount.On.Station = [THIS]-> get amount of ware $ware in cargo bay
while [THIS] -> add 100000 units of $ware
end
$Amount.Max = [THIS]-> get amount of ware $ware in cargo bay
$free.amount = $Amount.Max - $Amount.On.Station
= [THIS] -> add $free.amount units of $ware
end
The variable $free.amount will contain the free amount of a certain ware no matter if a ship or a station is examined. Once again, many thanks!! :thumb_up:
I would add another check in there, as the command works fine on Factories

Code: Select all

if [THIS]->is of class [Ship]
   * Do it the normal way
else if [THIS]->is of class [Factory]
   * Do it the normal way
else
  * we are a ..somthing else..: do it the hard way.
end
also when you call = [THIS] -> add $free.amount units of $ware
you may need to first negate $free.amount in order for it to actually remove the wares you just added (or reverse the math) - then negate again before returning
[ external image ]
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

User avatar
JSDD
Posts: 1378
Joined: Fri, 21. Mar 14, 20:51
x3tc

Post by JSDD » Wed, 2. Jul 14, 02:44

<=> - (x - y) = + (y - x) ;)

... to be frank, i would also replace the while-loop with a:

Code: Select all

= $Station -> add 2.147.483.647 units of $Ware
<-- why that ?!
--> because you cant "trust" some instructions
// example: try the "get-true-amount"-instruction on npc-ships to find out how many lasers arent installed :roll: => doesnt function !!!
To err is human. To really foul things up you need a computer.
Irren ist menschlich. Aber wenn man richtig Fehler machen will, braucht man einen Computer.


Mission Director Beispiele

Nicoman35
Posts: 681
Joined: Thu, 17. Nov 05, 13:12
x3tc

Post by Nicoman35 » Wed, 2. Jul 14, 08:02

Gentlemen, thanks for your inputs. This is the newest version. I hope I didn't miss anything....:)

Code: Select all

if [THIS] -> is of class [Dock]
  $Amount.On.Station = [THIS]-> get amount of ware $ware in cargo bay
  = [THIS] -> add 2147483647 units of $ware
  $Amount.Max = [THIS]-> get amount of ware $ware in cargo bay
  $free.amount = $Amount.Max - $Amount.On.Station
  $remove.amount = -$free.amount
  = [THIS] -> add $remove.amount units of $ware
else
  $free.amount = [THIS] -> get free amount of ware $ware in cargo bay
end

Post Reply

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