Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
JazHaz
---- E L I T E ----
---- E L I T E ----
Posts: 2991
Joined: Tue Sep 22, 2009 11:07 am
Location: Enfield, Middlesex
Contact:

Re: Scripters cove

Post by JazHaz »

If you want a better guide then 4 credits are not going to go far! :roll:

Sheesh! Cheapskates! :twisted:
User avatar
Gouanaco
Competent
Competent
Posts: 47
Joined: Sun Oct 06, 2013 8:21 am
Location: Aus

Re: Scripters cove

Post by Gouanaco »

JazHaz wrote:
If you want a better guide then 4 credits are not going to go far! :roll:

Sheesh! Cheapskates! :twisted:

*sigh* Here... 125 creds.... that should be enough....right?
Also how long did it take everyone to learn these Scripting practices....?
Commander: Gouanaco
Ship: { Cobra Mark III }
Galaxy: [1]
Legal Status: Clean
Rating: Average (63)
Career: Trader/Bounty Hunter
Cash: 12 956.4@ (credits)
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Scripters cove

Post by Tricky »

Use this site, JavaScript | MDN - Mozilla Developer Network, as your bible, especially the Javascript Reference link from that page.

The version that Oolite uses is a cut down version of SpiderMonkey (v1.8 - ECMAScript edition 5).

Ignore all references to the Document Object Model (DOM), console.log and alert. Those only work for web based javascripts.
Zireael
---- E L I T E ----
---- E L I T E ----
Posts: 1396
Joined: Tue Nov 09, 2010 1:44 pm

Re: Scripters cove

Post by Zireael »

This is my attempt to create E:D-like engine trails, based on fuel leaks from CSOB's custom shields.

Code: Select all

this.name        = "customshieldsenginetrails";
this.author      = "Zireael";
this.copyright   = "Copyright Sept. 24, 2012 by CommonSenseOTB, licensed under Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Script For Engine trails";
this.version     = "0.01";

this.shipSpawned = function()
   {
   if(this.ship && this.ship.isValid && this.ship.target && this.ship.target.isValid)
      {
	  this.customshieldsframetime = 0.0;
	  this.customshieldsframetimelimit = 10.0;
	  this.ship.velocity = this.ship.velocity.add(this.ship.vectorForward.multiply(10 + (this.customshieldsframetimelimit * 3)));
	  this.csfl = addFrameCallback(this.customshieldsfuelleaks.bind(this));//----------
      return;
	  }
   else
      {
	  this.ship.remove();
	  return;
	  }
   }

this.customshieldsfuelleaks = function(delta)
   {
   if(this.ship && this.ship.isValid && this.ship.target && this.ship.target.isValid)
      {
	  this.customshieldsframetime += delta;
	  this.customshieldsfuelscooperpossibilities = system.filteredEntities(this, function (entity){return ((entity.fuel < 7.0) && (entity.equipmentStatus("EQ_FUEL_SCOOPS") === "EQUIPMENT_OK") && (entity !== this.ship.target))}, this.ship, 25);//must have space for fuel, working fuel scoops, and not be the one leaking the fuel to begin with
	  if(player.ship.scoopOverride === false)//if effect is not currently active
			   {
			   player.ship.scoopOverride = true;//activate the effect
			   this.ship.spawnOne("customshieldsfuelleaksscoopoverride");//spawn marker timer for effect control
			   }
			}
	  if(this.customshieldsframetime >= this.customshieldsframetimelimit)//length of time engine trail exists
	     {
		 removeFrameCallback(this.csfl);//----------
		 this.ship.remove();		 
         return;
		 }
      return;
      }
   else
      {
	  removeFrameCallback(this.csfl);//----------
      this.ship.remove();   
      return;
	  }
   }
Now what do I do in order to test it, apart from sticking it in EngineTrails.oxp/Scripts? I want it to be applied to all non-player ships.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1248
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove

