Author Topic: [Let It Be Known To All] Tumble Bug - Repost + tumbleBetter Function  (Read 2397 times)

Quote
To anyone who uses tumble(%player, %time); There is a bug in it that Badspot hasn't fixed. When you're tumbling you can click to respawn. If you want to use the tumble function, the below code fixes the bug.
Code: [Select]
package TumbleFix
{
function observer::onTrigger(%data, %cam, %slot, %bool)
{
if(%slot == 0 && %bool && isObject(%client = %cam.getControllingClient()) &&
isObject(%player = %client.player) &&
isObject(%vehicle = %player.getObjectMount()) &&
isObject(%data = %vehicle.getDataBlock()) &&
%data.getName() $= "deathVehicle")
{
return;
}

parent::onTrigger(%data, %cam, %slot, %bool);
}
};
activatePackage(TumbleFix);


Also, as the %time variable in the tumble function never worked in the first place, I made a tumbleBetter function were it does work.

The usage is tumbleBetter(%player, %time, %force);
%player - The player object you wish to tumble(obviously).
%time - How long you want the player to tumble for, in milliseconds.
%force - An integer from 0 to 3.
      0 = Tumble for %time, then stop if it's safe. Regain control of
      player after clicking.
      1 = Tumble for %time, then stop if it's safe. Regain control of
      player automatically.
      2 = Tumble for %time, then stop wether it's safe or not. Regain
      control of player after clicking.
      3 = Tumble for %time, then stop wether it's safe or not. Regain
      control of player automatically.

Code: [Select]
function tumbleBetter(%player, %time, %force)
{
//===========
// Force
//===========
// 0 = Tumble for %time, then stop if it's safe. Regain control of
//player after clicking.
// 1 = Tumble for %time, then stop if it's safe. Regain control of
//player automatically.
// 2 = Tumble for %time, then stop wether it's safe or not. Regain
//control of player after clicking.
// 3 = Tumble for %time, then stop wether it's safe or not. Regain
//control of player automatically.

if(!isObject(%player))
{
return;
}

if(%player.getClassName() !$= "Player")
{
return;
}

if(%player.getState() $= "Dead")
{
return;
}

if(%time < -1)
{
%time = 2000;
}

%currVehicle = %player.getObjectMount();
%client = %player.client;

%newCar = new WheeledVehicle()
{
dataBlock = deathVehicle;
client = %client;
initialPosition = %player.getPosition();
};

missionCleanup.add(%newCar);

%newCar.setVelocity("0 0 0");

if(!isObject(%newCar))
{
return;
}

%newCar.applyImpulse(%newCar.getPosition(), vectorScale(%newCar.getVelocity() * -1, %newCar.getDataBlock().mass));

%player.canDismount = false;

%newCar.setTransform(%player.getTransform());
%newCar.applyImpulse( %newCar.getPosition(), vectorScale(%player.getVelocity(), %newCar.getDataBlock().mass));

%newCar.mountObject(%player, 0);

if(%time != -1)
{
%newCar.schedule(%time, tumbleCheckBetter, %force);
}

if(isObject(%client.camera))
{
%client.camera.setMode("Corpse", %player);
%client.setControlObject(%client.camera);
}
}

function vehicle::tumbleCheckBetter(%obj, %force)
{
%obj.getDataBlock().tumbleCheckBetter(%obj, %force);
}

function deathVehicle::tumbleCheckBetter(%data, %obj, %force)
{
%player = %obj.getMountedObject(0);
%client = %player.client;

if(vectorLen(%obj.getVelocity()) < 1 || %obj.getWaterCoverage() > 0.3 || %force >= 2)
{
if(isObject(%player))
{
%player.canDismount = true;
%player.stopSkiing();
}

%obj.unMountObject(%player);
%obj.schedule(0, delete);

if(%force == 1 || %force >= 3)
{
if(isObject(%client))
{
%client.camera.getDataBlock().onTrigger(%client.camera, 0, 1);
%client.camera.getDataBlock().schedule(50, onTrigger, %client.camera, 0, 0);
}

else
{
%player.setControlObject(%player);
}
}
}

else if(isObject(%player))
{
%obj.schedule(1000, tumbleCheckBetter, %force);
}
}

NOTE: The tumbleBetter function requires Item_Skis to work.
« Last Edit: August 30, 2014, 08:03:59 AM by jes00 »

you could also make tumble just call tumbleBetter.

then stop if it's safe.
What does this mean?
For me, a %force of 0 or 1, it never stops tumbling. I tumble until I'm still on the ground, and I continue clicking but I'm still in control of camera

What does this mean?
If you've stopped tumbling and are now safe from fall damage.
For me, a %force of 0 or 1, it never stops tumbling. I tumble until I'm still on the ground, and I continue clicking but I'm still in control of camera
Are you sure you're using it right? Maybe you have another add-on interfering? It works fine for me.

Well I'll look into it more later
I'll put out the update once I know what the call the four "types" (one for each "force")

Well I'll look into it more later
I'll put out the update once I know what the call the four "types" (one for each "force")
I personally prefer types 1 and 3. But I included the other two for people who wanted to keep it closer to the original tumble function.

EDIT: I was able to replicate your bug. I'll fix it tomorrow. It seems to only happen if %time is around 3000 or lower.
« Last Edit: August 29, 2014, 06:06:13 AM by jes00 »

Thank you for this.

Fixed the bug Headcrab Zombie found. Please use the new code instead.