HUD scripting example
Moderators: winston, another_commander
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
HUD tests
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
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
player.alertHostiles is a boolean (yes/no), so just remove the ==1 completely.
For the Aquatics Guardian system I use something similar:
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.
For the Aquatics Guardian system I use something similar:
Code: Select all
if(player.alertCondition == 3 && player.alertHostiles && !missionVariables.aquatics_guardianActive)
And yes, once your energy is back up you will need to do something else to change your HUD back again.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
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!
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!
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
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
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
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
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.Killer Wolf wrote: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 playCode: Select all
this.hudThing = function() { if (player.alertCondition == 3) { player.ship.hud = "dbcombathud.plist"; } // else // { // player.ship.hud = "dbnormalhud.plist"; // } }
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.
- JazHaz
- ---- E L I T E ----
- Posts: 2991
- Joined: Tue Sep 22, 2009 11:07 am
- Location: Enfield, Middlesex
- Contact:
I think this is the list you are referring to: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).
http://wiki.alioth.net/index.php/Oolite ... t_handlers
JazHaz
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!Gimi wrote:Maybe you could start a Kickstarter Campaign to found your £4500 pledge.drew wrote:£4,500 though! <Faints>
Cheers,
Drew.
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:
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!"
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";
}
}
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!"
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
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.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.
UPS-Courier & DeepSpacePirates & others at the box and some older versions
In any case I'd definitely put an else with 'normalhud.plist' like
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...
Code: Select all
else
{
player.ship.hud = "dbnormalhud.plist";
}
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
- JazHaz
- ---- E L I T E ----
- Posts: 2991
- Joined: Tue Sep 22, 2009 11:07 am
- Location: Enfield, Middlesex
- Contact:
Can someone make a HUD for Widescreen please?
I run Oolite in 1280 x 800 widescreen!
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....
I run Oolite in 1280 x 800 widescreen!
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
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!Gimi wrote:Maybe you could start a Kickstarter Campaign to found your £4500 pledge.drew wrote:£4,500 though! <Faints>
Cheers,
Drew.
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm