void MoveObject(float afAmountX, float afAmountY, float afAmountZ, string &in asObject, float afSpace, float afFreq)
{
if(GetLocalVarInt("Moving"+asObject) == 1)
{
AddDebugMessage("Object already moving", false);
return;
}
SetLocalVarFloat("MoveFreq_"+asObject, afFreq);
SetLocalVarFloat("MoveSpace_"+asObject, afSpace);
SetLocalVarFloat("MoveAmountX_"+asObject, MathSqrt(MathPow(afAmountX, 2)));
SetLocalVarFloat("MoveSpaceX_"+asObject, afSpace);
if(afAmountX < 0)
{
SetLocalVarFloat("MoveSpaceX_"+asObject, -afSpace);
}
SetLocalVarFloat("MoveAmountY_"+asObject, MathSqrt(MathPow(afAmountY, 2)));
SetLocalVarFloat("MoveSpaceY_"+asObject, afSpace);
if(afAmountY < 0)
{
SetLocalVarFloat("MoveSpaceY_"+asObject, -afSpace);
}
SetLocalVarFloat("MoveAmountZ_"+asObject, MathSqrt(MathPow(afAmountZ, 2)));
SetLocalVarFloat("MoveSpaceZ_"+asObject, afSpace);
if(afAmountZ < 0)
{
SetLocalVarFloat("MoveSpaceZ_"+asObject, -afSpace);
}
AddTimer(asObject, 0.0f, "MoveObjectTimer");
}
void MoveObjectTimer(string &in asTimer)
{
SetLocalVarInt("Moving"+asTimer, 1);
if(GetLocalVarFloat("MoveAmountX_"+asTimer) != 0)
{
SetEntityPos(asTimer, GetEntityPosX(asTimer)+GetLocalVarFloat("MoveSpaceX_"+asTimer), GetEntityPosY(asTimer), GetEntityPosZ(asTimer));
AddLocalVarFloat("MoveAmountX_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
if(GetLocalVarFloat("MoveAmountX_"+asTimer) < 0)
{
SetLocalVarFloat("MoveAmountX_"+asTimer, 0);
}
}
if(GetLocalVarFloat("MoveAmountY_"+asTimer) != 0)
{
SetEntityPos(asTimer, GetEntityPosX(asTimer), GetEntityPosY(asTimer)+GetLocalVarFloat("MoveSpaceY_"+asTimer), GetEntityPosZ(asTimer));
AddLocalVarFloat("MoveAmountY_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
if(GetLocalVarFloat("MoveAmountY_"+asTimer) < 0)
{
SetLocalVarFloat("MoveAmountY_"+asTimer, 0);
}
}
if(GetLocalVarFloat("MoveAmountZ_"+asTimer) != 0)
{
SetEntityPos(asTimer, GetEntityPosX(asTimer), GetEntityPosY(asTimer), GetEntityPosZ(asTimer)+GetLocalVarFloat("MoveSpaceZ_"+asTimer));
AddLocalVarFloat("MoveAmountZ_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
if(GetLocalVarFloat("MoveAmountZ_"+asTimer) < 0)
{
SetLocalVarFloat("MoveAmountZ_"+asTimer, 0);
}
}
if(GetLocalVarFloat("MoveAmountX_"+asTimer) == 0 && GetLocalVarFloat("MoveAmountY_"+asTimer) == 0 && GetLocalVarFloat("MoveAmountZ_"+asTimer) == 0)
{
SetLocalVarInt("Moving"+asTimer, 0);
return;
}
AddTimer(asTimer, GetLocalVarFloat("MoveFreq_"+asTimer), "MoveObjectTimer");
}