[Discussion] Generic X3TC S&M questions II

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

User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Exactly what I meant by something stupid overlooked. :P

The thing is, it works for some of the ships... :S

EDIT: I knew something was wrong, that's my old snippet.

In my new one, I've got an array made of the ship TYPE which is transferred across and is the array read, and put in as a TYPE, not an object... ;) And I get 1 fighter.

No mammoths now it seems though. But only 1 fighter. The last in the array. So it's only counting down once... it's stuck somewhere... probably me messing up loops in loops.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

it's stuck somewhere... probably me messing up loops in loops.
If you mean this code snipped, then everything looks alright and the loop should iterate over the array elements correctly.

Still it's strange that you even get a fighter, because of the following lines you shouldn't get anything:

Code: Select all

033   ||$Rand =  = random value from 1 to 6 - 1
034   ||if $Ship == Mammoth
035   |||$Rand = 0
036   |||while $Rand 
So only if the ship is a Mammoth you "try" to create it. But if it's a Mammoth you set the random value to 0, so the condition "while $Rand" would directly fail.

Or was that not the snippet in question?

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

No need, I was just messing around there.

UniTrader fixed it, it was a stupid array mistake.

Very stupid. A 1 liner.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

And now Loops hate me again!

Code: Select all

001   send incoming message 'Removing ship!' to player: display it=[TRUE] 
002   $Ar = $sector -> get ship array from sector/ship/station 
003   $Count =  size of array $Ar 
004   add money to player: $Count 
005   while $Count 
006   |dec $Count = 
007   |$Ship = $Ar[$Count] 
008   |$Sup = $Ship -> get local variable: name='ej.military.support' 
009   |skip if $Sup != [TRUE] 
010   ||$Ship -> jump out of existence 
011   |send incoming message 'GONE' to player: display it=[TRUE] 
012   end 
013   return null
1 ship jumps. 1. You run it again and another one does. Some problem with the loop! I've added a wait in, no help.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Again, the loop is correct and the problem has to lie within the array (maybe the second ship is not in $sector) or the local variable 'ej.military.support' not being set to the correct value.

Code: Select all

009   |skip if $Sup != [TRUE]
010   ||$Ship -> jump out of existence 
You could also try another condition, because this one specifically tests for $Sup to be [TRUE]. Try this one:

Code: Select all

009 | skip if not $Sup
010 || $Ship -> jump out of existence
Btw: I'd always use "skip if not" to express "if", becuase "skip if not" can also be read as "do if".
Additionally it might be a good idea to change the text entry for "skip if not" to "do if" (Gazz did this iirc). This really helps code readability.
I've added a wait in, no help.
A wait would only help if the game freezes when executing your script.

Greetings,
ScRaT

EDIT: Maybe the problem also lies in the command "jump out of existence". Did you try to put a dummy command in there (maybe a log entry)? I never used the command, so I don't know how it behaves (although I'd assume it wouldn't stop your script).
Or might $Ship be even the object the script is running on?
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

EmperorJon wrote:And now Loops hate me again!

Code: Select all

001   send incoming message 'Removing ship!' to player: display it=[TRUE] 
002   $Ar = $sector -> get ship array from sector/ship/station 
003   $Count =  size of array $Ar 
004   add money to player: $Count 
005   while $Count 
006   |dec $Count = 
007   |$Ship = $Ar[$Count] 
008   |$Sup = $Ship -> get local variable: name='ej.military.support' 
009   |skip if $Sup != [TRUE] 
010   ||$Ship -> jump out of existence 
011   |send incoming message 'GONE' to player: display it=[TRUE] 
012   end 
013   return null
1 ship jumps. 1. You run it again and another one does. Some problem with the loop! I've added a wait in, no help.
i suggest creating a new script, which runs the command, jump out of existence.

then calling that script using START, otherwises the loop is going to get blocked by the command

also, u can simplfy that abit

Code: Select all

008   |skip if not $Ship -> get local variable: name='ej.military.support' 
009   ||START $Ship -> call script: 'my.jumpoutofexistence'
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

I can confirm the problem is Jump out of Existance. Doesn't seem to like running on more than 1 ship from the same script, so I started a script which jumps them out anywhere from 1s to 30s and started idle too, so when the command comes through they tottle around and flash out randomly. :)
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Are there any attack commands which get the ships to attack everything in a sector? Including stations?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Not a single command, but you could use an Egosoft script like "!ship.cmd.killenemies'.

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

That's what I meant. I didn't know if it included stations.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

I though it did, but I wasn't sure. Looking into the code, reveals the following lines:

Code: Select all

034   * -------------------------------------------------------------------------
035   * Targeting
036   * -------------------------------------------------------------------------
037   * find enemy in range.
038 @ |$enemy = [THIS] -> call script '!fight.targeting' :  the max scan range=$range  refpos array   x y z=$arefpos  Target Class=null
039   |
040   * Pirates target a station nearby if no other target
041   |if ! $enemy AND $ispirate
042   ||if not  = random value from 0 to 20 - 1
043 @ |||$enemy = [THIS] -> call script '!fight.targeting' :  the max scan range=5000  refpos array   x y z=$arefpos  Target Class=Station
044   ||end
045   |end
So, only pirates will attack stations and they'll only do that, if they didn't find any other target.
Unfortunately that's the way all fightscripts work...

It seems as if you had to write your own script or copy and modify this one to suit your needs.

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Is that the script? It'll make it easy for me to copy that and edit it, instead of having to unpack the vanilla one.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Is that the script?
The code I posted? It's a snippet from '!ship.cmd.killenemies'.
It'll make it easy for me to copy that and edit it, instead of having to unpack the vanilla one.
Well, that's no big problem, is it? Simply unpack the .pck and append .xml to the filename. Voilà, the script is unpacked.

