Page 1 of 4
HUD change script
Posted: Fri Mar 12, 2010 10:37 am
by Killer Wolf
as per the Progress thread, could someone knock up a quick script to change HUDs please? personally i'd like a script that changes the HUD to a trading HUD when docked, and something simple to change to a damaged HUD if damage is incurred. not picky about the parameters of this, ie number of bits of equipment damaged etc, i just want to try a few experiments.
ta
Re: HUD change script
Posted: Fri Mar 12, 2010 10:52 am
by another_commander
Killer Wolf wrote:as per the Progress thread, could someone knock up a quick script to change HUDs please? personally i'd like a script that changes the HUD to a trading HUD when docked, and something simple to change to a damaged HUD if damage is incurred. not picky about the parameters of this, ie number of bits of equipment damaged etc, i just want to try a few experiments.
ta
Quick example below. This goes in script.js, which lives inside Config:
Code: Select all
this.shipDockedWithStation = function()
{
player.ship.hud = "trading-hud.plist";
}
this.shipWillLaunchFromStation = function(stationLaunchingFrom)
{
player.ship.hud = "hud.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 < 50)
{
player.ship.hud = "damaged-hud.plist";
}
}
Posted: Fri Mar 12, 2010 12:38 pm
by Killer Wolf
sweet, thanks AC.
Posted: Sat Mar 13, 2010 9:52 pm
by JensAyton
This has now been changed to a read/write string property, as in:
Code: Select all
player.ship.hud = "trading-hud.plist";
..
Posted: Sun Mar 14, 2010 8:36 am
by Lestradae
What I have been wanting to ask for ages, would it be too difficult/messy to make HUDs into items of equipment?
That could put a whole new spin to them, still possible to have ships that have a specific/unique one, don't know if I'm the only one who would find this interesting?
Re: ..
Posted: Sun Mar 14, 2010 10:13 am
by Frame
Lestradae wrote:What I have been wanting to ask for ages, would it be too difficult/messy to make HUDs into items of equipment?
That could put a whole new spin to them, still possible to have ships that have a specific/unique one, don't know if I'm the only one who would find this interesting?
Not quite sure what you mean, but you can dynamical on to fly change the hud to whatever you like at any time, during, after or just before docking
so if you couple it with some trigger like
playerBoughtEquipment
and also take into account that the player can buy a new ship (with a new hud) that triggers
playerBoughtNewShip, that will override the HUD setting(and it should)..
I'll leave it up to you to make a working example
Cheers Frame
Re: ..
Posted: Sun Mar 14, 2010 11:43 am
by JensAyton
Lestradae wrote:What I have been wanting to ask for ages, would it be too difficult/messy to make HUDs into items of equipment?
That could put a whole new spin to them, still possible to have ships that have a specific/unique one, don't know if I'm the only one who would find this interesting?
- Custom, scripted equipment has already been done.
- HUDs are now scriptable.
Tadaa!
..
Posted: Sun Mar 14, 2010 12:29 pm
by Lestradae
Ah, that's fast: I ask for it and it's already been done, basically. Nice
Posted: Mon Mar 15, 2010 7:47 pm
by Killer Wolf
is it possible to query/use the player's condition status (the red/yellow/green) and/or if they've been targetted by another ship?
Posted: Mon Mar 15, 2010 7:59 pm
by Eric Walch
Killer Wolf wrote:is it possible to query/use the player's condition status (the red/yellow/green) and/or if they've been targetted by another ship?
What about
player.alertCondition or
player.alertHostiles
Posted: Mon Mar 15, 2010 9:36 pm
by another_commander
Killer Wolf wrote:is it possible to query/use the player's condition status (the red/yellow/green) and/or if they've been targetted by another ship?
Although I am sure that player.alertHostiles would be just fine for the vast majority of cases, here is a little script which uses the alertConditionChanged handler to find which ship has triggered the red alert (i.e. is attacking the player). Note that this script will not act in the case where the player gets targeted by a ship while already in red alert. This means that if you start a fight while very close to a sun, the script will not pick up the attack. In this case, maybe the shipBeingAttacked handler can come in handy.
Code: Select all
this.alertConditionChanged = function(currentAlertCondition, previousAlertCondition)
{
if(currentAlertCondition == 3) // red alert
{
this.stp = this.findShipTargetingPlayer();
if (this.stp)
{
log("scripttest2", "Player being targeted by " + this.stp);
}
else // red alert is not because of a ship targeting player, could be temperature or altitude alert
{
log("scrtipttest2", "Red alert - not due to ship attacking player");
}
}
}
this.findShipTargetingPlayer = function()
{
var scannerRange = 25000;
// find ships in scanner range
this.shipsInRange = system.filteredEntities(
player.ship,
function(ship)
{
return (ship.isShip && ship.position.distanceTo(player.ship.position) < scannerRange);
} )
// see which of the ships found is targeting the player (if any)
for (var i = 0; i < shipsInRange.length; i++)
{
if (shipsInRange[i].target && shipsInRange[i].target.isPlayer)
{
return shipsInRange[i];
}
}
// nothing found
return null;
}
Posted: Mon Mar 15, 2010 10:45 pm
by Eric Walch
Code: Select all
if (shipsInRange[i].target && shipsInRange[i].target.isPlayer)
should be
Code: Select all
if (shipsInRange[i].target && shipsInRange[i].target.isPlayer && shipsInRange[i].target.hasHostileTarget)
because not all ships targeting the player have hostile intentions.
Posted: Mon Mar 15, 2010 11:22 pm
by JensAyton
Simplification:
Code: Select all
this.findShipTargetingPlayer = function()
{
function isTargetingPlayer(entity)
{
return entity.isShip && entity.hasHostileTarget && entity.target.isPlayer;
}
return system.filteredEntities(this, isTargetingPlayer, player.ship, 25000);
}
Posted: Tue Mar 16, 2010 7:54 am
by Killer Wolf
thanks for the info. just to clarify one other thing : if we have a script that determines HUDs, do we take out the HUD entry for the player variant in the SHIPDATA?
Posted: Tue Mar 16, 2010 8:25 am
by another_commander
No, the shipdata HUD entry should remain. It is good practice. If you don't have it, then the standard HUD will be displayed as default.