Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove

Post by Cody »

CommRLock78 wrote:
What I have seems to work...
Here... have a cookie!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post 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)
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Scripters cove

Post 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)
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post 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)
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Scripters cove

Post 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).
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Scripters cove

Post 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.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

easy way to auto-prime equipment?

Post 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?
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

Not without a change to the trunk code, no.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: Scripters cove

Post 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:
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post 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?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post 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?
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Scripters cove

Post 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.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post 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.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2409
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Scripters cove

Post by Wildeblood »

Thank you, Tricky. Thank you, cim.
User avatar
Pleb
---- E L I T E ----
---- E L I T E ----
Posts: 908
Joined: Sun Apr 29, 2012 2:23 pm
Location: United Kingdom

Re: Scripters cove

Post 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? :?
Desktop PC: CPU: Intel i7-4790K Quad Core 4.4GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1080Ti RAM: 32GB DDR3

Laptop PC: CPU: Intel i5-10300H Quad Core 4.5GHz (Turbo-Charged) GPU: Nvidia GeForce GTX 1650 RAM: 32GB DDR4
Post Reply