All pastes #938691 Raw Edit

Untitled

public text v1 · immutable
#938691 ·published 2008-03-11 20:26 UTC
rendered paste body
//==============================================================================

#include <a_samp>

//==============================================================================

forward MoveGates (  );

//==============================================================================

new Gates [ 999 ];

new Float: GatePositions [ 999 ] [ 6 ];

new Float: MoveDistance [ 999 ];

new Float: MoveSpeed [ 999 ];

new MAX_GATES = 0;

//==============================================================================

stock GetDistanceToPoint ( playerid , Float: x2 ,Float: y2 , Float:z2 )
{
	new Float: dis;
	new Float: x1, Float: y1 ,Float: z1;

	GetPlayerPos ( playerid , x1 , y1 , z1 );
	dis = floatsqroot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
	return floatround ( dis );
}

//==============================================================================

stock CreateGate ( modelid , Float: X , Float: Y , Float: Z , Float: XR , Float: YR , Float: ZR , Float: MoveX , Float: MoveY , Float: MoveZ , Float: Move_Distance , Float: Move_Speed )
{
    GatePositions [ MAX_GATES ] [ 0 ] = X;
    GatePositions [ MAX_GATES ] [ 1 ] = Y;
    GatePositions [ MAX_GATES ] [ 2 ] = Z;
    
    GatePositions [ MAX_GATES ] [ 3 ] = MoveX;
    GatePositions [ MAX_GATES ] [ 4 ] = MoveY;
    GatePositions [ MAX_GATES ] [ 5 ] = MoveZ;
    
    MoveSpeed [ MAX_GATES ] = Move_Speed;
    
    MoveDistance [ MAX_GATES ] = Move_Distance;
    
    Gates [ MAX_GATES ] = CreateObject ( modelid , X , Y , Z , XR , YR , ZR );
    
    MAX_GATES = MAX_GATES += 1;
    
    return MAX_GATES - 1;
}

//==============================================================================

public MoveGates ( )
{
	for ( new gateid = 0; gateid < MAX_GATES; gateid ++ )
	{
		new IsPlayerCloseToGate = 0;
		
		for ( new playerid = 0; playerid < MAX_PLAYERS; playerid ++ )
		{
			if ( IsPlayerConnected ( playerid ) )
			{
				if ( GetDistanceToPoint ( playerid ,GatePositions [ gateid ] [ 0 ] , GatePositions [ gateid ] [ 1 ] , GatePositions [ gateid ] [ 2 ] ) < MoveDistance [ gateid ] )
				{
                    IsPlayerCloseToGate = 1;
				}
			}
		}
		
		if ( IsPlayerCloseToGate == 1 )
		{
			MoveObject ( Gates [ gateid ] , GatePositions [ gateid ] [ 3 ] , GatePositions [ gateid ] [ 4 ] , GatePositions [ gateid ] [ 5 ] , MoveSpeed [ gateid ] );
		}
		else
		{
	    	MoveObject ( Gates [ gateid ] , GatePositions [ gateid ] [ 0 ] , GatePositions [ gateid ] [ 1 ] , GatePositions [ gateid ] [ 2 ] , MoveSpeed [ gateid ] );
		}
	}
}

//==============================================================================

stock BeginGateTimer ( )
{
    SetTimer ( "MoveGates" , 1 , true );
}

//==============================================================================