[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 »

Code: Select all

Get ship array of race blah blah 

do your check here ... 

inc Counter 
end
Not quite sure what you mean here... where does inc counter go? Right at the end? Because that's what I'm making of it.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

EJ

Yes it goes just before the 'end'

and check the edit in my prev post.

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

Post by EmperorJon »

EDIT: Dumb problem. Inc is now in right place (NOT AS BELOW)

Everything else is the same. However, there still seems to be problems with my removal mechanisms...

AND. It only runs if the ship belongs to Pirates. I don't even get 'Done!' if not. It's like it's making a Pirates array... hmm. It says Pirates last on the array, would it be at the top? If so... array probs no doubt.

Code: Select all

001   $Races =  array alloc: size=0
002   append Argon to array $Races
003   append Boron to array $Races
004   append Split to array $Races
005   append Paranid to array $Races
006   append Teladi to array $Races
007   append Xenon to array $Races
008   append Yaki to array $Races
009   append Pirates to array $Races
010   
011   $RaceCount =  size of array $Races
012   $Counter = 0
013   while $Counter < $RaceCount
014   |$Race = $Races[$Counter]
015   |$M3s =  get ship array: of race $Race class/type=M3
016   |
017   |$Count =  size of array $M3s
018   |while $Count
019   ||dec $Count = 
020   ||$Ship = $M3s[$Count]
021   ||$Ship -> set name to 'Done!'
022   ||$Race = $Ship -> get owner race
023   ||$GCheck = $Ship -> get local variable: name='ej.weapon.change'
024   ||$Valid = [TRUE]
025   ||skip if $GCheck != [TRUE]
026   |||$Valid = [FALSE]
027   ||skip if $Race != Player
028   |||$Valid = [FALSE]
029   ||if $Valid
030   |||
031   |||$Ship -> set local variable: name='ej.weapon.change' value=[TRUE]
032   |||
033   * Not Pirate or Yaki M3 - Loses random amount of PBGs
034   |||$Ship -> set name to 'Checks'
035   |||$Amount = $Ship -> get amount of ware Plasma Burst Generator in cargo bay
036   |||if $Amount != 0 AND $Race != Pirates AND $Race != Yaki
037   ||||$AmountTake = $Amount + 1
038   ||||$Rand1 =  = random value from 0 to $AmountTake - 1
039   ||||$Take = - $Rand1
040   ||||= $Ship -> add $Rand1 units of Plasma Burst Generator
041   |||else if $Amount == 0
042   ||||display subtitle text: text='No PBGs onboard' duration=300 ms
043   |||end
044   |||
045   * Pirate or Yaki M3 - Loses new random amount of PBGs, divided by 2.
046   |||
047   |||$Amount = $Ship -> get amount of ware Plasma Burst Generator in cargo bay
048   |||if $Amount != 0 AND $Race == Pirates OR $Race == Yaki
049   ||||$AmountTake = $Amount + 1
050   ||||$Rand2 =  = random value from 0 to $AmountTake - 1
051   ||||$Take = ( - $Rand2 ) / 2
052   ||||= $Ship -> add $Rand1 units of Plasma Burst Generator
053   |||else if $Amount == 0
054   ||||display subtitle text: text='No PBGs onboard' duration=300 ms
055   |||end
056   |||
057   ||end
058   |end
059   end
060   inc $Counter = 
061   return null

Removed all the nasty gos and everything. You're right. I didn't need them. As for the problem, I have 1 more idea...
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren »

to start, swap lines 59 and 60 about

Code: Select all

59  inc $Counter =
60  end
MarCon
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Erm, you have to put the "inc $Counter" statement inside the loop, because you want to increment the counter value each time the loop body is finished once.

It's also good practice to count from top down. It only saves you one line of code, but it's much more common. ;)
Like this:

Code: Select all

$array = array alloc: size=5
$size = size of array $array
while $size
  dec $size =
  $someval = $array[$size]
  * Do stuff 
  = wait 1 ms
end
In this case you need to put the "dec $size" statement right before you first get the array value.

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

Post by EmperorJon »

Post above edited.

Anyway. Got it working in the there described way by putting the inc just after the loop starts... put it where Mark says and infinite. :wink:

As for Scrat, I usually use that loop. I used it before. It's easier.


EDIT: Don't panic, everythings works.

Well. Except, one little niggling fact.

I got the message saying the ships had no PBGs onboard.

