#include <amxmodx>
#include <fakemeta>
#include <engine>
#define PLUGIN "3rd person view (2)"
#define VERSION "1.4"
#define AUTHOR "The_Thing"
new g_3rdview_toggle
new Maxplayers
new bool:change_3rdview[33]
new bool:g_changemodel[33]
new g_ent_playermodel[33]
new g_ent_weaponmodel[33]
new Float:user_check_time[33]
new cvar_viewtype
public plugin_precache()
{
precache_model("models/rpgrocket.mdl")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_3rdview_toggle = register_cvar("amx_3rdview", "1")
register_concmd("changeview", "change_personal_view", ADMIN_USER, "- 3rd view toggle")
register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
register_event("DeathMsg", "event_Death", "a")
register_event("ResetHUD", "event_NewRound", "be")
cvar_viewtype = register_cvar("view_type", "1")
Maxplayers = get_maxplayers()
}
public fw_PlayerPreThink(id)
{
if (!get_pcvar_num(g_3rdview_toggle))
return FMRES_IGNORED;
if (!is_user_alive(id))
return FMRES_IGNORED;
if (is_user_bot(id))
return FMRES_IGNORED;
if (!change_3rdview[id])
return FMRES_IGNORED;
static Float:time
time = get_gametime()
if (time < user_check_time[id])
return FMRES_IGNORED;
user_check_time[id] = time + 0.1
Set_User_Model(id)
return FMRES_IGNORED;
}
public check_user_weapon_model(id)
{
fm_set_weaponmodel_ent(id)
}
public client_connect(id)
{
change_3rdview[id] = false
}
public client_disconnect(id)
{
change_3rdview[id] = false
}
public event_Death()
{
if (!get_pcvar_num(g_3rdview_toggle))
return;
new id = read_data( 2 )
if (!(1 <= id <= Maxplayers))
return;
if (is_user_bot(id))
return;
if (!change_3rdview[id])
{
fm_set_playermodel_ent(id)
g_changemodel[id] = true
}
}
public event_NewRound(id)
{
if (!get_pcvar_num(g_3rdview_toggle))
return;
if (is_user_bot(id))
return;
if (is_user_alive(id))
{
if (g_changemodel[id])
Recover_User_Model(id)
change_3rdview[id] = false
set_view(id, CAMERA_NONE)
set_task(0.112, "change_personal_view", id)
}
}
public change_personal_view(id)
{
if (!get_pcvar_num(g_3rdview_toggle))
return;
if (!is_user_alive(id))
return;
change_3rdview[id] = !change_3rdview[id]
if (change_3rdview[id])
{
new type = get_pcvar_num(cvar_viewtype)
if (type < 1 || type > 3 )
type = 0
Set_User_Model(id)
set_view(id, type)
}
else
{
Recover_User_Model(id)
set_view(id, CAMERA_NONE)
}
}
public Set_User_Model(id)
{
fm_set_playermodel_ent(id)
fm_set_weaponmodel_ent(id)
g_changemodel[id] = true
}
public Recover_User_Model(id)
{
fm_remove_model_ents(id)
fm_set_rendering(id, kRenderFxNone, 0, 0, 0, kRenderNormal, 255)
g_changemodel[id] = false
}
// Set Player Model on Entity
stock fm_set_playermodel_ent(id)
{
// Make original player entity invisible
// but without hiding shadows or firing effects
fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransTexture, 0)
// Format model string
static player_model[32], model[100]
fm_get_user_model(id, player_model, sizeof player_model - 1)
formatex(model, sizeof model - 1, "models/player/%s/%s.mdl", player_model, player_model)
// Set model on entity or make a new one if unexistant
if (!pev_valid(g_ent_playermodel[id]))
{
g_ent_playermodel[id] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if (!pev_valid(g_ent_playermodel[id])) return;
set_pev(g_ent_playermodel[id], pev_classname, "player_model")
set_pev(g_ent_playermodel[id], pev_movetype, MOVETYPE_FOLLOW)
set_pev(g_ent_playermodel[id], pev_aiment, id)
set_pev(g_ent_playermodel[id], pev_owner, id)
}
engfunc(EngFunc_SetModel, g_ent_playermodel[id], model)
}
// Set Weapon Model on Entity
stock fm_set_weaponmodel_ent(id)
{
// Get player's p_ weapon model
static model[100]
pev(id, pev_weaponmodel2, model, sizeof model - 1)
// Set model on entity or make a new one if unexistant
if (!pev_valid(g_ent_weaponmodel[id]))
{
g_ent_weaponmodel[id] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if (!pev_valid(g_ent_weaponmodel[id])) return;
set_pev(g_ent_weaponmodel[id], pev_classname, "weapon_model")
set_pev(g_ent_weaponmodel[id], pev_movetype, MOVETYPE_FOLLOW)
set_pev(g_ent_weaponmodel[id], pev_aiment, id)
set_pev(g_ent_weaponmodel[id], pev_owner, id)
}
engfunc(EngFunc_SetModel, g_ent_weaponmodel[id], model)
}
// Remove Custom Model Entities
stock fm_remove_model_ents(id)
{
// Remove "playermodel" ent if present
if (pev_valid(g_ent_playermodel[id]))
{
engfunc(EngFunc_RemoveEntity, g_ent_playermodel[id])
g_ent_playermodel[id] = 0
}
// Remove "weaponmodel" ent if present
if (pev_valid(g_ent_weaponmodel[id]))
{
engfunc(EngFunc_RemoveEntity, g_ent_weaponmodel[id])
g_ent_weaponmodel[id] = 0
}
}
// Get User Model -model passed byref-
stock fm_get_user_model(player, model[], len)
{
get_user_info(player, "model", model, len)
}
stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
static Float:color[3]
color[0] = float(r)
color[1] = float(g)
color[2] = float(b)
set_pev(entity, pev_renderfx, fx)
set_pev(entity, pev_rendercolor, color)
set_pev(entity, pev_rendermode, render)
set_pev(entity, pev_renderamt, float(amount))
}