Page 70 of 117

Re: Scripters cove

Posted: Thu Oct 10, 2013 2:07 pm
by JazHaz
If you want a better guide then 4 credits are not going to go far! :roll:

Sheesh! Cheapskates! :twisted:

Re: Scripters cove

Posted: Fri Oct 11, 2013 12:00 am
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....?

Re: Scripters cove

Posted: Fri Oct 11, 2013 2:41 am
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.

Re: Scripters cove

Posted: Sat Dec 14, 2013 1:18 pm
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.

Re: Scripters cove

Posted: Thu Mar 06, 2014 11:03 am
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.

Re: Scripters cove

Posted: Thu Mar 06, 2014 11:53 am
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.

Re: Scripters cove

Posted: Thu Mar 06, 2014 12:46 pm
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?

Re: Scripters cove

Posted: Thu Mar 06, 2014 2:01 pm
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);

Re: Scripters cove

Posted: Thu Jul 31, 2014 6:02 am
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?

Re: Scripters cove

Posted: Thu Jul 31, 2014 6:05 am
by cim
player.ship.currentWeapon returns an EquipmentInfo.

Try this._numberForWeaponType(player.ship.currentWeapon.equipmentKey);

Re: Scripters cove

Posted: Thu Jul 31, 2014 8:23 pm
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.

Re: Scripters cove

Posted: Thu Jul 31, 2014 8:39 pm
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)

Re: Scripters cove

Posted: Sat Aug 09, 2014 5:42 am
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.

Re: Scripters cove

Posted: Sat Aug 09, 2014 8:00 am
by cim
Setting mission.exitScreen inside the callback should work.

Re: Scripters cove

Posted: Sat Aug 09, 2014 9:29 am
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