They each had 8.

So. I create a ship which does have PBGs, but can't mount them (to see if they only work in the cargo bay but not installed)

Nothing. Not even a 'no PBGs' message.

Just the notification that the checks are done.

:evil:

I'm losing it here. Guess I've lost my begginer's luck and gone from a begginer to the helpless bit between that and actually understanding stuff.


EDIT2:

Well, fixed some things.

Also, noticed 2 interesting points:

1. I have 2 messages in the log saying 'Plasma Burst Generator' :?
2. I've created an Advanced Mambarracunova Raider


Next step is to remove the calculation and simply put remove a PBG. If it does, I know it's a dodgy calc, and not at all a general script layout prob. ect.

Thanks to all of you for all your help. This is why the Egosoft forums are such a great place.
______
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 »

Well.

Here's the working code. I got to the bottom of it eventually!

For all your references: To minus a ware and remove, you first have to minus install it! :wall: :lol:

Code: Select all

001   $Races =  array alloc: size=0
002   append Argon to array $Races
003   append Boron to array $Races
004   append Split to array $Races
005   append Paranid to array $Races
006   append Teladi to array $Races
007   append Xenon to array $Races
008   append Yaki to array $Races
009   append Pirates to array $Races
010   
011   $RaceCount =  size of array $Races
012   while $RaceCount
013   |dec $RaceCount = 
014   |$Race = $Races[$RaceCount]
015   |$M3s =  get ship array: of race $Race class/type=M3
016   |
017   |$Count =  size of array $M3s
018   |while $Count
019   ||dec $Count = 
020   ||$Ship = $M3s[$Count]
021   ||$Race = $Ship -> get owner race
022   ||$GCheck = $Ship -> get local variable: name='ej.weapon.change'
023   ||$Valid = [TRUE]
024   ||skip if $GCheck != [TRUE]
025   |||$Valid = [FALSE]
026   ||skip if $Race != Player
027   |||$Valid = [FALSE]
028   ||if $Valid
029   |||
030   |||$Ship -> set local variable: name='ej.weapon.change' value=[TRUE]
031   |||
032   * Not Pirate or Yaki M3 - Loses random amount of PBGs
033   * Minimum is half!
034   |||$Amount = $Ship -> get amount of ware Plasma Burst Generator in cargo bay
035   |||if $Amount > 0 AND $Race != Pirates AND $Race != Yaki
036   ||||$AmountTake = $Amount + 1
037   ||||$Minimum = $Amount / 2
038   ||||$Rand1 =  = random value from $Minimum to $AmountTake - 1
039   ||||$Take = - $Rand1
040   ||||= $Ship -> install $Take units of Plasma Burst Generator
041   ||||= $Ship -> add $Take units of Plasma Burst Generator
042   |||else if $Amount == 0
043   |||end
044   |||
045   * Pirate or Yaki M3 - Loses new random amount of PBGs, divided by 2.
046   * Only loses half of the random value.
047   |||$Amount = $Ship -> get amount of ware Plasma Burst Generator in cargo bay
048   |||if $Amount > 0 AND $Race == Pirates OR $Race == Yaki
049   ||||$AmountTake = $Amount + 1
050   ||||$Rand2 =  = random value from 0 to $AmountTake - 1
051   ||||$Take = ( - $Rand2 ) / 2
052   ||||= $Ship -> install $Take units of Plasma Burst Generator
053   ||||= $Ship -> add $Take units of Plasma Burst Generator
054   |||else if $Amount == 0
055   |||end
056   |||
057 @ |||= wait 5 ms
058   ||end
059   |end
060   end
061   return null
______
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 »

Well, as that seems working ish for now I've returned to my previous script with the RelVal problem, and solved the overflow.

Instead of RelVal x number / 1000s... whatever...

I got (RelVal/1000s) x (number/1000s)

Problem is, there's an empty array somewhere. I'm using the same style of array, to get wares of a ship. Problem is, the ships dead. I was wondering if it saved that data, as I've used the technique for position before, but I'm now guessing it doesn't. Which sort of throws out my entire script. You're paid an amount for the ship + an amount for onboard items... Any ideas on this guys?

(I know the problem is an empty array, I did a check: Get size of array, give money to player, no money)
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
Carlo the Curious
Posts: 16999
Joined: Mon, 5. Mar 07, 22:03
x4

Post by Carlo the Curious »

