Java script question - help, please!

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

Moderators: winston, another_commander

Post Reply
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

Java script question - help, please!

Post by Lestradae »

:?

I have hacked/created two equipment items with which's java scripts I am partially unhappy because I want them to be sellable and this is not working as intended.

The first .js should do the following:

If the player ship has "EQ_COMBAT_COMP" installed then "player.ship.reticleTargetSensitive = true" should be the case.

If the player ship has the above not installed (because it was never bought, is damaged or was re-sold), then "player.ship.reticleTargetSensitive = false" should be the case.

The second .js should do:

If the player ship has "EQ_GALACTIC_HYPERDRIVE_2" installed, then ...

"this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour
player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_ALL_SYSTEMS_REACHABLE"

... should be the case.

If the player ship doesn't have this installed (same as above, because it was never bought, is damaged or was re-sold), then ...

"this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour
player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_STANDARD"

... should be the case.

Could someone help me with this or even provide simple java scripts that do this for me?

Would be very grateful for any help :D

Cheers

L
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The event functions you want are this.playerBoughtEquipment = function(equipment) triggered when the player buys a piece of equipment (identified in the parameter equipment, this.equipmentDamaged = function(equipment) and this.equipmentDestroyed = function(equipment) for when it gets damaged or destroyed/sold respectively.

By using these functions you can set or change the parameters (very much along the lines that the original equipment items do).

If you're still stuck let me know and I'll script it for you, just not now as I'm sat at Geneva Airport waiting for a plane...
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

...

Post by Lestradae »

Thanks, T, be sure I'll come back to you about that :twisted:

Will be on holiday for two weeks, too, so I hope all will be well in Geneva!

Cheers

L
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post by Lestradae »

Then this here should work?!?

Code: Select all

this.playerBoughtEquipment = function(equipment)
{
    if(equipment == "EQ_COMBAT_COMP")
    {
        player.ship.reticleTargetSensitive = true
    }
}

this.equipmentDamaged = this.equipmentDestroyed  = function(equipment)
{
    if(equipment == "EQ_COMBAT_COMP")
    {
        player.ship.reticleTargetSensitive = false
    }
}
... and this here, too:

Code: Select all

this.playerBoughtEquipment = function(equipment)
{
    if(equipment == "EQ_GALACTIC_HYPERDRIVE_2")
    {
        this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour
        player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_ALL_SYSTEMS_REACHABLE"
    }
}

this.equipmentDamaged = this.equipmentDestroyed  = function(equipment)
{
    if(equipment == "EQ_GALACTIC_HYPERDRIVE_2")
    {
        this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour
        player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_STANDARD"
    }
}
Hope for answers, I am absolutely noob again with the .js :oops:

Yes? No? Got something wrong/missing?

Cheers

L
User avatar
Nemoricus
---- E L I T E ----
---- E L I T E ----
Posts: 388
Joined: Mon May 18, 2009 8:51 pm

Post by Nemoricus »

Order of operations problem, I think.

this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour should go after player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_STANDARD".

Other than that, looks good.
Dream as if you'll live forever
Live as if you'll die tomorrow
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

It probably also needs a:

Code: Select all

this.reset = function() 
{ 
    if(player.ship.hasEquipment ( "EQ_COMBAT_COMP")) 
    { 
        player.ship.reticleTargetSensitive = true 
    } 
} 
You must also check on reset as the property reticleTargetSensitive will not be stored in the save file.

But why invent the wheel by creating existing equipment?
Post Reply