#include <amxmodx>
#include <nvault>
#include <reapi>
const FV_MIN = 80; //Min value.
const FV_DEFAULT = 90; //Default value.
const FV_MAX = 130; //Max value.
const MAX_LEN_BUFFER = 64;
enum any: DATA {
NVAULT,
MSG
};
new
g_szNameNvault[] = "FOV",
eGame[DATA],
g_UserFov[MAX_PLAYERS +1] = {FV_DEFAULT, ...};
public plugin_init() {
register_plugin("[REAPI] User FOV", "2.04.24", "DEV-CS.RU");
new szNameNvault[] = "FOV";
eGame[NVAULT] = nvault_open(szNameNvault);
if(eGame[NVAULT] == INVALID_HANDLE)
set_fail_state("Couldn t open ^"%s^" nvault file", g_szNameNvault);
register_clcmd("fov", "UTIL_Cmd");
eGame[MSG] = get_user_msgid("SetFOV");
register_message(eGame[MSG], "MSG_SetFov");
RegisterHookChain(RG_CBasePlayer_Spawn, "RG_CBasePlayer_Spawn_Post", true);
}
public plugin_end()
nvault_close(eGame[NVAULT]);
public client_disconnected(id)
g_UserFov[id] = FV_DEFAULT;
public UTIL_Cmd(const id) {
new
szBuffer[MAX_LEN_BUFFER +1],
Fov;
read_args(szBuffer, MAX_LEN_BUFFER);
remove_quotes(szBuffer);
parse(szBuffer, szBuffer, MAX_LEN_BUFFER, szBuffer, MAX_LEN_BUFFER);
UTIL_LimitationValue(true, g_szNameNvault, id, FV_MIN, FV_MAX, str_to_num(szBuffer), Fov);
SET_UserFov(id, Fov);
return PLUGIN_HANDLED;
}
public client_authorized(id, const szAuthid[]) {
new szBuffer[MAX_LEN_BUFFER +1];
enum {
CELL_TIMESTAMP,
CELL_VALUE
};
if(nvault_lookup(eGame[NVAULT], szAuthid, szBuffer[CELL_VALUE], MAX_LEN_BUFFER, szBuffer[CELL_TIMESTAMP]))
g_UserFov[id] = str_to_num(szBuffer[CELL_VALUE]);
}
public MSG_SetFov(mId, mDest, mEntity) {
#define NUM_ARGS 1
if(!is_user_alive(mEntity) || get_msg_arg_int(NUM_ARGS) != FV_DEFAULT)
return;
set_msg_arg_int(NUM_ARGS, get_msg_argtype(NUM_ARGS),g_UserFov[mEntity]);
}
public RG_CBasePlayer_Spawn_Post(const id)
if(is_user_alive(id))
set_member(id, m_iFOV, g_UserFov[id]);
SET_UserFov(const id, const Fov) {
message_begin(MSG_ONE_UNRELIABLE, eGame[MSG], .player = id);
write_byte(Fov);
message_end();
UTIL_SaveUserFov(id, Fov);
}
UTIL_SaveUserFov(const id, const Fov) {
if(!is_user_connected(id))
return;
new szBuffer[MAX_LEN_BUFFER +1];
get_user_authid(id, szBuffer, MAX_LEN_BUFFER +1);
nvault_set(eGame[NVAULT], szBuffer, fmt("%i", Fov));
g_UserFov[id] = Fov;
}
/*
* The value of the variable, if it goes beyond the acceptable limit, is reduced to the limit.
*
* @param bNotif Notification in the chat (true - on, false - off).
* @param szBuffer The prefix for the message.
* @param pUser The player's index (If it is present to receive for the player).
* @param Min Min value.
* @param Max Max value.
* @param NewValue Buffer of the received number.
*
* @return Not returns.
*/
stock UTIL_LimitationValue(const bool:bNotif = false, const szTmp[] = "", const pUser = 0, const Min, const Max, const OldValue, &NewValue) {
if(OldValue < Min) {
NewValue = Min;
if(bNotif)
client_print(pUser, print_chat, "[%s] Min Fov %i", szTmp, Min);
}
else if(OldValue > Max) {
NewValue = Max;
if(bNotif)
client_print(pUser, print_chat, "[%s] Max Fov %i", szTmp, Max);
}
else NewValue = OldValue;
}