Blockland Forums > Modification Help
Vectors
ThinkInvisible:
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: --- InitContainerRadiusSearch(%aobj.position, 1000, $Typemasks::projectileobjecttype);
while(%obj = containerSearchNext())
{
if(%obj.getdatablock().getName() $= "homingCountermeasureProjectile") {
%homepl = %obj;
%cmeasured = 1;
}
}
--- End code ---
(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
PurpleMetro:
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.
Amade:
--- Quote from: ThinkInvisible on August 20, 2011, 11:00:19 AM ---Can someone explain how vectors work and all the commands that deal with them?
--- End quote ---
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) {}
/// @}
--- Quote from: ThinkInvisible on August 20, 2011, 11:00:19 AM ---Also, is there an easier way to hunt for the closest player than comparing every player's position?
--- End quote ---
Use a radius search:
--- Code: ---InitContainerRadiusSearch(%center, %radius, %typemasks);
while(%obj = containerSearchNext())
{
%obj.doStuff();
}
--- End code ---
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.
ThinkInvisible:
What are the args for the radiussearch? I can't get it to work right.
Amade:
--- Quote from: ThinkInvisible on August 20, 2011, 01:35:34 PM ---What are the args for the radiussearch? I can't get it to work right.
--- End quote ---
%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.