View difference between Paste ID: egdF86M6 and 4cMJbU5p
SHOW: | | - or go back to the newest paste.
1
#include <amxmodx>
2
#include <reapi>
3
4
const ACCESS_FLAG = ADMIN_BAN;
5
6
public plugin_init()
7
{
8
	register_plugin("[ReAPI] AdminFreeLook", "1.0", "ReHLDS Team");
9
10
	if(!is_regamedll()) {
11
		set_fail_state("ReGameDLL is not available");
12
		return;
13
	}
14
15
	RegisterHookChain(RG_GetForceCamera, "GetForceCamera");
16
	RegisterHookChain(RG_CBasePlayer_Observer_IsValidTarget, "Observer_IsValidTarget");
17
}
18
19
public GetForceCamera(const index)
20
{
21
	if (!shouldRunCode())
22
		return HC_CONTINUE;
23
	
24
	if (canFreeLook(index)) {
25
		SetHookChainReturn(ATYPE_INTEGER, 0);
26
		return HC_SUPERCEDE;
27
	}
28
29
	return HC_CONTINUE;
30
}
31
32
public Observer_IsValidTarget(const this, const iPlayerIndex, bool:bSameTeam)
33
{
34
	if (shouldRunCode())
35
		return HC_CONTINUE;
36
37
	if (!is_user_connected(iPlayerIndex))
38
		return HC_CONTINUE;
39
40
	if (iPlayerIndex == this || get_entvar(iPlayerIndex, var_iuser1) > 0 || (get_entvar(iPlayerIndex, var_effects) & EF_NODRAW) || get_member(iPlayerIndex, m_iTeam) == TEAM_UNASSIGNED)
41
		return HC_CONTINUE;
42
43
	// Don't spec observers or players who haven't picked a class yet
44
	if (bSameTeam && get_member(iPlayerIndex, m_iTeam) != get_member(this, m_iTeam))
45
		return HC_CONTINUE;
46
47
	if (canFreeLook(iPlayerIndex)) {
48
		SetHookChainReturn(ATYPE_INTEGER, iPlayerIndex);
49
		return HC_SUPERCEDE;
50
	}
51
52
	return HC_CONTINUE;
53
}
54
55
stock bool:canFreeLook(const index) {
56
	return bool:(get_user_flags(index) & ACCESS_FLAG);
57
}
58
59
stock bool:shouldRunCode()
60
{
61
	return bool:(Float:get_member_game(m_flFadeToBlackValue) <= 0.0
62
		&& Float:get_member_game(m_flForceCameraValue) > 0.0
63
		&& Float:get_member_game(m_flForceChaseCamValue) > 0.0);
64
}