Page 21 of 118

..

Posted: Fri Mar 19, 2010 11:42 pm
by Lestradae
Ahruman wrote:
Lestradae wrote:
Sorry if that detail is still not absolutely clear to me, but I can have both a death action and a ship script in the same entry and both will work
No. If there’s a ship script, it overrides any _actions.
Commander McLane wrote:
Concerning the overriding: If there is a shipDied event-handler in the ship script, it will override the death_actions in the shipdata. If no shipDied exists, it can't override anything, can it? Therefore the death_actions will be executed.
Wrong. The death_actions (and setup_actions, launch_actions, and script_actions) are run by the default ship script, oolite-default-ship-script.js. If you have a custom ship script, it replaces the default ship script completely.
Hurray. It's not often that it really pisses me off when I was right. This is one of these occasions :?

I can't have a ship with both Griff's exploding thingies and a witty remark at its demise then. Great :(

Re: ..

Posted: Sat Mar 20, 2010 2:05 am
by Kaks
Lestradae wrote:
I can't have a ship with both Griff's exploding thingies and a witty remark at its demise then. Great :(
You can! You just need to have exploding thingies & witty remarks written both in javascript. Just drop the legacy stuff.

Re: ..

Posted: Sat Mar 20, 2010 7:26 am
by Lestradae
Kaks wrote:
Lestradae wrote:
... both Griff's exploding thingies and a witty remark at its demise ...
You can! You just need to have exploding thingies & witty remarks written both in javascript.
Yeah, but you know how many ships are in there ... I will have to understand how you "sum up" something like that in java script then :?
Kaks wrote:
Just drop the legacy stuff.
I'm in the process of doing just that ... of appoximately 390 scripts, below 20 legacy ones are left.

..

Posted: Sat Mar 20, 2010 7:41 am
by Lestradae
OK, now to something completely different on the field of stumbly nearly-first steps in java script.

I am attempting to create scripts that make HUDs or cockpits buy- and sellable.

If you sell a HUD, you are supposed to drop back to the standard one. If you buy a new ship, your hud should transfer with you.

I try to do that via three java scripts, one for buying, one for selling and one for setting up the HUD of choice.

In the equipment.plist, I am setting up a piece of equipment to buy a specific hud and one for _SALE.

They look like this:

Buying ...

Code: Select all

this.playerBoughtEquipment = function(equipment)
        {
        switch(equipment)
                {
                case "EQ_BWEEDFALCON_HUD":
                        {
                        missionVariables.bweed-falconhud = 1;
                        player.ship.hud = "bweed-falconhud.plist";
                        return;
                        }

                case "EQ_CONDOR_HUD":
                        {
                        missionVariables.condorhud = 1;
                        player.ship.hud = "condorhud.plist";
                        return;
                        }
                }
        }
Selling ...

Code: Select all

this.playerBoughtEquipment = function(equipment)
        {
        switch(equipment)
                {
                case "EQ_BWEEDFALCON_HUD_SALE":
                        {
                        missionVariables.bweed-falconhud = null;
                        player.ship.hud = "hud.plist";
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD");
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD_SALE");
                        player.credits += 5000;
                        return;
                        }

                case "EQ_CONDOR_HUD_SALE":
                        {
                        missionVariables.condorhud = null;
                        player.ship.hud = "hud.plist";
                        player.ship.removeEquipment("EQ_CONDOR_HUD");
                        player.ship.removeEquipment("EQ_CONDOR_HUD_SALE");
                        player.credits += 2000;
                        return;
                        }
                }
        }
Setup ...

Code: Select all

this.startUp = this.reset = function()
        {
        if(missionVariables.bweed-falconhud == 1)
                {
                player.ship.hud = "bweed-falconhud.plist";
                }
        if(missionVariables.condorhud == 1)
                {
                player.ship.hud = "condorhud.plist";
                }
        }
Will this work? Happy for feedback.

Posted: Sat Mar 20, 2010 8:15 am
by Thargoid
Problem I can see with that is if you buy a ship with a HUD already as part of it's set-up (shipdata.plist). Then you will have a new HUD but no way to sell it (as you won't know you have it by the scripting - you won't have the equipment item).

You can get around that with the world script event that the player has bought a new ship ( playerBoughtNewShip ) and a check as to what HUD is then active, and awarding suitable equipment as required.

Should work, although if a new HUD comes along for which no equipment exists then it'll screw things up.

k

Posted: Sat Mar 20, 2010 8:54 am
by Lestradae
Thargoid wrote:
Problem I can see with that is if you buy a ship with a HUD already as part of it's set-up (shipdata.plist). Then you will have a new HUD but no way to sell it (as you won't know you have it by the scripting - you won't have the equipment item).
Is that so? The way I read it, if you have a ship with a HUD already as part of it's set-up in the shipdata.plist, the scripts I wrote will initially do nothing with that ... except if you buy another HUD, then it should override this and set the bought hud.

One thing I could imagine would be that if you sell a bought HUD the ship would first drop back to the default HUD (as the script explicitly does this after a _SALE) and when you reload the game you would have the shipdata set-up HUD back, suddenly ...

Is there a logical error in there somewhere:

Ship with preinstalled HUD -> Buy new HUD -> mission variable set and HUD switched to new one ...

Restart/reload game -> mission variables are saved, so the new HUD is still set up by the set-up script (third above) ...

Later you sell the new HUD -> mission variable set back to null and HUD to Oolite default -> for the rest of this session you should have the Oolite default HUD ...

Restart/reload game -> mission variables set to null, so no HUD is set up, also not the default one -> you get the preinstalled HUD back

Now a bit :?

Posted: Sat Mar 20, 2010 11:09 am
by Thargoid
I was meaning more that you couldn't sell the HUD your new ship came with, as your script wouldn't know you had it. But if you bought a HUD, then later a new ship that came with its own HUD, your script would still have you owning (and being able to sell) the first HUD.

As I mentioned you could work around it using the playerBoughtNewShip event. But it would probably be simpler to just forget selling HUDs and just concentrate of buying them, then most of the problems go away.

Posted: Sat Mar 20, 2010 11:10 am
by Eric Walch
You don't need the mission variables to check for the hud. The way you programmed it you can directly ask for the equipment.

One bug is with ships with custom huds of their own. When you sell the special huds those ships end up with the default hud. It would be better to store the name of the original hud on startup, like

Code: Select all

this.startUp = this.reset = function() 
        { 
	     this.originalHud = player.ship.hud;
        if(player.ship.hasEquipment("EQ_BWEEDFALCON_HUD")) 
                { 
                player.ship.hud = "bweed-falconhud.plist"; 
                } 
        if(player.ship.hasEquipment("EQ_CONDOR_HUD")) 
                { 
                player.ship.hud = "condorhud.plist"; 
                } 
        }

this.playerBoughtEquipment = function(equipment) 
        { 
        switch(equipment) 
                { 
                case "EQ_BWEEDFALCON_HUD_SALE": 
                        { 
                        player.ship.hud = this.originalHud; 
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD"); 
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD_SALE"); 
                        player.credits += 5000; 
                        return; 
                        } 

                case "EQ_CONDOR_HUD_SALE": 
                        { 
                        player.ship.hud = this.originalHud; 
                        player.ship.removeEquipment("EQ_CONDOR_HUD"); 
                        player.ship.removeEquipment("EQ_CONDOR_HUD_SALE"); 
                        player.credits += 2000; 
                        return; 
                        } 
                } 
        }

Posted: Sat Mar 20, 2010 12:21 pm
by Eric Walch
Thinking about my last message I realised it still has a bug. When two scripts change the hud, the second one that runs at startup stores the wrong hud as the original one. With the current code I saw no solution for prefenting this problem.

The only solution would be a command to reset the hud to its default value. So I just made a new commit. Starting with rev 3069 , setting the hud to null like in: "player.ship.hud = null", will reset the hud to the one originally defined for that ship.

..

Posted: Sat Mar 20, 2010 8:07 pm
by Lestradae
Eric Walch wrote:
The only solution would be a command to reset the hud to its default value. So I just made a new commit. Starting with rev 3069 , setting the hud to null like in: "player.ship.hud = null", will reset the hud to the one originally defined for that ship.
Ah, very cool. That's a solution. I assume the "setting plus selling" script from you above should then look like this, uniting all three scripts of mine into a single one:

Code: Select all

this.startUp = this.reset = function()
        {
        if(player.ship.hasEquipment("EQ_BWEEDFALCON_HUD"))
                {
                player.ship.hud = "bweed-falconhud.plist";
                }
        if(player.ship.hasEquipment("EQ_CONDOR_HUD"))
                {
                player.ship.hud = "condorhud.plist";
                }
        }

this.playerBoughtEquipment = function(equipment)
        {
        switch(equipment)
                {
                case "EQ_BWEEDFALCON_HUD":
                        {
                        player.ship.hud = "bweed-falconhud.plist";
                        return;
                        }
                case "EQ_CONDOR_HUD":
                        {
                        player.ship.hud = "condorhud.plist";
                        return;
                        }
                case "EQ_BWEEDFALCON_HUD_SALE":
                        {
                        player.ship.hud = null;
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD");
                        player.ship.removeEquipment("EQ_BWEEDFALCON_HUD_SALE");
                        player.credits += 5000;
                        return;
                        }
                case "EQ_CONDOR_HUD_SALE":
                        {
                        player.ship.hud = null
                        player.ship.removeEquipment("EQ_CONDOR_HUD");
                        player.ship.removeEquipment("EQ_CONDOR_HUD_SALE");
                        player.credits += 2000;
                        return;
                        }
                }
        }
Yes?

That way, I also wouldn't need to use the playerBoughtNewShip event anymore.

Posted: Sat Mar 20, 2010 10:21 pm
by Thargoid
You can also remove the this.reset too (just leave it as this.startUp = function() ), as that no longer exists in 1.74.

The other problem you may have is your HUD getting damaged in combat (unless you want to add something to show somehow a damaged version with missing functionality or something).

..

Posted: Sat Mar 20, 2010 10:48 pm
by Lestradae
Thargoid wrote:
The other problem you may have is your HUD getting damaged in combat (unless you want to add something to show somehow a damaged version with missing functionality or something).
Well, the damaged HUD would give no change except a temporary revertion to the standard HUD, wouldn't it?

And at the next station a HUD repair would be offered I assume, allowing to re-set the old status quo.

To show a damaged HUD in case of the equipment damaged is an interesting idea. Will think about that one.

Posted: Sun Mar 21, 2010 9:35 am
by Thargoid
I meant if you're having the HUD as a piece of equipment, then it will be "available" for damage during combat.

Either then it should be self-repairing (which makes little sense) or visibly change somehow and/or lose some of its capability to reflect the damage (yes it would be repairable at the next docking, subject to whatever tech level you assign it).

I would say reverting to the original HUD in case of damage isn't the way to go, as it doesn't make any kind of practical sense (a new HUD for me is essentially ripping out and replacing the dashboard of your ship - the old one isn't physically there any more), but then I don't see the need for having HUDs as equipment in the first place to be honest.

..

Posted: Sun Mar 28, 2010 10:54 pm
by Lestradae
Would it be possible via java script to create an entry on the missions page giving the datum as "1st of January 3125" or so for the Oolite "Galactic Mean Time" start date and then upgrade that, so that the datum is visible also?

I think it should be possible, not sure if I'd try to have a go at it.

Re: ..

Posted: Mon Mar 29, 2010 9:50 am
by another_commander
Lestradae wrote:
Would it be possible via java script to create an entry on the missions page giving the datum as "1st of January 3125" or so for the Oolite "Galactic Mean Time" start date and then upgrade that, so that the datum is visible also?

I think it should be possible, not sure if I'd try to have a go at it.
Use the JavaScript Date object. In the example below, whenever the player launches, the current date (starting from 21 Mar 3125) appears on the screen. 21 Mar 3125 corresponds to 2084004 and the date is calculated based on days passed since. I'll leave the mission screens part to you.

Code: Select all

this.shipWillLaunchFromStation = function()
{
	var testDate = new Date();
	var daysPassed = clock.days - 2084004;    // 2084004 is the first day in Oolite
	
	testDate.setFullYear(3125, 2, 21);                  // start date is 21 Mar 3125 - note: January is month 0
	testDate.setDate(testDate.getDate() + daysPassed);  // calculate new date at time of launch
   testDate.setHours(clock.hoursComponent);             // make hours match ship's clock
   testDate.setMinutes(clock.minutesComponent);             // make minutes match ship's clock
	testDate.setSeconds(clock.secondsComponent);             // make seconds match ship's clock
	
	player.commsMessage(testDate);
}