Page 58 of 118

Re: Scripters cove

Posted: Sat Jan 19, 2013 11:49 pm
by Cody
CommRLock78 wrote:
What I have seems to work...
Here... have a cookie!

Re: Scripters cove

Posted: Sun Jan 20, 2013 2:17 am
by Wildeblood
CommRLock78 wrote:
cim wrote:
CommRLock78 wrote:
system.ID = -1 for interstellar, right?
Yes, though system.isInterstellarSpace is perhaps a better test.
What I have seems to work (so far :P) - I'm not sure how to implement system.isInterstellarSpace as it is Boolen
Boolean :D Yes. Also galaxyNumber is a global variable, no need to find it in system.info.galaxyID.

Code: Select all

if (!system.isInterstellarSpace && system.ID === 138 && galaxyNumber === 0 && system.planets.length < 5)

Re: Scripters cove

Posted: Sun Jan 20, 2013 2:46 am
by CommRLock78
Wildeblood wrote:
Boolean :D Yes. Also galaxyNumber is a global variable, no need to find it in system.info.galaxyID.

Code: Select all

if (!system.isInterstellarSpace && system.ID === 138 && galaxyNumber === 0 && system.planets.length < 5)
Thanks for clearing that up Wildeblood. I think I'll implement that bit of code :).

It appears that '!' is 'false' or 'not', so if I were to be checking to see if I was in interstellar space (i.e. testing if the code system.isInstellarSpace were true) I'd just leave out the '!' ? (i.e., no '!' in system.isInstellarSpace)

Re: Scripters cove

Posted: Sun Jan 20, 2013 4:22 am
by Wildeblood
CommRLock78 wrote:
Wildeblood wrote:
Boolean :D Yes. Also galaxyNumber is a global variable, no need to find it in system.info.galaxyID.

Code: Select all

if (!system.isInterstellarSpace && system.ID === 138 && galaxyNumber === 0 && system.planets.length < 5)
Thanks for clearing that up Wildeblood. I think I'll implement that bit of code :).

It appears that '!' is 'false' or 'not', so if I were to be checking to see if I was in interstellar space (i.e. testing if the code system.isInstellarSpace were true) I'd just leave out the '!' ? (i.e., no '!' in system.isInstellarSpace)
Yes again, but in this case I don't think you need to be checking it at all. As you said, in interstellar space system.ID will be -1, not 138. Thargoid's advice was to make sure you're in system space before checking system.planets.length - you're already doing that.

My theory with these multi-part conditional tests, which I got from Capt. Murphy, is that they are most efficient if you test the most likely failures first. Hence check system.ID, which only has a 1/256 chance of passing, before galaxyNumber, which has a 1/8 chance (and don't check anything you don't really need to).

Code: Select all

if (system.ID === 138 && galaxyNumber === 0 && system.planets.length < 5)

Re: Scripters cove

Posted: Sun Jan 20, 2013 5:42 am
by CommRLock78
Wildeblood wrote:
Yes again, but in this case I don't think you need to be checking it at all. As you said, in interstellar space system.ID will be -1, not 138. Thargoid's advice was to make sure you're in system space before checking system.planets.length - you're already doing that.

My theory with these multi-part conditional tests, which I got from Capt. Murphy, is that they are most efficient if you test the most likely failures first. Hence check system.ID, which only has a 1/256 chance of passing, before galaxyNumber, which has a 1/8 chance (and don't check anything you don't really need to).

Code: Select all

if (system.ID === 138 && galaxyNumber === 0 && system.planets.length < 5)
Thanks for the advice :), and I'd like to thank you, Cmd. Cheyd, Thargoid, and Cim for my first lesson in javascript, I have a new respect for OXP creators that write these scripts - JS is quite a bit different from anything my limited knowledge is used to (essentially BASIC and Matlab :P).

Re: Scripters cove

Posted: Sun Jan 20, 2013 8:05 am
by Tricky
I would also delete the shipWillLaunchFromStation event function. One less event to fire in your OXP. Deleting it will also stop any code that resets variables and such like from occuring more than once when you launch from the station then re-dock (maybe you forgot something) and then re-launching.

