[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

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

Post by SlapNTickle »

Thanks for the clarification Cycrow.

The value returned by 'get debris count', is that the number of breakable rocks in the field, or does it also include the collectible rocks?
The number of breakable rocks would make more sense but it never hurts to ask. :wink:

Also, does 'get asteriod yield' return the amount of minerals in the debris field or is it only applicable to the big asteroids?

EDIT
Is there a way to prevent the debris from respawning?
I personally don't like this and would prefer to clear sectors of debris and leave perpetual mining to the asteriods.
I'm currently using 'catch ware object' to grab the collectible rocks.
User avatar
eldyranx3
Posts: 2178
Joined: Sat, 14. Jan 06, 21:29
xr

Post by eldyranx3 »

What script controls checking to see if the player has a police license for the given race owner? I looked through the .pcks but I didn't see it.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

SlapNTickle wrote:Thanks for the clarification Cycrow.

The value returned by 'get debris count', is that the number of breakable rocks in the field, or does it also include the collectible rocks?
The number of breakable rocks would make more sense but it never hurts to ask. :wink:

Also, does 'get asteriod yield' return the amount of minerals in the debris field or is it only applicable to the big asteroids?

EDIT
Is there a way to prevent the debris from respawning?
I personally don't like this and would prefer to clear sectors of debris and leave perpetual mining to the asteriods.
I'm currently using 'catch ware object' to grab the collectible rocks.
i think get debris count is for the breakable rocks, althou not certain, my knowledge on the mining commands is limited, althou if you can find SymTec, hes the best one to ask about them

for respawning, the usual way to stop it with asteroids is to build a mine on them and destroy the mine, althou i doubt this would work with debris.
i guess u could just move them way of the ecliptic so they dont interfer with the sector thou
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

eldyranx3 wrote:What script controls checking to see if the player has a police license for the given race owner? I looked through the .pcks but I didn't see it.
there isn't a script that controls police license, what is it your trying to do ?
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

How about this command:

Code: Select all

<RetVar/IF> player has police licence for race <Var/Race>
@SlapNTickle

Try this command:

Code: Select all

<RefObj> -> disable ship rebuild
Afaik it works for stations, ships and as asteroids and thus, referring to Cycrow's explanation, most likely also for debris.
Also, does 'get asteriod yield' return the amount of minerals in the debris field or is it only applicable to the big asteroids?
The asteroid yield affects the output of an asteroid. So an asteroid with a yield of 60 will produce more effective than an asteroid with yield 5. I guess the same is true for debris.

Greetings,
ScRaT
User avatar
eldyranx3
Posts: 2178
Joined: Sat, 14. Jan 06, 21:29
xr

Post by eldyranx3 »

@ Cycrow:

I'm looking into adding the Terran Security License. I don't see anything in twares that would suggest hows its controlled, and I cant see any scripts that check for its presence and its consequences.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

its hardcoded, no way to add more, and no way to create new inventory wares

u could technically simulate it thou
User avatar
eldyranx3
Posts: 2178
Joined: Sat, 14. Jan 06, 21:29
xr

Post by eldyranx3 »

Through a AL plugin Im sure, but I think it'd be too CPU intensive for what it would offer, as there are no missions in Terran Space that need the scanner.

Thanks for the heads up!
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22438
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

no need for an AL plugin, just use signals.

use the SIGNAL_ATTACKED, and if the owner is terran remove the license
use the SIGNAL_KILLED, if in terran space and target is enemy, give bounty reward.

the main problem would be how to handle the ware, there are several ways to do this, but as you cant set an inventory ware, u cant make it display in the same place as other wares.

easiest i think would be to create a normal way and stick it the playership
ie, a global scripts that checks if the playership is changed, and moves the ware from the old to the new ship

Code: Select all

$playership = [PLAYERSHIP]
while [TRUE]
  wait 1000 ms
  if $playership != [PLAYERSHIP]
    $amt = $playership -> get amount of ware Terran Police Licence in cargo bay
    [PLAYERSHIP] -> add $amt units of ware Terran Police Licence
    $amt = - $amt
    $playership -> add $amt units of ware Terran Police Licence
    $playership = [PLAYERSHIP]
  end
end
could be an al timer scripts, or a global, AL slightly better i would think
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

Cycrow and ScRaT_GER

Thanks for the help guys, the scripts are coming together nicely.

Some more quick questions

1. My mobile miners launch Fighter Drones to smash the rocks. The normal Fighter Drones don't fire at the debris, while the Mk2 Fighter Drones merrily turn rocks into dust. They're both running the same script so I don't know what's going on. Any ideas? It's not a huge problem, I can simply require Fighter Drones be in the cargo bay, but create the Mk2 version when launching.

2. Is there anyway to determine the drones remaining energy?
If not, I'll try the 'get flight time' command since the drones last about 10 minutes before exploding. Is the return value in seconds?

3. How long does the debris usually take to respawn in a sector?
I want to clear a sector to see if it stays clear.

4. Because I'm using Fighter Drones to smash rocks I need to know if they get destroyed. Is this the correct command to use?

Code: Select all

$drone -> connect ship command/signal SIGNAL_KILLED to MyDroneDiedScript with prio 1
MyDroneDiedScript will be called when the drone is killed corrent?
Will the script be called when I destroy the drone with the 'destruct' command?
Logain Abler
Posts: 2255
Joined: Mon, 31. Oct 05, 08:44
x4

Post by Logain Abler »

SlapNTickle wrote:
4. Because I'm using Fighter Drones to smash rocks I need to know if they get destroyed. Is this the correct command to use?

Code: Select all

$drone -> connect ship command/signal SIGNAL_KILLED to MyDroneDiedScript with prio 1
MyDroneDiedScript will be called when the drone is killed corrent?
Will the script be called when I destroy the drone with the 'destruct' command?
I use this to capture killed drones in my SSDN script:

Code: Select all

 $drone->add secondary signal: signal={SIGNAL_KILLED}, script='script.name', prio=100, name='id.name'
The name section allows you to remove the secondary signal from the object if it’s no longer needed (I think).


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

Post by SlapNTickle »

Thanks Logain

Ok, now a stupid question thats probably been answered many times, but refuses to show up on a search.

Local and global variables.
I want to make sure I understand properly before I start flinging them about.

Code: Select all

get local variable: name=<varname>
Returns the value of <varname> which is stored on the calling object. If the variable doesn't exist, NULL is returned.

Code: Select all

set local variable: name=<varname> value=<value>
Creates a variable called <varname> on the calling object and sets its value to <value>.

Questions

1. If I call the 'set' command three times using the same <varname>, will I end up with three copies of the local variable attached to the object, or only one copy updated three times?
--- I assume I get one copy of the variable whos value is updated each time I call 'set'.

2. I need to 'get' the variable value every time I want to use it?
--- I assume this is correct.

3. I need to 'set' the variable value every time I want to change it?
--- I assume this is correct.

4. What about arrays?
--- I assume 'get' returns an array ptr which should allow me to directly alter the local array.
--- I assume 'set' would attach the array to the calling object.
--- I assume replacing one array with another would destroy the old and attach the new.

5. How long do the local variable last?
--- I assume the object would retain its local variables until it's destroyed.

6. Global variable behave the same way?
--- I assume this is correct.

Do I pass :P
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Do I pass
Yes.

Just to clarify:
3. I need to 'set' the variable value every time I want to change it?
--- I assume this is correct.
This is correct, but you don't need to do it with arrays. As you pointed out, arrays are treated as pointers, so you directly change the underlyling array and thus don't need to 'set' the variable.

Greetings,
ScRaT
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

As a general piece of advice, use secondary signals if you can, as there can only be one signal.killed (and the stock scripts already use that)

Also the call order is...
secondary signals (by order of addition?)
Then the primary signal




w.r.t Variables
Local variables, are variables on an object, ($obj->get local variable: name=<varname>) (i.e. they are like properties)
And on any error (e.g. doesn't exist, object doesn't exist / what ever) it returns null (as with most functions)

And yes you are correct on the set local variable as well


A1. calling set repeatedly just over writes the values (if you think about it... how can you differentiate value1 from value2/3 given that there is only get variable by name?)

A2. A3. a4
Yes. But just to confuse you, arrays are not value type variables, but are reference types. So if you modify the array, the value of the local variable changes as well.
e.g.
$array = new array size aloc: 0
this ->set local variable name="myarray" value = $array
* at this point the localvar myarray, has value array(0)
append value="stuff" to array $array
* the local variable still references the exact same array, but the array is now array(1){"stuff"}

q4. Explain what you mean by "replacing" an array?
assuming my above code, doing something like $array = $newarray, would NOT change the local variable.

The only way to make a local variable reference a different array, would be to explicitly call the function
$this-> set local variable name="myarray" value=$newarray

a5. Until the object dies, or you replace the local var with another set command

a6. Yes, except obviously, they dont live on an object, which obviously means they don't disapear when the "object" dies






On arrays and value and reference types (I'm using CLR i.e. vb/c# terminology)
Value type variables, are variables that hold actual information
Reference type variables are variables that just point to some data "some where" (in your memory.. probably... I would image)

Examples of values: Integers, (Strings in c# are apparently not value types, but they behave as value types)
Example of reference type: ships/ingame objects, arrays, complex types. e.g. If you have a variable of a ship, and change it's hull, then obviously, in game, and in your script the hull has changed. As both the game, and your array just reference the ship. Similarly with arrays, if you have multiple pointers to an array, changing the array in one pointer will show the change in all the pointers.


Hope this hasn't confused you... much...
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

ScRaT_GET and s9ilent

Exactly the kind of clarification I was looking for, thank you. :D

s9ilent
q4. Explain what you mean by "replacing" an array?
assuming my above code, doing something like $array = $newarray, would NOT change the local variable.

The only way to make a local variable reference a different array, would be to explicitly call the function
$this-> set local variable name="myarray" value=$newarray
The second part of your answer is what I meant.
If the local variable points to $array and I change it to point to $newarray, what happens to $array?
I assume the script engine knows to get rid of it if its not being used anymore.
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

All "private" variables in a script are disposed when the script ends
Local/global variables are disposed when you call the set local/global variable to null

(AFAIK, unless x3 has some cooler garbage collector, which I doubt given that you can go to and go sub)
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

s9ilent
All "private" variables in a script are disposed when the script ends
Local/global variables are disposed when you call the set local/global variable to null
An example.

- The miner creates an array ( $target.array ) and makes it local.
- The miner then gets debris in range and loops thru it looking for rocks to break.
- For each rock that must be broken, it creates an array ( $target ) which has 2 members and adds it to $target.array.

So $target.array is an array of array ptrs.
I assume the $target arrays are stored on the object when added to $target.array, otherwise they would be lost when the script ends.
If that's correct, setting any entry in $target.array to NULL would destroy the $target array that entry references.

Correct?
As a general piece of advice, use secondary signals if you can, as there can only be one signal.killed (and the stock scripts already use that)

Also the call order is...
secondary signals (by order of addition?)
Then the primary signal
I assume the killed signal script is called before the object is actually destroyed so it can access local variables etc.
I assume the arguments are the same as the default signal scripts.

Phew, slowly getting there. :lol:
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

On signals, yes, the scripts run first, then the object is physically removed.
Having said that, signals should NOT have waits in them, and should execute and return immediately, or else the object wont actually die until the signals have finished.
If you need waits, then just make your signal call a global script instead.
via $nullobject = null
START $nullobject -> call script xyz ...


On arrays
That is mostly correct.
It removes the reference to the $target, from the $target.array
However, if for some reason you have another array/variable to referenced the old $target directly, it (the other variable/array) would continue to still reference the old target.

e.g. if i have a $target which is an array(1) {"stuff"}
and I got
$target.array[0] = $target
$myvariable1 = $target

Then I went $target.array[0] = null
$myvaraiable1 is still array(1){"stuff"}
Even if I went $target = null
$myvaraible1 is still array(1){"stuff"}
SlapNTickle
Posts: 14
Joined: Wed, 16. Nov 05, 04:59
x3tc

Post by SlapNTickle »

s9ilent

Ok, I think my brain has caught up. :D

Code: Select all

find <value> in array: <value>
I assume this command scans the array for the value and returns TRUE/FALSE.

Code: Select all

get index of <value> in array <var/array> offset <var/number> + 1
I assume this command scans the array for the value and returns its index, but I'm not sure what the offset is for?
What is returned if the value isn't found?

We could really do with an updated MSCI manual.
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

There is the xai corp wiki msci hand book thingy. Which is like a x3 scripting wiki
http://www.xai-corp.net/msci-handbook
However, it doesn't get updated too often, (but it does get updated, and it does have an x3tc edition, although, tbh with the exception of a few entries I put in there, the x3tc entries are mostly stubs) but usually the more techy questions end up in this forum any way (e.g. arrays value/reference variables)


Find value, yes returns true false




The offset means start searching from xxx onwards,
e.g. offset 1, means start searching from 1 + 1 onwards
(The +1 confuses most people, but many just assume the reason for it is so you can do:

-$index = get index of value $value in array $array offset $index + 1
while $index != -1
-dowork
-$index = get index of value $value in array $array offset $index + 1
end

as that would iterate over all $value's in the array
(Note, this command returns -1 on null/error, as 0 is ~= null)

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