function svectorProjectile::changeForm(%db,%prj)
{
initContainerRadiusSearch(%prj.getPosition(),50,$TypeMasks::PlayerObjectType);
while(1)
{
%search=containerSearchNext();
if(%prj.client==%search.client)
{
continue;
}
%mg=%prj.client.minigame;
%mc=%search.client.minigame;
%mgo=isObject(%mg);
%mco=isObject(%mco);
if(%mgo == %mco == 1)
{
if(%mg!$=%mc)
{
continue;
}
}
if(isObject(%search))
{
%obj=%search;
}
break;
}
if(!isObject(%obj)) {%prj.delete();return;}
%pos=vectorAdd(%obj.getPosition(),"0 0 "@ getWord(%obj.getScale(),2)*1.8);
%vec=vectorSub(%pos,%prj.getPosition());
%vec=vectorScale(vectorNormalize(%vec),svectorProjectile.muzzleVelocity);
%p = new Projectile()
{
initialVelocity = %vec;
initialPosition = %prj.getPosition();
datablock = svectorProjectile;
sourceObject = %prj.client.player;
sourceSlot = %prj.sourceSlot;
client = %prj.client;
scale = %prj.getScale();
CNT = %prj.CNT++;
};
if(%prj.CNT<12) {svectorProjectile.schedule(getRandom(100,200),"ChangeForm",%p);}
%prj.delete();
}
So, this is the homing script from Bushido's old Homing Vector. I've been playing around with it to see what it is that's causing server instability, and I think I know what it is.
Say you were to fire the gun when two players were nearby. If those players happened to be exactly the same distance away from a projectile that was fired, what would happen? The engine won't know what to do. It will try to send it to two different places at once. This obviously wouldn't work, and the engine would crash.
I was trying to figure out a way to fix this. Ive never worked with containerSearches before, so please bear with me.
I was thinking of adding another if statement to the code to test for two vectors of the same length, and delete the projectile in this case. However, I don't know how I'd identify these in the script.
if (%vec1 == %vec2)
{
%prj.delete();
}
But, I don't know how to identify %vec1 and %vec2 when the containerSearch starts.
Alternately, there could be an if statement that tests whether there are two playerObjects within the search radius, and if this is the case, randomly choose one of them. This wouldn't be as good, because you could be aiming at someone right in front of you and instead it goes after someone 10 feet away from you, but it's certainly better than crashing.
Any thoughts on how this can be done? I'm not trying to re-release the Vector, I just want to be able to use it in my own server without having to worry about random crashes.