Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #define IsKeyPressed(%1) ( newkeys & %1 ) && !( oldkeys & %1 )
- #define PLAYER_VELOCITY_KEY KEY_SPRINT
- #define VEHICLE_VELOCITY_KEY KEY_HANDBRAKE
- new
- bool:gUseVelocity[ MAX_PLAYERS ] = { true, ... },
- gDirection[ MAX_PLAYERS ] = { 0, ... },
- Float:gPower[ MAX_PLAYERS ] = { 1.0, ... };
- public OnPlayerConnect( playerid )
- {
- gUseVelocity[ playerid ] = true;
- gDirection[ playerid ] = 0;
- gPower[ playerid ] = 1.0;
- return 1;
- }
- public OnPlayerDisconnect( playerid, reason )
- {
- gUseVelocity[ playerid ] = true;
- gDirection[ playerid ] = 0;
- gPower[ playerid ] = 1.0;
- return 1;
- }
- forward zcmd_velocity( playerid, params[] );
- public zcmd_velocity( playerid, params[] )
- {
- gUseVelocity[ playerid ] = !gUseVelocity[ playerid ];
- if ( gUseVelocity[ playerid ] ) SendClientMessage( playerid, 0xffffffff, "Velocity feature enabled" );
- else SendClientMessage( playerid, 0xffffffff, "Velocity feature disabled" );
- return 1;
- }
- forward zcmd_dir( playerid, params[] );
- public zcmd_dir( playerid, params[] )
- {
- if ( isnull( params ) )
- {
- gDirection[ playerid ] = 0;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to forwards" );
- }
- else
- {
- switch ( strval( params ) )
- {
- case 1:
- {
- gDirection[ playerid ] = 1;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to backwards" );
- }
- case 2:
- {
- gDirection[ playerid ] = 2;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to left" );
- }
- case 3:
- {
- gDirection[ playerid ] = 3;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to right" );
- }
- case 4:
- {
- gDirection[ playerid ] = 4;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to up" );
- }
- case 5:
- {
- gDirection[ playerid ] = 5;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to down" );
- }
- default:
- {
- gDirection[ playerid ] = 0;
- SendClientMessage( playerid, 0xffffffff, "Your direction is now set to forwards" );
- }
- }
- }
- return 1;
- }
- forward zcmd_pow( playerid, params[] );
- public zcmd_pow( playerid, params[] )
- {
- if ( isnull( params ) )
- {
- gPower[ playerid ] = 1.0;
- SendClientMessage( playerid, 0xffffffff, "Your power is now set to 1.0" );
- }
- else
- {
- new
- string[ 128 ];
- format( string, 128, "Your power is now set to %.4f", floatstr( params ) );
- SendClientMessage( playerid, 0xffffffff, string );
- gPower[ playerid ] = floatstr( params );
- }
- return 1;
- }
- public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
- {
- if ( gUseVelocity[ playerid ] )
- {
- if ( IsKeyPressed( VEHICLE_VELOCITY_KEY ) )
- {
- if ( IsPlayerInAnyVehicle( playerid ) )
- {
- switch ( gDirection[ playerid ] )
- {
- case 0: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ] ); //forwards
- case 1: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), -gPower[ playerid ] ); //backwards
- case 2: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), -gPower[ playerid ], false ); //left
- case 3: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ], false ); //right
- case 4:
- {
- new
- Float:x,
- Float:y,
- Float:z;
- GetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z );
- SetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z + gPower[ playerid ] ); //up
- }
- case 5:
- {
- new
- Float:x,
- Float:y,
- Float:z;
- GetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z );
- SetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z - gPower[ playerid ] ); //down
- }
- default: AddVehicleVelocityDirection( GetPlayerVehicleID( playerid ), gPower[ playerid ] ); //forwards
- }
- }
- }
- else
- {
- if ( IsKeyPressed( PLAYER_VELOCITY_KEY ) )
- {
- if ( !IsPlayerInAnyVehicle( playerid ) )
- {
- switch ( gDirection[ playerid ] )
- {
- case 0: AddPlayerVelocityDirection( playerid, gPower[ playerid ] ); //forwards
- case 1: AddPlayerVelocityDirection( playerid, -gPower[ playerid ] ); //backwards
- case 2: AddPlayerVelocityDirection( playerid, -gPower[ playerid ], false ); //left
- case 3: AddPlayerVelocityDirection( playerid, gPower[ playerid ], false ); //right
- case 4:
- {
- new
- Float:x,
- Float:y,
- Float:z;
- GetPlayerVelocity( playerid, x, y, z );
- SetPlayerVelocity( playerid, x, y, z + gPower[ playerid ] ); //up
- }
- case 5:
- {
- new
- Float:x,
- Float:y,
- Float:z;
- GetPlayerVelocity( playerid, x, y, z );
- SetPlayerVelocity( playerid, x, y, z - gPower[ playerid ] ); //down
- }
- default: AddPlayerVelocityDirection( playerid, gPower[ playerid ] ); //forwards
- }
- }
- }
- }
- }
- return 1;
- }
- AddVehicleVelocityDirection( vehicleid, Float:power = 1.0, bool:updown = true )
- {
- new
- Float:x,
- Float:y,
- Float:z,
- Float:angle;
- GetVehicleVelocity( vehicleid, x, y, z );
- GetVehicleZAngle( vehicleid, angle );
- switch ( updown )
- {
- case false : //left or right (use negative power for left)
- {
- x += ( power * floatcos( angle, degrees ) );
- y += ( power * floatsin( angle, degrees ) );
- }
- case true : //front or back (use negative power for backwards)
- {
- x += ( power * floatsin( -angle, degrees ) );
- y += ( power * floatcos( -angle, degrees ) );
- }
- }
- SetVehicleVelocity( vehicleid, x, y, z );
- return true;
- }
- AddPlayerVelocityDirection( playerid, Float:power = 1.0, bool:updown = true )
- {
- new
- Float:x,
- Float:y,
- Float:z,
- Float:angle;
- GetPlayerVelocity( playerid, x, y, z );
- GetPlayerFacingAngle( playerid, angle );
- switch ( updown )
- {
- case false : //left or right (use negative power for left)
- {
- x += ( power * floatcos( angle, degrees ) );
- y += ( power * floatsin( angle, degrees ) );
- }
- case true : //front or back (use negative power for backwards)
- {
- x += ( power * floatsin( -angle, degrees ) );
- y += ( power * floatcos( -angle, degrees ) );
- }
- }
- SetPlayerVelocity( playerid, x, y, z );
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement