Page 67 of 118

Re: Question about Timers

Posted: Wed Feb 27, 2013 12:18 am
by GGShinobi
Thanks Wildeblood, I'll try that.

And I think I understand now why my first experiments with timers failed miserably... :lol:

Re: Scripters cove

Posted: Wed Mar 06, 2013 11:34 am
by Rorschachhamster
Ok, quaternions... :roll:
In the documentation on the wiki there is the example for a rotation with two subentities at 120° +/-. I work on a three point system of leading a ship slowly unto the position of another entity with a very slow pace (to avoid collision warning before the very near point is reached). This is what I have, with rotationBy as the example rotations, because it is three sided, for the vector that is the vector on wich the ship closes in:

Code: Select all

	this.vectorContainer = chosenWagon.vectorUp;
	var choosedirection = Math.ceil(Math.random()*3);
	switch (choosedirection) {
	case(1):
	this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,0.8660254]);
	break;
	case (2):
	this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,-0.8660254]);
	break;
	default:
	break;
	};
Now, if this.vectorContainer isn't changed it works like a charm... :? Any hints?

Re: Scripters cove

Posted: Wed Mar 06, 2013 3:59 pm
by Wildeblood
How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.

Here the fifth element of each sub-array is its category:-

Code: Select all

this.$tips = [
	["content","content","content","content","myCategory"],
	["content","content","content","content","otherCategory"],
	["content","content","content","content","myCategory"]
];
And I want to remove two of the three sub-arrays by calling this.$removeTips(myCategory).

Code: Select all

// REMOVE ALL TIPS IN GIVEN CATEGORY

this.$removeTips = function(category)
	{
	var counter = 0;
	for (var i = 0; i < this.$tips.length; i++) // BOGUS!
		{
		if (this.$tips[i][5] && this.$tips[i][5] === category)
			{
			delete this.$tips[i];
			counter++;
			}
		}
	return counter;
	}

Re: Scripters cove

Posted: Wed Mar 06, 2013 4:08 pm
by Eric Walch
Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.

e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);

(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)

In here Δt is the time parameter, assuming you do it in frameCallbacks.

Re: Scripters cove

Posted: Wed Mar 06, 2013 4:09 pm
by cim
Wildeblood wrote:
How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.
Reverse the for loop

Code: Select all

for (var i = this.$tips.length-1 ; i >= 0 ; i--)
Then if you delete an element from the array, it only reindexes elements you've already considered, and doesn't affect your array pointer.

Re: Scripters cove

Posted: Wed Mar 06, 2013 4:41 pm
by Wildeblood
cim wrote:
Reverse the polarity of the plasma conduits.
Thanks, cim.

Re: Scripters cove

Posted: Wed Mar 06, 2013 6:10 pm
by Rorschachhamster
Eric Walch wrote:
Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.

e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);

(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)

In here Δt is the time parameter, assuming you do it in frameCallbacks.
Ok... this sounds like I can understand it, eventually. :lol: Oh, and I probably have to because visualEffects can't be AIed. :D

But the actual problem is really more a Vector3D question, in wich rotateBy uses a Quaternion to specify the rotation. :D
I need the vectorUp rotated by 120° (and 240° or -120°) around the z-axis of the ship that it's originates from, but it's in another ship's script.
The chosenWagon is the origin of the vectorUp. So, it has to be turned around the vectorForward (or heading) of that ship, and I thought this would be done by the same quaternion as in the subentities example on the wiki. Obviously this doesn't work. Maybe because I have to work that z-axis to be turned around somehow in? :P I really don't know, how...

Re: Scripters cove

Posted: Sat Mar 09, 2013 9:50 am
by spara
Hello helpful people. Question about weaponFacings.

I'm using this code to read the number of weapon facings of a targeted ship:

Code: Select all

this.shipTargetAcquired = function(target) {
	log("facings", target.weaponFacings);
}
I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?

I'm am a bit confused as Orbital Shuttle's shipdata says:

Code: Select all

forward_weapon_type = "WEAPON_NONE";
...
weapon_facings = 0;
weapon_position_aft = "0.0 0.0 -17.5";
weapon_position_forward = "0.0 -4.5 17.5";
weapon_position_port = "-9.0 0.0 11.5";
weapon_position_starboard = "9.0 0.0 11.5";

Re: Scripters cove

Posted: Sat Mar 09, 2013 9:57 am
by Thargoid
The wiki tells all. The value is a bitmask of the four facings and whether they are available or not.

The other bits in shipdata are the weapon positions on the model-is where the beam comes from when that weapon fires. But yes the weapon_facings setting in the shipdata does seem a bit odd and is being ignored for some reason, maybe being overridden by having the position entire in there.

Re: Scripters cove

Posted: Sat Mar 09, 2013 10:00 am
by cim
spara wrote:
I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?

I'm am a bit confused as Orbital Shuttle's shipdata says:
Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include the weapon_facings parameter, so they'll be overriding the core shipdata, not specifying it, and it'll default back to 15.

Re: Scripters cove

Posted: Sat Mar 09, 2013 10:09 am
by Smivs
cim wrote:
Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include the weapon_facings parameter...
<Smivs adds another line to his 'To do' list...>

Re: Scripters cove

Posted: Sat Mar 09, 2013 10:31 am
by spara
Why of course :shock:. You must be psychic cim. I'm using Griff's atm and at the same time looking at the core ship definitions. All clear now, thanks a lot.

This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.

Re: Scripters cove

Posted: Sat Mar 09, 2013 10:42 am
by cim
spara wrote:
This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
Well, that and we're never going to be in a position where every miscellaneous ship OXP has it set even if they should. Before 1.77 every NPC ship had a value of 15 (and the property was implicit). Now almost every ship still has a value of 15, but some of them don't. It's one of those things that will gradually get better over time, but it's still at least slightly useful now.

Re: Scripters cove

Posted: Sun Mar 17, 2013 10:47 am
by Rorschachhamster
Quick AI script question:
Does "setTargetToRandomStation" choose the main station as well?
Because I never encountered it in my tests, and that were many tests... :roll:

EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...

Re: Scripters cove

Posted: Sun Mar 17, 2013 11:01 am
by cim
Rorschachhamster wrote:
Does "setTargetToRandomStation" choose the main station as well?
Only if there are no other non-carrier dockables in the system, which is generally rare.
Rorschachhamster wrote:
EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
Yes, certainly. The rollD command just generates a particular AI event, and as with other AI events you're under no obligation to respond.