Page 1 of 1

Java script question - help, please!

Posted: Fri Jun 26, 2009 3:55 pm
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

Posted: Fri Jun 26, 2009 5:18 pm
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...

...

Posted: Fri Jun 26, 2009 11:53 pm
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

..

Posted: Sun Jun 28, 2009 5:34 pm
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

Posted: Sun Jun 28, 2009 8:40 pm
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.

Posted: Sun Jun 28, 2009 9:28 pm
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?