HUD scripting example

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

Moderators: winston, another_commander

User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

cheers A_C, i wasn't sure if one would override the other.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

HUD tests

Post by Killer Wolf »

Okay, been giving this a test run.

when i dock i change to my trading hud, when i launch i swap to my normal hud - great.

the bit about low energy : it seems very slow to trigger, and once it does it doesn't change back. i thought the script was continually being looked at and the damaged hud would only appear during the low energy state, but i take it i have to add another line saying "if energy > 50 use the normal hud"?

can't get my combat hud to work. the examples quoted previous, i didn't know where to add in the hud statement, so instead i just put

{
if (player.alertHostiles = 1)
{
player.ship.hud = "dbcombathud.plist";
}
}

am i doing that wrong? cos it don't work (just tried putting "== 1" in the test too, cos i spotted a log error which it fixed). i tried shooting a station - cops attacked me, it didn't change. i hyperspaced to Xeesle, attacked a trader who turned red and attacked me, it didn't change. i hyped in on another run, got jumped by a pirate escort, it didn't change :-(
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

player.alertHostiles is a boolean (yes/no), so just remove the ==1 completely.

For the Aquatics Guardian system I use something similar:

Code: Select all

if(player.alertCondition == 3 && player.alertHostiles && !missionVariables.aquatics_guardianActive)
Basically alertCondition == 3 means your ship is at red alert and player.alertHostiles being true means that it's got something around that's hostile. Drop the mission variable bit (that's just a check whether the guardians are already active or not) and use something similar.

And yes, once your energy is back up you will need to do something else to change your HUD back again.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

Many thanks. i read about it being a Boolean but (being totally JS ignorant) i thought you'd still have to specify if you were looking for a true/false/1/0 off it. i'll give it a retry later.

tell you what though, it might be a fairly minorish cosmetic change, but going from a specific docked hud to an in-flight one upon launching really adds to the game, for me.

ta!
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

right : bollocks.
can some clever JS person point out my stupidity w/ the following please.

this.shipDockedWithStation = function()
{
player.ship.hud = "dbtradinghud.plist";
}

this.shipWillLaunchFromStation = function(stationLaunchingFrom)
{
player.ship.hud = "dbnormalhud.plist";
}


// The below method has not been tested at all, might as well not compile, shown as quick'n'dirty example
this.shipBeingAttacked = function()
{
if (player.ship.energy < 150)
{
player.ship.hud = "dbsnafuhud.plist";
}
}


this.hudThing = function()
{
if (player.alertCondition == 3)
{
player.ship.hud = "dbcombathud.plist";
}
// else
// {
// player.ship.hud = "dbnormalhud.plist";
// }
}


the stuff down to the energy test was posted here, and works fine. the other stuff i tried to make up, and flatly does not work. it originally didn't have the "this.hudThing" in, then i thought it needed something like that judging by the previous examples. this shows the commented-out Else leg to try and simplify matters, and it still won't play :-(

nowt in the logs saying "hah you suck!" so i'm assuming it's all syntactically ok? and yes, the hud plist names are not typoed.

cheers
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6671
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Killer Wolf wrote:

Code: Select all

this.hudThing = function()
{
    if (player.alertCondition == 3)
    {
        player.ship.hud = "dbcombathud.plist";
    }
//	else
//	{
//		player.ship.hud = "dbnormalhud.plist";
//	}
}
the stuff down to the energy test was posted here, and works fine. the other stuff i tried to make up, and flatly does not work. it originally didn't have the "this.hudThing" in, then i thought it needed something like that judging by the previous examples. this shows the commented-out Else leg to try and simplify matters, and it still won't play :-(

nowt in the logs saying "hah you suck!" so i'm assuming it's all syntactically ok? and yes, the hud plist names are not typoed.
Well, the this.hudThing is not defined anywhere, this is why it does not run. The other functions (this.shipBeingAttacked, this.shipDockedWithStation etc.) all refer to JS handlers, whose names are defined inside the core game code. As an example, when the player is about to launch, Oolite will try to find if there is a script function referring to the shipWillLaunchFromStation handler and if it finds it, it will execute its contents. Thus, you need to know which handlers are recognizable by Oolite and the wiki contains such a list (can't access it from here atm, so I cannot link to it). In any case, hudThing is not a valid handler. I believe you are looking for the alertConditionChanged one.
User avatar
JazHaz
---- E L I T E ----
---- E L I T E ----
Posts: 2991
Joined: Tue Sep 22, 2009 11:07 am
Location: Enfield, Middlesex
Contact:

Post by JazHaz »

another_commander wrote:
Thus, you need to know which handlers are recognizable by Oolite and the wiki contains such a list (can't access it from here atm, so I cannot link to it).
I think this is the list you are referring to:

http://wiki.alioth.net/index.php/Oolite ... t_handlers
JazHaz

Gimi wrote:
drew wrote:
£4,500 though! :shock: <Faints>
Cheers,
Drew.
Maybe you could start a Kickstarter Campaign to found your £4500 pledge. 8)
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

As A_C ninja'd me (in a role-reversal for him I guess ;) ), I'll just add that the event functions that the game uses are here in the wiki.

As he says, if you replace this.hudThing = function() with this.alertConditionChanged = function() you should see more:

Code: Select all

this.alertConditionChanged = function(newCondition, oldCondition)
{
        if (player.alertCondition == 3 && player.alertHostiles) 
    { 
        player.ship.hud = "dbcombathud.plist"; 
    }
}
I think the newCondition and oldCondition parameters are new (I don't remember them being there last time I looked at the wiki page), so you could probably replace player.alertCondition with newCondition in the if statement.

Editted to add - if you don't put the && player.alertHostiles in you'll get the combat HUD whenever you go to red alert (e.g. if you sunskim). The addition is a logical AND with the property that you're under alert due to hostiles. You can see a full list of the player propertieshere, also in the wiki.

Oh and also to add "damn, double-ninja'd!"
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

oops, stupid me thought it could be a user-defined name to describe a function :-(

cheers all, i'll give that a bash tonight.
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 »

Killer Wolf wrote:
oops, stupid me thought it could be a user-defined name to describe a function :-(

cheers all, i'll give that a bash tonight.
You can define any function name yourself, but someone has to call those functions. The predefined function names are called by Oolite when they exist. Self defined function names have to be called by other parts from your script itself.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

In any case I'd definitely put an else with 'normalhud.plist' like

Code: Select all

  else
   {
      player.ship.hud = "dbnormalhud.plist";
   } 
otherwise you get the combat hud with the first hostile(s) - as you want it to do - but then it never reverts back to the original hud once no hostiles are present...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

thanks all, i'll be giving that a blast in a mo.

naffing new-fangled javascript - why we can't have PLISTs in COBOL i don't know! :-D
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:

Post by Cody »

Killer Wolf wrote:
why we can't have PLISTs in COBOL i don't know!
Ah, there's a thought... once upon a time I could program in COBOL.
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
JazHaz
---- E L I T E ----
---- E L I T E ----
Posts: 2991
Joined: Tue Sep 22, 2009 11:07 am
Location: Enfield, Middlesex
Contact:

Post by JazHaz »

Can someone make a HUD for Widescreen please?

I run Oolite in 1280 x 800 widescreen! :D

Could be nice to use the full width of the screen, and as widescreen computers are becoming more popular it might be a nice thing to have....
JazHaz

Gimi wrote:
drew wrote:
£4,500 though! :shock: <Faints>
Cheers,
Drew.
Maybe you could start a Kickstarter Campaign to found your £4500 pledge. 8)
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

just to officially announce, you guys fkn RULE!!

ah, that's my new ship kitted out, let's launch and have some fun :
Image

ooh, one of those i'm-so-hard Dominatrixes! let's kick her ass!
Image

uh....dammit, this isn't going well!
Image

oh bugger 8-(
Image
Post Reply