Post by UK_Eliter »

Dear all

I'd be grateful with help on the following.

I'm trying to remove, via world script, visual effects - witchspace rings, sparks, etc. I think I can see how to generate an array of such things; indeed my code does this already, and tries to remove the entities in the array, but I am not sure (the script does complex things, so it is hard to tell) whether it works. Do OXP scripts have write-access to such entities?

Thanks.
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

You can remove any effects you made:

Code: Select all

var ve = system.addVisualEffect("dataKeyOfAVisualEffect", player.ship.position);
ve.remove();
if you insert a script="myvescript.js"; line into your effectdata.plist and put the following content into this .js file then you will get a message into your log when you remove your effect.

Code: Select all

this.name="myvescript";
this.effectRemoved = function()
{
     log("myvescript", "Oh, bye!");
}
If you want to remove another effects then you can search your target in the system.allVisualEffects array based on dataKey, position or any other properties you see in VisualEffect or Entity. But you can not modify effects created by the core game which is not in this array.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1248
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove

Post by UK_Eliter »

Thanks Norby! But can you tell me how to pick out, within system.allVisualEffects, the effects that show up in the log as OOSparkEntity and OORingEffectEntity? Or are those among the unmodifiable (and perhaps even undetectable via system.allVisualEffects) effects?
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

I do not see these in system.allVisualEffects. I used the following code when several ships arrived near the witchpoint and I saw many witchspace rings around the ships, but the result log contained effects created by OXPs only.

Code: Select all

for(var i = 0; i < system.allVisualEffects.length; i++)
   log("ve", i+". "+system.allVisualEffects[i].dataKey);
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2457
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

(Help, please!) This doesn't seem to work, and I don't know why:-

Code: Select all

this._numberForWeaponType(player.ship.currentWeapon);

Code: Select all

this._numberForWeaponType = function (weapon)
	{
	switch(weapon)
		{
		case "EQ_WEAPON_PULSE_LASER":
			{
			return 1;
			}
		case "EQ_WEAPON_BEAM_LASER":
			{
			return 2;
			}
		case "EQ_WEAPON_MINING_LASER":
			{
			return 3;
			}
		case "EQ_WEAPON_MILITARY_LASER":
			{
			return 4;
			}
		default:
			{
			return 0;
			}
		}
	}
It is falling through to the default, and returning 0 every time. Why? What sort of values does player.ship.currentWeapon hold or point to?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

player.ship.currentWeapon returns an EquipmentInfo.

Try this._numberForWeaponType(player.ship.currentWeapon.equipmentKey);
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

You should also put a break; after each of the returns, as once one case has been positively triggered then there's no need to evaluate the remaining ones. Should make the code a very little bit quicker.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Thargoid wrote:
You should also put a break; after each of the returns, as once one case has been positively triggered then there's no need to evaluate the remaining ones. Should make the code a very little bit quicker.
That would be odd if true - though I suppose it's possible if the JS engine's optimisation of switch/case is a bit odd - because nothing after the return is evaluated should even be considered.

(Also, JS switch/case, like its C inspiration, has fall-through, so once one case comparison matches if you don't break or return out of the switch the rest get executed unconditionally)
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2457
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Thanks, guys.

Another question now: can I reset the exit screen of a mission screen while it is displayed? I want to have options "Exit to chart screen" or "Back to interfaces screen" on the mission screen.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Setting mission.exitScreen inside the callback should work.
Neelix
---- E L I T E ----
---- E L I T E ----
Posts: 288
Joined: Sat May 31, 2014 9:02 pm
Location: Melbourne, Australia

Re: Scripters cove

Post by Neelix »

cim wrote:
Setting mission.exitScreen inside the callback should work.
Any chance of making this default to the screen the mission screen was called from?

- Neelix
Talaxian Enterprises: [wiki]Vacuum Pump[/wiki] [wiki]Waypoint Here[/wiki]
Post Reply