Page 71 of 118

Re: Scripters cove

Posted: Sat Aug 09, 2014 10:35 am
by cim
Most of the time in practice I think that would either be the interfaces screen, or something invalid (for mission screens called when docking), and I'm not sure how well it would work for a chain of mission screens.

If you want to do it for your own mission screens, then:

Code: Select all

mission.runScreen(
{
  // other parameters...
  exitScreen: guiScreen
}, /* callback goes here */);

Re: Scripters cove

Posted: Sat Aug 09, 2014 11:53 am
by Neelix
cim wrote:
Most of the time in practice I think that would either be the interfaces screen, or something invalid (for mission screens called when docking), and I'm not sure how well it would work for a chain of mission screens.

Cheers, for the code fragment, I'll no doubt find that useful. :-)

My main concern here is consistency between internal interfaces (Deliveries) and Mission interfaces. When you exit a Deliveries interface you end up back on the interfaces screen. When you exit one of the others (including Ship Registration) you usually end up back on the status screen, which I tend to find disconcerting and since I often want to continue checking interfaces, irritating as well.

- Neelix

Re: Scripters cove

Posted: Sat Aug 09, 2014 1:05 pm
by cim
Neelix wrote:
(including Ship Registration)
Fixed - thank you.

Re: Scripters cove

Posted: Thu Aug 21, 2014 1:33 pm
by dertien
can someone tell me what the correct code is to check if the player ship weapons online button has been pressed ?

Code: Select all

this.isLaserOnline = function()
{
if (this.weaponsOnline == true)
      {
      player.consoleMessage("Debug MSG:Weapons Online");
      //this.laserBayDoorOpen();
      }
if (this.weaponsOnline == false)
      {
      player.consoleMessage("Debug MSG:Weapons offline");
	  //this.laserBayDoorClosed();
      }
}
this gives no errors in the log, but doesn't show the message either.

Re: Scripters cove

Posted: Thu Aug 21, 2014 1:54 pm
by Wildeblood
Try player.ship.weaponsOnline

Re: Scripters cove

Posted: Thu Aug 21, 2014 2:01 pm
by dertien
Thx Wildeblood, that worked :)

Re: Scripters cove

Posted: Fri Aug 22, 2014 2:38 am
by dertien
Player ship already works, trying to find same for NPC's

but:

Code: Select all

this.$checkNPCalert = function()
{
if (this.ship.hasHostileTarget == false)
      {
	  this.$laserDoorClosed();
      }
if (this.ship.hasHostileTarget == true)
      {
	   this.$laserDoorOpen();
		this.ship.commsMessage("DEBUG ATTACKING");
      }  
}
Is there another way to check if an NPC has turned hostile, towards the player or towards another NPC?

(I am running this periodiacally with a timer that is initialized at startup)

Code: Select all

this.startUp = function()
{
	 this.$alertchecker = new Timer(this, this.$checkNPCalert,6, 15);
}

Re: Scripters cove

Posted: Fri Aug 22, 2014 6:00 am
by cim
dertien wrote:
(I am running this periodiacally with a timer that is initialized at startup)

Code: Select all

this.startUp = function()
{
	 this.$alertchecker = new Timer(this, this.$checkNPCalert,6, 15);
}
This will be the problem - the actual check code looks fine.

Assuming this is in the ship script, there's no such thing as a startUp event in a ship script: startUp happens exactly once, in worldscripts only, when a commander (new or existing) is loaded from disk. Use shipSpawned for initialisation code in ship scripts.

Re: Scripters cove

Posted: Fri Aug 22, 2014 9:36 am
by dertien
Thx Cim, that works now. :D

Re: Scripters cove

Posted: Fri Aug 22, 2014 9:42 pm
by dertien
Possible workaround solution for equipment attached to subentity destroy and purchase mechanics for the player ship.

Just would like to know if this could circumvent the fact that there is no subentities.add, and if I missed any steps with my reasoning.

Code: Select all

OPTION A

Check damage status of purchased equipment with timer

Check if subentity is intact && if it is at position x
if intact and at position x (all is well)
if subent has been destroyed - remove relevant purchased equipment set equipment status to "EQUIPMENT_DAMAGED"
Restore all subentitites & check status of all equipment
Depending on EQUIPMENT_OK or EQUIPMENT_DAMAGED hide subents in the model
or

If it is not possible to check for a certain position, we might be able circumvent it like so:
Each subentity gets a subentity dummy ( a low poly model subentity like a cube that is hidden inside the hull with a very high energy value so it cannot be destroyed by laser fire)

Code: Select all

OPTION B

Step A: Check which EQ_equipment is EQ_damaged or EQ_OK using a switch case which gets initialized on launch from the station
if equipment is ok reset subent to position, if equipment is damaged remove the dummy.

Step B:

