HUD scripting example
Moderators: winston, another_commander
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
HUD change script
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
ta
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
Re: HUD change script
Quick example below. This goes in script.js, which lives inside Config: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
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";
}
}
Last edited by another_commander on Sun Mar 14, 2010 12:09 am, edited 1 time in total.
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
This has now been changed to a read/write string property, as in:
Code: Select all
player.ship.hud = "trading-hud.plist";
E-mail: [email protected]
- Lestradae
- ---- E L I T E ----
- Posts: 3095
- Joined: Tue Apr 17, 2007 10:30 pm
- Location: Vienna, Austria
..
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?
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: ..
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 dockingLestradae 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?
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
Bounty Scanner
Number 935
Number 935
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Re: ..
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.
E-mail: [email protected]
- 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
What about player.alertCondition or player.alertHostilesKiller 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?
UPS-Courier & DeepSpacePirates & others at the box and some older versions
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
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.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?
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;
}
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Code: Select all
if (shipsInRange[i].target && shipsInRange[i].target.isPlayer)
Code: Select all
if (shipsInRange[i].target && shipsInRange[i].target.isPlayer && shipsInRange[i].target.hasHostileTarget)
UPS-Courier & DeepSpacePirates & others at the box and some older versions
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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);
}
E-mail: [email protected]
- Killer Wolf
- ---- E L I T E ----
- Posts: 2279
- Joined: Tue Jan 02, 2007 12:38 pm
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am