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: 2279
Joined: Tue Jan 02, 2007 12:38 pm

HUD change script

Post 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
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: HUD change script

Post 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";
    }
}
Last edited by another_commander on Sun Mar 14, 2010 12:09 am, edited 1 time in total.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

sweet, thanks AC.

:-)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

This has now been changed to a read/write string property, as in:

Code: Select all

player.ship.hud = "trading-hud.plist";
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post 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?
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Re: ..

Post 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
Bounty Scanner
Number 935
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: ..

Post 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!
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post by Lestradae »

Ah, that's fast: I ask for it and it's already been done, basically. Nice :D
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Post 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?
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:
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
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post 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;
}
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 »

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.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post 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);
}
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2279
Joined: Tue Jan 02, 2007 12:38 pm

Post 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?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post 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.
Post Reply