this.equipmentDamaged = function(eqKey)
{
  if (eqKey == "EQ_ADVANCED_NAVIGATIONAL_ARRAY")
	{
		/* Two subentities exist on the ship, the real subentity equipment and its dummy.
		The dummy is located inside the ship model, the other is placed on the hull*/
		/* if both subentities exist, there is no problem and the equipment should be repaired. 
		This is in case the EQ_equipment is destroyed without the subentity being destroyed by npc*/	
		if (this._findSubEntity("HPC_ana") != null && this._findSubEntity("HPC_ana_dummy") != null)
		{
			// both are intact and equipment should not be destroyed so repair it
			this.ship.setEquipmentStatus("EQ_ADVANCED_NAVIGATIONAL_ARRAY","EQUIPMENT_OK");
		}
		/*  However, if the subentity equipment does not exist on the ship and the dummy isn't 
		then the subentity equipment is destroyed*/
	if (this._findSubEntity("HPC_ana") == null && this._findSubEntity("HPC_ana_dummy") != null)
		{
       // then the ana is destroyed thus do the following:
	   this.ship.setEquipmentStatus("EQ_ADVANCED_NAVIGATIONAL_ARRAY","EQUIPMENT_DAMAGED"); // damage EQ_equipment
	   this.ship.restoreSubEntities() // restore subentities and put them back on the model as not to trigger the overhaul when docked
		var $ana = this._findSubEntity("HPC_ana"); // find the subent ana and put it inside the model
               if ($ana)
               {
                  $ana.position = [0,0,0];
               }
		var $ana_dmy = this._findSubEntity("HPC_ana_dmy"); // destroy the dummy ana
               if ($ana_dmy)
               {
                  HPC_ana_dmy.remove(); // remove the ana dummy in order to not trigger both if's() above and use timer to loop through A and B
               }   
	}
}
  else if (eqKey == "EQ_ECM")
  {
     // and so on
  }
  // and so on
}

Step C:

During docking tunnel, stop/delete timers and restore all subentites to have no overhaul or destroy all dummies again according to rule A before docking to have an overhaul.

Cim, I am pretty confident that you gave me enough building blocks to do this by myself, but I may not see the whole picture, therefore my question:

Does this look like it will work, or am I forgetting an obvious obstacle that makes this unfeasible ?
What impact will this have on the overhaul feature?

Re: Scripters cove

Posted: Sat Aug 23, 2014 8:25 am
by cim
restoreSubEntities, as well as returning all subentities to the ship, also returns all subentities back to their original position, orientation, energy values, etc. So if you have anything like the landing gear which can move independently, you'll also need to record what state it's in. The "energy values" one is particularly important - subentity A gets destroyed, so you damage equipment A, restore subentities, and move subentity A to the hidden position ... and subEntity B which was at 10/300 energy left is now restored to 300/300. So before calling restoreSubEntities, you'll need to record the energy levels of all subentities, then call it, then reset the energy levels.
(If you intend for subentity damage to be able to accumulate over time - i.e. energy_recharge_rate of 0 - you'll also need to do this on save/load)

You would have to make sure that any destroyable subentity had an equipment item associated with it (e.g. the covers protecting some items) and make sure the addition and removal of those items was also handled properly. Otherwise you'll be putting the hatch covers back on every time.

Load/save: which subentities your ship currently has is saved to the savegame, but other things about them aren't - when you reload the game, all subentities still on the ship will be restored to their original positions. You'll need to move them again then, too.

Note that equipment the player hasn't even bought yet will have status "EQUIPMENT_UNAVAILABLE". You'll need to handle that case as well.

Option A is probably the better rough approach - you don't yet have a check in it for "equipment damaged, but subentity is in the normal position", but other than that it should work.

Re: Scripters cove

Posted: Sat Aug 23, 2014 11:06 am
by dertien
Thanks Cim,

As you said earlier, this one needs skill. Thank you for your time and good advice.

Re: Scripters cove

Posted: Fri Aug 29, 2014 3:09 am
by dertien
A little question:

I have this code, which works well, but only after purchase of the relevant laser at the shop.

Code: Select all

this.playerBoughtEquipment = function(equipment)
	{
	switch(equipment)
		{
		case "EQ_WEAPON_PULSE_LASER":
			{
			var pulselaser = this._findSubEntity("HPC_pulselaser"); 
							if (pulselaser)
								{
								pulselaser.position = [-10.0, 1.63, 14.23];
								break;								
								}
			}
		case "EQ_WEAPON_BEAM_LASER":
			{
			var beamlaser = this._findSubEntity("HPC_beamlaser"); 
							if (beamlaser)
								{
								beamlaser.position = [-10.0, 1.63, 14.23];
								break;
								}
			}
		case "EQ_WEAPON_MINING_LASER":
			{
			var mininglaser = this._findSubEntity("HPC_mininglaser"); 
							if (mininglaser)
								{
								mininglaser.position = [-10.0, 1.63, 14.23];
								break;
								}
			}
		case "EQ_WEAPON_MILITARY_LASER":
			{
			var militarylaser = this._findSubEntity("HPC_militarylaser"); 
							if (militarylaser)
								{
								militarylaser.position = [-10.0, 1.63, 14.23];
								break;
								}
			}
		}
	}
Can someone tell me how I should check for equipment that is already on the ship, in this case the lasers ?

Thank you.

Re: Scripters cove

Posted: Fri Aug 29, 2014 4:34 am
by Wildeblood
dertien wrote:
Can someone tell me how I should check for equipment that is already on the ship, in this case the lasers ?
See the previous page in this thread, where I was asking a similar thing. :)

Code: Select all

player.ship.currentWeapon.equipmentKey
or

Code: Select all

player.ship.forwardWeapon.equipmentKey
are likely what you seek.

Re: Scripters cove

Posted: Fri Aug 29, 2014 12:42 pm
by dertien
EDIT: Thx Wildeblood that did it. Thank you .