EmperorJon wrote:Well, as that seems working ish for now I've returned to my previous script with the RelVal problem, and solved the overflow.

Instead of RelVal x number / 1000s... whatever...

I got (RelVal/1000s) x (number/1000s)
Note that you've also introduced more rounding errors - few RelVals are exactly divisible by 1000, and for anything under 1000 (M5s) it will be zero.
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

By 1000 I didn't mean 1000.

The numbers are sometimes bigger.

Hm. Well, I can't think of any other way of doing it without serious rounding errors...

How many Decimal places does TC work to then if it'll round it to 0?
______
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 »

The numbers are sometimes bigger.
That's not better, it's worse. ;)
How many Decimal places does TC work to then if it'll round it to 0?
None. There are only integers.

So you'll have to use a different mechanism, like multiplying by 10000 and then dividing by your number.

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

Post by EmperorJon »

That's not better, it's worse.
I KNOW! :oops:
So you'll have to use a different mechanism, like multiplying by 10000 and then dividing by your number.
I DON'T KNOW! :wink:

It's all to confusing. I either get it competely innacurate and get rounding errors or it goes overflows.
factor = 80.7212
except for M6M, M7 & M7M: factor = 65.555784
(one-off exceptions are SS_SH_A_M1: factor = 49.892, SS_SH_A_M2 & SS_SH_T_M2: factor = 50.299)

Initial base ship price = factor * Production RelVal (NPC)
So I have to get 65555784 x 1000000
Hmmm. What about, half the relval then times it by... No.

Erg!?!
______
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 »

Why are you messing around with RelVals anyways?
You know that you can get the value of a ship simply by the standard command (although it's not really accurate)?

Code: Select all

$wtcode = [PLAYERSHIP] -> get ware type code of object
$price = get average price of ware $wtcode
If the multiplying-and-then-dividing method is right for you, depends on what you're doing. It works well for percentages, so instead of getting 60,8 (which is not possible in the game), you get 608.

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

Post by EmperorJon »

Why are you messing around with RelVals anyways?
You know that you can get the value of a ship simply by the standard command (although it's not really accurate)?
GRR! :lol:

I'll try that.

Anyone answer my previous question? About the array?
______
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 »

You mean this one?
Problem is, there's an empty array somewhere. I'm using the same style of array, to get wares of a ship. Problem is, the ships dead. I was wondering if it saved that data, as I've used the technique for position before, but I'm now guessing it doesn't. Which sort of throws out my entire script. You're paid an amount for the ship + an amount for onboard items... Any ideas on this guys?
When you save objects in arrays and the objects die, a null reference stays in the array, so no data is saved. If you want the data to be persistent, you have to save them seperately.

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

Post by EmperorJon »

Sorry, bad wording.

What I mean is:

I can use 'get postion as array' to get the position of a ship even after it's died. (An invincible model of it stays there until the script ends, quite funny if you put a wait it :lol: )

So, I can get an array for a ship which is dead. Called in a Killed signal.

If I do this for wares onboard as an array, it's empty.

Presumably because it's capable of getting the position of the 'husk', but not the stuff onboard. That's gone, lost into the depths of the program the moment the ship blows up.


So what's my alternative? :?

As for your previous point, yes you're right, and it's out a bit... 2 possible explainations. Price at shipyard is Max price not average? Price given on average is sell price?

Doesn't matter, as lon as they're all proportional out by a similar amount. I don't want the exact price any, but a fraction of it, 5th or something.
______
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 »

So, I can get an array for a ship which is dead. Called in a Killed signal.

If I do this for wares onboard as an array, it's empty.
That's interesting...
How did you connect the script to the signal (secondary or directly)?

But maybe this is also hardcoded and if so, there i nothing you can do.

As always, there are workarounds, like using SIGNAL_DAMAGED instead to save the wares into a local variable and retrieving that local variable in the SIGNAL_KILLED script. However, I don't know how reliable this is.

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

Post by EmperorJon »

Hmm.

Secondary.
______
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 just tried it and everything works fine.
I simply created two scripts, one which logs the amount of energy cells and another one which creates a ship in the playersector gives it 10 energy cells and connects SIGNAL_KILLED to the first script.

Killing the ship prints "10" into the player logbook.
It works with primary and secondary signals.

Are you using the right command to get the wares?

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

Post by EmperorJon »

I'll post the thing in a bit. Or PM it to you if that'd cause less trouble...
______
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”