EDIT: If I were you, I'd simply remove the $ispirate in

Code: Select all

041   |if ! $enemy AND $ispirate
Greetings,
ScRaT
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

I have some questions about mobile mining commands.

I'm new to X3 scripting and I want to try creating a mobile mining script. I've had a look at the default mining scripts but I'm having trouble getting things straight in my head. Could someone give me a brief overview of what the mining commands do since they aren't in the MSCI manual.

The default script uses the following commands

get debris count
get asteriod yield
get resource waretype of asteriod
has collectible rocks
Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler »

Hi All,

I’m having an issue with one of my scripts. For some reason Shipyards will not show any trade-able wares, stations or ships.

But the issue is random and doesn’t affect all shipyards and seems to hit a random times during the game.

I build and test my scripts/mods with no other mods/scripts that use custom stations or install custom stations or ships to shipyards.

The setup script I use checks the state of the al plug-in and adds & removes the custom docks.

Any help would be much appreciated as I’m close to pulling both scripts from release and calling it a day.

LA

Step one is to build am array holding the main races, then loop through each race:

Code: Select all

 $race.Array = create new array, arguments={Argon}, {Boron}, {Paranid}, {Split}, {Teladi}
  append {Terran} to array $race.Array
  $sr = size of array $race.Array
  while $sr > 0 
    dec $sr =
    $race = $race.Array[$sr]
    gosub Race.Shipyard.Sub
  end

Step two is to get all the shipyards of the race and loop through them and add/remove the custom dock depending on the al-plugin status.

Code: Select all

Race.Shipyard.Sub:
$shipyard.Array = get station array: of race $race class/type={Shipyard 2037}
$sy = size of array $shipyard.Array
while $sy > 0 
  dec $sy =
  $shipyard = $shipyard.Array[$sy]
  if $status 
    gosub Install.Sub
  else
    gosub Remove.Sub
  end
end
endsub
Step three is the add/remove bit. The temp.Array is just an array holding the sub type values of the custom docks which are saved within the al-plugin settings array:

Install:

Code: Select all

Install.Sub:
$s = size of array $temp.Array
while $s > 0 
  dec $s =
  $pm = $temp.Array[$s]
  $sub.type = get ware from maintype 5 and subtype $pm
  if not $shipyard->trades with ware $sub.type
    $shipyard->add product to factory or dock: $sub.type
    = $shipyard->add 1 units of $sub.type
  end
end
endsub
Remove:

Code: Select all

Remove.Sub:
$s = size of array $temp.Array
while $s > 0 
  dec $s =
  $pm = $temp.Array[$s]
  $sub.type = get ware from maintype 5 and subtype $pm
  if $shipyard->trades with ware $sub.type
    $shipyard->remove product from factory or dock: $sub.type
  end
end
endsub
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

I’m having an issue with one of my scripts. For some reason Shipyards will not show any trade-able wares, stations or ships.

But the issue is random and doesn’t affect all shipyards and seems to hit a random times during the game.
I've heard of that bug before and it seems to be a bug of the game. Saving and reloading the game solves it temporarily afaik.

Your script looks fine, that shouldn't be the problem.

@SlapNTickle
What exactly don't you understand about these commands?
They pretty much do exactly what you'd expect them to do. For example "has collectible rocks" returns [TRUE] if a sector has collectible rocks and [FALSE] otherwise.

Greetings,
ScRaT
Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler »

ScRaT_GER wrote: I've heard of that bug before and it seems to be a bug of the game. Saving and reloading the game solves it temporarily afaik.
:) Cheers ScRaT_GER, I'll do a bit more research, I'll be a lot happier knowing I'm not screwing up the game.

LA
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

ScRaT_GER

I suppose the main point of confusion is whether the 'debris' that is returned by the 'find debris' command is a single rock or a container for all the rocks a single big rock has been smashed into. The commands 'has collectible rocks' and 'get debris count' sound very container-ish.

I have the collect rock script working fine which simply loops while the debris has collectible rocks. The break rock script simply loops while the debris exists and shoots it until it has collectible rocks or ceases to exist.

The test mining script simply calls both the break and collect scripts while the debris exists.

- while debris exists
- call collect rock script -- returns when cargo bay full, or no more collectible rocks in 'debris'
- break if cargo bay full
- call break rock script -- returns if 'debris' has collectible rocks, or no longer exists
- loop

It should keep collecting and shooting the debris until all the rocks have been smashed and collected, but it doesn't, hence the confusion. Even after playing around with 'get debris count' I still don't know exactly what it's returning. An updated MSCI manual would be so very useful.

EDIT:
Ok, the break rock script will break rocks, but it never seems to return via the 'has collectible rocks' check, even if the rock it just smashed has clearly turned into a bunch of collectible rocks. It either exits because the debris ceases to exist, or it just sits there firing at nothing until I stop it. :evil:
Last edited by SlapNTickle on Tue, 17. Aug 10, 10:11, edited 1 time in total.
PolerBair
Posts: 3
Joined: Tue, 17. Aug 10, 03:11
x3tc

Post by PolerBair »

I'm sure this must have been asked a hundred times but for some reason searching for script editor returned no results at all.

How do I open the script editor in game?
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

SlapNTickle, The debris is basically like an asteroid field. Usually it has an invisible asteroid in the middle of the field, which is whats returns by the command.

so the other 2 commands should return if the field has any collectible rocks and how much debris there is.

PolerBair, have you activated in your game yet ?
if you have, u can find it in the global command console, or through any ships command console as well

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