Отслеживание нажатия кнопки SourcePawn

yarik2oo9

Участник
Сообщения
14
Реакции
0
Необходимо отследить нажатие кнопки, и при true выполнить функцию...
 

FrozDark

Участник
Сообщения
1,769
Реакции
2,050
можно определять лишь нажатия вперед, назад, лево, право, стрельба1 (ЛКМ), стрельба2 (ПКМ), приседание, прыжок, использование и хотьбу
 

FrozDark

Участник
Сообщения
1,769
Реакции
2,050
PHP:
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
	static iPrevButtons[MAXPLAYERS+1];
	
	if ((buttons & IN_USE) && !(iPrevButtons[client] & IN_USE))
	{
		if (OnButtonUsePress(client) != Plugin_Continue)
		{
			buttons &= ~IN_USE;
		}
	}
	else if (!(buttons & IN_USE) && (iPrevButtons[client] & IN_USE))
	{
		OnButtonUseReleased(client);
	}
	iPrevButtons[client] = buttons;
	return Plugin_Continue;
}

Action:OnButtonUsePress(client)
{
	// Игрок нажал на кнопку Е
	// return Plugin_Changed, Plugin_Handled, Plugin_Stop, чтобы запретить игроку нажатие кнопки Е
}

OnButtonUseReleased(client)
{
	// Игрок отпустил кнопку Е
}

можно ещё отслеживать нажатие кнопки TAB

код который поможет определить отдельную кнопку
PHP:
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
	static iPrevButtons[MAXPLAYERS+1];
	
	decl button;
	for (new i = 0; i < MAX_BUTTONS; i++)
	{
		button = (1 << i);
		
		if (buttons & button)
		{
			if (!(iPrevButtons[client] & button))
			{
				if (OnButtonPress(client, button) != Plugin_Continue)
				{
					buttons &= ~button;
				}
			}
		}
		else if (iPrevButtons[client] & button)
		{
			OnButtonRelease(client, button);
		}
	}
	
	iPrevButtons[client] = buttons;
	return Plugin_Continue;
}

Action:OnButtonPress(client, button)
{
	
}

OnButtonRelease(client, button)
{

}

доступные кнопки, кнопки не только ксс, так что некоторые могут не работать
PHP:
#define IN_ATTACK      (1 << 0)
#define IN_JUMP   (1 << 1)
#define IN_DUCK   (1 << 2)
#define IN_FORWARD    (1 << 3)
#define IN_BACK   (1 << 4)
#define IN_USE      (1 << 5)
#define IN_CANCEL      (1 << 6)
#define IN_LEFT   (1 << 7)
#define IN_RIGHT        (1 << 8)
#define IN_MOVELEFT  (1 << 9)
#define IN_MOVERIGHT        (1 << 10)
#define IN_ATTACK2    (1 << 11)
#define IN_RUN      (1 << 12)
#define IN_RELOAD      (1 << 13)
#define IN_ALT1   (1 << 14)
#define IN_ALT2   (1 << 15)
#define IN_SCORE        (1 << 16)       // Used by client.dll for when scoreboard is held down
#define IN_SPEED        (1 << 17)   // Player is holding the speed key
#define IN_WALK   (1 << 18)    // Player holding walk key
#define IN_ZOOM   (1 << 19)    // Zoom key for HUD zoom
#define IN_WEAPON1    (1 << 20) // weapon defines these bits
#define IN_WEAPON2    (1 << 21) // weapon defines these bits
#define IN_BULLRUSH  (1 << 22)
#define IN_GRENADE1  (1 << 23)    // grenade 1
#define IN_GRENADE2  (1 << 24)    // grenade 2
 
Последнее редактирование:
Сверху Снизу