[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
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 25130
Joined: Sun, 2. Apr 06, 16:38
x4

Post by X2-Illuminatus »

Bishop149 wrote:Where's the teleport command?
General Object Commands -> <RetVar/IF> move player to ship <Var/Ship>: Teleport=<Var/Number>
Nun verfügbar! X3: Farnham's Legacy - Ein neues Kapitel für einen alten Favoriten

Die komplette X-Roman-Reihe jetzt als Kindle E-Books! (Farnhams Legende, Nopileos, X3: Yoshiko, X3: Hüter der Tore, X3: Wächter der Erde)

Neuauflage der fünf X-Romane als Taschenbuch

The official X-novels Farnham's Legend, Nopileos, X3: Yoshiko as Kindle e-books!
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

Ok cool, I found that one but it initially wanted me to select an existing ship.

I guess I'd have to create one and assign it as the variable first. . .
I'll play about with it, might be more complex than I first thought. .
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

I am writing part of a script in which there's a small chance a passenger will mutiny and take over the players ship.

Code below, i've not filled in all the details of various irrelevant variables.

Code: Select all

$ship = get player ship
$passengers = [PLAYERSHIP] -> get passenger array
$pasarrsiz = size of array $passengers
$mutiny = = random value from 0 to 100 - 1
if $mutiny > 98
  $mutineer1 = = random value from 0 to $pasarraiz - 1
  $mutineer2 = $passengers [$mitineer]
  [PLAYERSHIP] -> set owner race to Neutral Race
  = $mutineer2 -> move passenger to ship [PLAYERSHIP]: set passenger as pilot = [TRUE]
  $suit= create ship: type= Space Suit owner= Player addto= location x=x y= y z= z
  = move player to ship $suit: Teleport= [FALSE]
  = $ship -> fly to sector "somewhere"
end
return null
This works fine, player is kicked out, random passenger is assigned as pilot of the ship the player no longer owns and off the ship heads towards "somewhere"

Then the ship blows up. . . . .
Why? Is this some default behaviour of ships not assigned a task?
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

GoD often kills such ships.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
Sorkvild
Posts: 3445
Joined: Thu, 8. Jun 06, 14:07
x3tc

Post by Sorkvild »

Has anyone made a script that allows player to buy "illegal ware production license" for millions resulting in non aggressive actions against player owned stations like distillery (argon space) ?
Elite Dangerous| I survived the Dragon Incident ... then I took an arrow to the knee
We want the Boron back!
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

I made that a few weeks ago! :O

http://forum.egosoft.com/viewtopic.php?p=3492944

No DL though.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
Sorkvild
Posts: 3445
Joined: Thu, 8. Jun 06, 14:07
x3tc

Post by Sorkvild »

EmperorJon wrote:I made that a few weeks ago! :O

http://forum.egosoft.com/viewtopic.php?p=3492944

No DL though.
Seriously, that's really great .

When this will be available ? I' d like to give a try :)
Elite Dangerous| I survived the Dragon Incident ... then I took an arrow to the knee
We want the Boron back!
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

If you wish I can email it
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz »

Bishop149 wrote:This works fine, player is kicked out, random passenger is assigned as pilot of the ship the player no longer owns and off the ship heads towards "somewhere"

Then the ship blows up. . . . .
The only odd thing I see (beyond having no task) is that you alter the race of PLAYERSHIP while the player is still in it.

There is an instruction to turn off "AI behaviour" of a ship. You may want to turn that off in case this was a former AI ship that the player stole. The AI might take control back.
Alternatively, you clone the entire ship. Then the AI has no say in the matter.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

Gazz wrote:



The only odd thing I see (beyond having no task) is that you alter the race of PLAYERSHIP while the player is still in it.

There is an instruction to turn off "AI behaviour" of a ship. You may want to turn that off in case this was a former AI ship that the player stole. The AI might take control back.
Alternatively, you clone the entire ship. Then the AI has no say in the matter.
Yeah I initially did it the other way round and ended up in a spacesuit that wasn't mine!
I guess I could get round it by simply using the variable $ship instead, might be a bit cleaner.

I'll have a play around and see if I can stop it blowing.
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
HotSake
Posts: 472
Joined: Sun, 3. Jan 10, 22:15
x3tc

Post by HotSake »

So set the owner of the space suit to Player.
User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz »

No, this is not about the space suit. You create it as player race and that's that.

What you were doing there is
- set PLAYERSHIP to neutral race,
- teleport the player out of a ship that did not even belong to him any more.

That looks mighty weird, considering I see no particular reason for doing it that way.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

Yeah I see no reason why it wouldn't work.

The point I was making is that as soon as I teleport the player out of the ship then its no longer [PLAYERSHIP] and changes you subsequently make to [PLAYERSHIP] will refer to the spacesuit. . . that's why I did it that way round.

I could get round it by bunging playership in another variable and the changing it.

Another (VERY basic) question.
I have a variable that is returning a shiptype eg "Nova" . . . I need to use the output in a command that will only accept a string.

I can't for the life of me work out how to convert the variables output to a string!
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

Typically, string conversion is done implicity when required


Otherwise:
(General commands)
$string = springtf '%s': $yourship nulll null null null <- sort of explicit conversion
Alternatively, there is probably a general objects commands -> get name


or $string = $yourship + '' (empty string) <-implicit conversion



*edit* after a quick check
$string = $efobjectyourship -> get name
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

Thanks

$string = sprintf '%s': $yourship nulll null null null <- sort of explicit conversion

That seemed to work!

But now I have a problem with an loop!
The following script it called to run on an Advanced Satellite:

Code: Select all

$type = get global variable: name='ship.to.alert'
$range = [THIS] -> get scanner range
$sector = [THIS] -> get sector
$target = null
while $target == null
 $target =  find ship: sector=$sector class or type=$type race=null flags=null refobj=[THIS] maxdist=$range maxnum=null refpos=null
 if $target != null
  $ID = $target -> get ID code
  $alert = sprintf: pageid=7022 textid=1, $ID, $target, $sector, $type, null
  send incoming question $alert to player: callback='a.test2'
 end
end
return null
What I want it to do is if a ship of the specified type (sent from another script) is in scanner range to send a message to the player.

Else to check again until one is found repeat ad infinitum util one's found.
It crashes the game every time I enter a shiptype that isn't in range initally.

I've tried messing around with various flow controls, entering a delay . . . nothing seems to work.

I suspect a fairly fundamental hole in my knowledge here!

To try and avoid asking quite so many questions here are there any good help resources around?

I am currently using a mix of these three to try and learn:
- http://cycrow.thexuniverse.us/scripts/help/index.html (couple of basic examples from Cycrow)
- http://www.xai-corp.net/msci-handbook/e ... ions/x3tc/ (list of command, with explanations)
- The MSCI Handbook

What they tell me is all good but they are woefully incomplete. . . 80% of my problems they can't answer. Any better ones around?
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
User avatar
Gazz
Posts: 13244
Joined: Fri, 13. Jan 06, 16:39
x4

Post by Gazz »

This script is guaranteed to lock up X3 if no target is found immediately.
However, if it crashes the game, like you said, you have a completely different problem, possibly passing an illegal argument or shiptype to the search.

It's a loop without a wait. It will not hand control back to any other script in the game.
Don't worry. Everyone has to do that... once. =P

It will also terminate immediately after reporting a ship once because
while ($target == null)
becomes FALSE.

No search flags at all and as a maxnum of desired results you also have null.
In a literal interpretation (and you know, computers...) you are asking for null results.

I would also put the reading of the global var into the loop so you can skip the (somewhat CPU intensive) object search if no object is currently looked for.
That would also be a good way for an uninstall tie in.
Something like ...

while $type != "terminate"
wait 20000 (you need need neeeeeeed this)
$type = get global variable: name='ship.to.alert'
skip if type
continue

stuff in the loop

end
destroy THIS


Get in the habit of putting the wait directly after any while. Not only is it less likely you forget about it or that it gets skipped by conditions, it also allows you to use continue, which is extremely useful.
My complete script download page. . . . . . I AM THE LAW!
There is no sense crying over every mistake. You just keep on trying till you run out of cake.
Bishop149
Posts: 7232
Joined: Fri, 9. Apr 04, 21:19
x3

Post by Bishop149 »

Thanks I wondered if it might need a wait!

The script is a work in progress I know it will abort after it finds one target. . .

There's lots still to do on it. . how to stop it alerting for the same ship over and over, how to stop it, how to manage multiple instances etc etc.

I tend to script one problem at a time. . . .
"Shoot for the Moon. If you miss, you'll end up co-orbiting the Sun alongside Earth, living out your days alone in the void within sight of the lush, welcoming home you left behind." - XKCD
User avatar
s9ilent
Posts: 2033
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent »

@Bishop149

Recommendations:



$type = get global variable: name='ship.to.alert'

//You may way to check that type, is indeed of datatype objecttype/objectclass (or null if that is a valid input for your needs)
I'm going to assume it should be either:
{DATATYP_OBJCLASS}
{DATATYP_SHIP}
(Thou I don't know if shiptypes, are also objclasses i.e. is typeof(argon nova: maintype x, subtype y) also an typeof(m3)? )


$range = [THIS] -> get scanner range


$sector = [THIS] -> get sector
use [SECTOR] instead, it is identical to the above, saves a line (and uses 1 less variable)


$target = null
while $target == null

As gazz said, you need a wait instruction
@Gazz 'Don't worry. Everyone has to do that... once. =P ' Once heh... if only :S:P


$target = find ship: sector=$sector class or type=$type race=null flags=null refobj=[THIS] maxdist=$range maxnum=null refpos=null
if $target != null
$ID = $target -> get ID code
$alert = sprintf: pageid=7022 textid=1, $ID, $target, $sector, $type, null
send incoming question $alert to player: callback='a.test2'
end
end
return null




Other random thoughts:
Have you considered changing your targets from an array of types? (or will your script only ever need to search for 1 type?
If you only ever need to search for 1 type, why not pass the type in as an argument instead of as a global var?

Consider changing structure to:
while condition
wait xxxx
if (some failing condition, e.g. target == null)
-continue
end

So you stick the wait at the top, so the loop is "continue" safe.
And the use of continues, rather than massive if blocks
Iseeyouseemeseeyou
Posts: 29
Joined: Thu, 10. Feb 11, 18:20

Post by Iseeyouseemeseeyou »

Either I'm just totally blanking or this is total newb moment:

wtf do I need to do to run scripts?

I do Global Commands -> Script Editor -> create a script -> back to script editor & keep hitting "enter" but it just keeps taking me back to edit the script & not doing anything.
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

r. :lol:
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______

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