Blockland Forums > Modification Help

Homing Script

Pages: (1/3) > >>

takato14:


--- Code: ---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();
}

--- End code ---

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.

--- Code: ---
if (%vec1 == %vec2)
{
       %prj.delete();
}

--- End code ---
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.

otto-san:

if(%mgo == %mco == 1)

is that even a valid if statement or is this another weird torque syntax thing i dont know about

takato14:


--- Quote from: otto-san on January 22, 2012, 02:06:20 PM ---if(%mgo == %mco == 1)

is that even a valid if statement or is this another weird torque syntax thing i dont know about

--- End quote ---
What do you mean valid? You can perform multiple tests in one if statement if that's what you mean.

jes00:


--- Quote from: takato14 on January 22, 2012, 02:19:45 PM ---What do you mean valid? You can perform multiple tests in one if statement if that's what you mean.

--- End quote ---
Not that way (that I know of).

Nexus:


--- Quote from: otto-san on January 22, 2012, 02:06:20 PM ---if(%mgo == %mco == 1)

is that even a valid if statement or is this another weird torque syntax thing i dont know about

--- End quote ---

I doubt it, nothing is wrong with


--- Code: ---if(%mgo == 1 && %mco ==1)
--- End code ---

Also, a while(1) loop should never be a real option.

Try to incorporate the conditions for the break into the test for the while loop instead, if you must.

Pages: (1/3) > >>

Go to full version