Code: Select all

this.shipWillLaunchFromStation = function (station) {
    delete this.shipWillLaunchFromStation;

    /* Rest of your code here. */
    ...
};
Note: That event (and all other events) will be redefined when you start a new game or load a new commander. In other words, all scripts are re-loaded.

easy way to auto-prime equipment?

Posted: Mon Jan 21, 2013 4:07 pm
by GGShinobi
I'm using the great missile spoof.oxp. I really like it, it's awesome, but it works a little bit "too well" for my taste. So in order to slightly increase the difficulty, I would like to have to launch the ECM and the spoof myself - the missile-spoof currently does all this automatically.

Since it is not easily possible to determine which ship launched an ECM, and therefore not easy to write a script that launches the missile spoof if it was the player who activated the ECM, I thought about making the missile spoof a primable equipment instead. But switching through 10 or more primable equipments in the heat of combat while a missile is inbound is perhaps to much of a rise in difficulty :P So I thought it would be nice if it was possible to auto-prime / automatically select the missile spoof as soon as a missile is launched upon the player's ship, and perhaps reset it to the previously selected equipment when the danger has been averted.

Is there a clean and easy way to achieve this?

Re: Scripters cove

Posted: Mon Jan 21, 2013 4:08 pm
by Thargoid
Not without a change to the trunk code, no.

Re: Scripters cove

Posted: Mon Jan 21, 2013 4:35 pm
by GGShinobi
Thargoid wrote:
Not without a change to the trunk code, no.
Thargoid, thanks for the answer. Ok, so I guess I have to live with priming it before I can use it. After all, it's a though space out there. :lol:

Re: Scripters cove

Posted: Tue Jan 22, 2013 1:54 am
by Wildeblood
How can I find if there is space in the ship's safe to buy the sub-tonne precious cargoes? Using this will turn over the cargo in the hold:-

Code: Select all

	if (player.ship.cargoSpaceAvailable > reserveSpace)
		{
		// Find something to buy.
		}
	if (player.ship.cargoSpaceAvailable < reserveSpace + 1)
		{
		// Find something to sell.
		}
- but what can I use instead of cargoSpaceAvailable for the safe?

Re: Scripters cove

Posted: Tue Jan 22, 2013 2:44 am
by Wildeblood
How can I position an object on a direct line between two other objects? Let's say I have objects playerShip, enemyShip and mysteryAsteroid, how do I position mysteryAsteroid so it is obscuring the player's view of enemyShip?

Re: Scripters cove

Posted: Tue Jan 22, 2013 3:18 am
by Tricky
Wildeblood wrote:
How can I position an object on a direct line between two other objects? Let's say I have objects playerShip, enemyShip and mysteryAsteroid, how do I position mysteryAsteroid so it is obscuring the player's view of enemyShip?

Code: Select all

mysteryAsteroidPosition = Vector3D.interpolate(player.ship.position, enemyShip.position, 0.5);
system.addShips("mysteryAsteroidRole", 1, mysteryAsteroidPosition, 0)
Places the asteroid 1/2 way between the player and the enemy. Increase the number 0.5 to place the asteroid closer to the enemy.

Re: Scripters cove

Posted: Tue Jan 22, 2013 8:00 am
by cim
Wildeblood wrote:
- but what can I use instead of cargoSpaceAvailable for the safe?
Have a look at the this._hasSpaceFor function in Resources/Scripts/oolite-contracts-cargo.js

Yes, there are separate safes for all three cargoes, and you can't use space in one to store the others.

Re: Scripters cove

Posted: Tue Jan 22, 2013 4:44 pm
by Wildeblood
Thank you, Tricky. Thank you, cim.

Re: Scripters cove

Posted: Thu Jan 24, 2013 8:39 pm
by Pleb
Quick question, I'm trying to use the new allowOfferShip function to make a ship only available if a mission variable is set to a specific value and the player is in an anarchy system. Is this even possible? :?