Author Topic: Vectors  (Read 943 times)

I'm trying to make a homing rocket script and so far failing, so:
Can someone explain how vectors work and all the commands that deal with them?
The only one I know about is vectorDist(); and not very much about that.

Also, is there an easier way to hunt for the closest player than comparing every player's position?

EDIT: Why isn't this working?

Code: [Select]
InitContainerRadiusSearch(%aobj.position, 1000, $Typemasks::projectileobjecttype);
while(%obj = containerSearchNext())
{
if(%obj.getdatablock().getName() $= "homingCountermeasureProjectile") {
%homepl = %obj;
%cmeasured = 1;
}
}

(If no object is found it goes on to find players - which always happens)

It works when self-protection is enabled.



Figured it out: i had a return; outside of a function so it never executed the whole file
« Last Edit: August 21, 2011, 01:33:35 PM by ThinkInvisible »

Well you can ask Mesprit i'm his friend and he made this homing UFO projectile for a gun that he also made that is waaay more better than the homing projectile event add on.

Can someone explain how vectors work and all the commands that deal with them?
A vector is a string containing three numbers, and can represent a position or a direction. For a example, "1 0 0" is a vector. As it is normalized (meaning its "length" is 1) it is probably a direction. Something like "102.3 5.8 0.3" is probably a position. You may find the wikipedia article on Euclidean Vectors helpful.

Vector section of console function dump:
   /*! @name VectorMath
   
   Vector manipulation functions.
   @{ */
   /*!  Returns a+b. */
   virtual string VectorAdd(Vector3F a, Vector3F b) {}
   /*!  Returns a-b. */
   virtual string VectorSub(Vector3F a, Vector3F b) {}
   /*!  Returns a scaled by scalar (ie, a*scalar). */
   virtual string VectorScale(Vector3F a, float scalar) {}
   /*!  Returns a scaled such that length(a) = 1. */
   virtual string VectorNormalize(Vector3F a) {}
   /*!  Calculate the dot product of a and b. */
   virtual float VectorDot(Vector3F a, Vector3F b) {}
   /*!  Calculate the cross product of a and b. */
   virtual string VectorCross(Vector3F a, Vector3F b) {}
   /*!  Calculate the distance between a and b. */
   virtual float VectorDist(Vector3F a, Vector3F b) {}
   /*!  Calculate the length of a vector. */
   virtual float VectorLen(Vector3F v) {}
   /*!  Create an orthogonal basis from the given vector. Return a matrix. */
   virtual string VectorOrthoBasis(AngAxisF aaf) {}
   /// @}


Also, is there an easier way to hunt for the closest player than comparing every player's position?
Use a radius search:
Code: [Select]
InitContainerRadiusSearch(%center, %radius, %typemasks);
while(%obj = containerSearchNext())
{
%obj.doStuff();
}
I believe the object closest to the center will end up being the first result, so you can just use an if instead of a while and it'll only call %obj.doStuff(); on the first (nearest) object.

What are the args for the radiussearch? I can't get it to work right.

What are the args for the radiussearch? I can't get it to work right.
%center, %radius, %typemasks
Center and radius are self-explanatory of course, the typemasks are the tricky part. If you only want your missile to track players, you would just use $Typemasks::PlayerObjectType. You can get the full list of typemasks by typing $Typemasks into the console and pressing tab to cycle through them.

So:

Code: [Select]
InitContainerRadiusSearch(%aobj, %radius, $Typemasks::PlayerObjectType);
if(%obj = containerSearchNext())
{
echo(%obj);
%homepl = %obj;
}

%aobj is the homing projectile
%radius... i don't know what goes here :c
%obj... what's that?
%homepl is the player to lock on to if all goes well

will that work?

...
%center needs to be a position - just use %aobj.position
%radius is the size of the radius search - for reference a 32x baseplate is 16 units long
%obj is the first object found by the search
your reasoning with %homepl is correct.

One last thing.
How do i keep it from targeting the player who fired it?

EDIT: Oh, and give it more than one typemask. Countermeasures much?
« Last Edit: August 20, 2011, 03:29:13 PM by ThinkInvisible »

Got countermeasures figured out. Since they have priority over players, i don't need to use more than one typemask at once.

EDIT: And i think i got selfprotection running. I just had some messed-up variables.
« Last Edit: August 21, 2011, 12:15:12 PM by ThinkInvisible »

Why isn't this working?
Code: [Select]
InitContainerRadiusSearch(%aobj.position, 1000, $Typemasks::projectileobjecttype);
while(%obj = containerSearchNext())
{
if(%obj.getdatablock().getName() $= "homingCountermeasureProjectile") {
%homepl = %obj;
%cmeasured = 1;
}
}

(If no object is found it goes on to find players - which always happens)

It works when selfprotection is on, though.


Figured it out: i had a return; outside of a function so it never executed the whole file
« Last Edit: August 21, 2011, 01:33:22 PM by ThinkInvisible »

Finished up the script, pretty neat.
Features:
-Swarm L. (Fires many small rockets)
-Heavy L. (Fires a few large rockets)
-Homing L. (Fires default amount of standard rockets)
-Countermeasure L. (Fires countermeasures: rockets in play are attracted to these instead of players)
-RTB Prefs
-Self-homing toggle

Lockin'