void get_button_state(bool *a, bool *b, bool *up, bool *down, bool *l, bool *r)
{
	if (a) *a = get_key_pressed(VK_NUMPAD5);
	if (b) *b = get_key_pressed(VK_NUMPAD0) || trainer_switch_pressed() || get_key_pressed(VK_BACK);
	if (up) *up = get_key_pressed(VK_NUMPAD8);
	if (down) *down = get_key_pressed(VK_NUMPAD2);
	if (r) *r = get_key_pressed(VK_NUMPAD6);
	if (l) *l = get_key_pressed(VK_NUMPAD4);
}
bool trainer_switch_pressed()
{
	return (GetTickCount() > trainerResetTime + 1000) && get_key_pressed(VK_F4);
}
void airbrake(bool inVehicle)
{
	// common variables
	Ped playerPed = PLAYER::PLAYER_PED_ID();
	BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(playerPed);

	Vector3 curLocation = ENTITY::GET_ENTITY_COORDS(playerPed, 0);
	Vector3 curRotation = ENTITY::GET_ENTITY_ROTATION(playerPed, 0);
	float curHeading = ENTITY::GET_ENTITY_HEADING(playerPed);
	//float tmpHeading = curHeading += ;

	float rotationSpeed = 2.5;
	float forwardPush;

	switch (travelSpeed)
	{
	case 0:
		forwardPush = 0.2f;
		break;
	case 1:
		forwardPush = 1.8f;
		break;
	case 2:
		forwardPush = 3.6f;
		break;
	}

	float xVect = forwardPush * sin(degToRad(curHeading)) * -1.0f;
	float yVect = forwardPush * cos(degToRad(curHeading));

	KeyInputConfig* keyConfig = get_config()->get_key_config();

	bool moveUpKey =	get_key_pressed(keyConfig->key_airbrake_up);
	bool moveDownKey = get_key_pressed(keyConfig->key_airbrake_down);
	bool moveForwardKey = get_key_pressed(keyConfig->key_airbrake_forward);
	bool moveBackKey = get_key_pressed(keyConfig->key_airbrake_back);
	bool rotateLeftKey = get_key_pressed(keyConfig->key_airbrake_rotate_left);
	bool rotateRightKey = get_key_pressed(keyConfig->key_airbrake_rotate_right);

	//Airbrake controls vehicle if occupied
	if (PED::IS_PED_IN_ANY_VEHICLE(playerPed, 0))
	{
		playerPed = PED::GET_VEHICLE_PED_IS_USING(playerPed);
	}

	BOOL xBoolParam = 1;
	BOOL yBoolParam = 1;
	BOOL zBoolParam = 1;

	ENTITY::SET_ENTITY_VELOCITY(playerPed, 0, 0, 0);
	ENTITY::SET_ENTITY_ROTATION(playerPed, 0, 0, 0, 0, false);
	ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x, curLocation.y, curLocation.z, xBoolParam, yBoolParam, zBoolParam);
	ENTITY::SET_ENTITY_HEADING(playerPed, curHeading);

	if (!inVehicle)
	{
		AI::TASK_PLAY_ANIM(PLAYER::PLAYER_PED_ID(), AIRBRAKE_ANIM_A, AIRBRAKE_ANIM_B, 8.0f, 0.0f, -1, 9, 0, 0, 0, 0);
	}

	if (IsKeyJustUp(keyConfig->key_airbrake_speed))
	{
		travelSpeed++;
		if (travelSpeed > 2)
		{
			travelSpeed = 0;
		}
	}

	create_airbrake_help_text();
	update_airbrake_text();

	if (moveUpKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x, curLocation.y, curLocation.z + forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
	if (moveDownKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x, curLocation.y, curLocation.z - forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
	if (rotateLeftKey)
	{
		ENTITY::SET_ENTITY_HEADING(playerPed, curHeading + rotationSpeed);
	}
	else if (rotateRightKey)
	{
		ENTITY::SET_ENTITY_HEADING(playerPed, curHeading - rotationSpeed);
	}

	/*
	std::stringstream ss2;
	ss2 << "Angle: " << curHeading << "\nXV: " << xVect << "\nYV: " << yVect << "\nCRZ: " << curRotation.z;
	set_status_text(ss2.str());
	*/

	if (moveForwardKey)
	{
		if (moveUpKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x + xVect, curLocation.y + yVect, curLocation.z + forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
		else if (moveDownKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x + xVect, curLocation.y + yVect, curLocation.z - forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
		else{ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x + xVect, curLocation.y + yVect, curLocation.z, xBoolParam, yBoolParam, zBoolParam); }
	}
	else if (moveBackKey)
	{
		if (moveUpKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x - xVect, curLocation.y - yVect, curLocation.z + forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
		else if (moveDownKey){ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x - xVect, curLocation.y - yVect, curLocation.z - forwardPush / 2, xBoolParam, yBoolParam, zBoolParam); }
		else{ ENTITY::SET_ENTITY_COORDS_NO_OFFSET(playerPed, curLocation.x - xVect, curLocation.y - yVect, curLocation.z, xBoolParam, yBoolParam, zBoolParam); }
	}
}
Exemple #4
0
/*
 * The button handler  must be called in the main loop.
 * This function handles the action of all keys. The key debouncing happens
 * in a seperate function called in the timer interrupt routine (in future).
 */
void button_handler(void)
{
	uint32_t keys = get_key_pressed(KEYMASK);

	if(!keys)
	{
		return;
	}

	switch(keys)
	{
		case 1<<BTN_F1:
			bt_handler_f1.callback(bt_handler_f1.args);
		break;
		case 1<<BTN_F2:
			bt_handler_f2.callback(bt_handler_f2.args);
		break;
		case 1<<BTN_F3:
			bt_handler_f3.callback(bt_handler_f3.args);
		break;
		case 1<<BTN_F4:
			bt_handler_f4.callback(bt_handler_f4.args);
		break;
		case 1<<BTN_F5:
			bt_handler_f5.callback(bt_handler_f5.args);
		break;
		case 1<<BTN_F6:
			bt_handler_f6.callback(bt_handler_f6.args);
		break;
		case 1<<BTN_MATH:
			bt_handler_f1.callback(bt_handler_f1.args);
		break;
		case 1<<BTN_CH0:
			bt_handler_ch0.callback(bt_handler_ch0.args);
		break;
		case 1<<BTN_CH1:
			bt_handler_ch1.callback(bt_handler_ch1.args);
		break;
		case 1<<BTN_CH2:
			bt_handler_ch2.callback(bt_handler_ch2.args);
		break;
		case 1<<BTN_CH3:
			bt_handler_ch3.callback(bt_handler_ch3.args);
		break;
		case 1<<BTN_MAINDEL:
			bt_handler_maindel.callback(bt_handler_maindel.args);
		break;
		case 1<<BTN_RUNSTOP:
			bt_handler_runstop.callback(bt_handler_runstop.args);
		break;
		case 1<<BTN_SINGLE:
			bt_handler_single.callback(bt_handler_single.args);
		break;
		case 1<<BTN_CURSORS:
			bt_handler_cursors.callback(bt_handler_cursors.args);
		break;
		case 1<<BTN_QUICKMEAS:
			bt_handler_quickmeas.callback(bt_handler_quickmeas.args);
		break;
		case 1<<BTN_ACQUIRE:
			bt_handler_acquire.callback(bt_handler_acquire.args);
		break;
		case 1<<BTN_DISPLAY:
			bt_handler_display.callback(bt_handler_display.args);
		break;
		case 1<<BTN_EDGE:
			bt_handler_edge.callback(bt_handler_edge.args);
		break;
		case 1<<BTN_MODECOUPLING:
			bt_handler_modecoupling.callback(bt_handler_modecoupling.args);
		break;
		case 1<<BTN_AUTOSCALE:
			bt_handler_autoscale.callback(bt_handler_autoscale.args);
		break;
		case 1<<BTN_SAVERECALL:
			bt_handler_saverecall.callback(bt_handler_saverecall.args);
		break;
		case 1<<BTN_QUICKPRINT:
			bt_handler_quickprint.callback(bt_handler_quickprint.args);
		break;
		case 1<<BTN_UTILITY:
			bt_handler_utility.callback(bt_handler_utility.args);
		break;
		case 1<<BTN_PULSEWIDTH:
			bt_handler_pulsewidth.callback(bt_handler_pulsewidth.args);
		break;

		default:
		break;
	}
}