name = "Look At Your Model",
url = "http://world-source.ru/",
new Handle:g_hOnLookStartPre;
new Handle:g_hOnLookStartPost;
new g_hRef[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
g_hOnLookStartPre = CreateForward(ET_Event, Param_Cell);
g_hOnLookStartPost = CreateForward(ET_Ignore, Param_Cell);
g_hOnLookEnd = CreateForward(ET_Ignore, Param_Cell);
HookEvent("player_death", StopLookEvent, EventHookMode_Post);
HookEvent("player_team", StopLookEvent, EventHookMode_Post);
HookEvent("player_spawn", StopLookEvent, EventHookMode_Post);
RegConsoleCmd("sm_look", LookModelCmd);
PrecacheModel("models/error.mdl");
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
RegPluginLibrary("look_at_your_model");
CreateNative("HookLookModel", HookLookModel_);
CreateNative("LookModel", LookModel_);
public HookLookModel_(Handle:plugin, args)
if ((func = Function:GetNativeCell(1)) != INVALID_FUNCTION)
RemoveFromForward(g_hOnLookStartPre, plugin, func);
AddToForward(g_hOnLookStartPre, plugin, func);
if ((func = Function:GetNativeCell(2)) != INVALID_FUNCTION)
RemoveFromForward(g_hOnLookStartPost, plugin, func);
AddToForward(g_hOnLookStartPost, plugin, func);
if ((func = Function:GetNativeCell(3)) != INVALID_FUNCTION)
RemoveFromForward(g_hOnLookEnd, plugin, func);
AddToForward(g_hOnLookEnd, plugin, func);
public LookModel_(Handle:plugin, args)
return g_hRef[GetNativeCell(1)] != INVALID_ENT_REFERENCE;
public Action:LookModelCmd(client, args)
if (client > 0 && client <= MaxClients && IsPlayerAlive(client) && !StopLook(client))
new Action:result = Plugin_Continue;
Call_StartForward(g_hOnLookStartPre);
if (result != Plugin_Continue)
new entity = CreateEntityByName("prop_dynamic");
if (entity <= MaxClients)
g_hRef[client] = EntIndexToEntRef(entity);
DispatchKeyValue(entity, "model", "models/error.mdl");
DispatchKeyValue(entity, "solid", "0");
//DispatchKeyValue(entity, "spawnflags", "256");
GetClientEyePosition(client, v);
GetClientAbsAngles(client, a);
GetAngleVectors(a, direction, NULL_VECTOR, NULL_VECTOR);
v[0] += direction[0] * 100.0;
v[1] += direction[1] * 100.0;
DispatchKeyValueVector(entity, "origin", v);
DispatchKeyValueVector(entity, "angles", a);
SetEntityRenderMode(entity, RENDER_TRANSCOLOR);
SetEntityRenderColor(entity, 255, 255, 255, 0);
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
SetEntProp(client, Prop_Send, "m_iObserverMode", 1);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 0);
SetEntProp(client, Prop_Send, "m_iFOV", 50);
SetEntityMoveType(client, MOVETYPE_NONE);
SetClientViewEntity(client, entity);
Call_StartForward(g_hOnLookStartPost);
stock bool:StopLook(client, bool:disconnect = false)
if (g_hRef[client] == INVALID_ENT_REFERENCE)
if ((g_hRef[client] = EntRefToEntIndex(g_hRef[client])) > MaxClients)
AcceptEntityInput(g_hRef[client], "Kill");
g_hRef[client] = INVALID_ENT_REFERENCE;
SetClientViewEntity(client, client);
SetEntityMoveType(client, MOVETYPE_WALK);
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", -1);
SetEntProp(client, Prop_Send, "m_iObserverMode", 0);
SetEntProp(client, Prop_Send, "m_bDrawViewmodel", 1);
SetEntProp(client, Prop_Send, "m_iFOV", 90);
Call_StartForward(g_hOnLookEnd);
public OnClientDisconnect(client)
public StopLookEvent(Handle:event, const String:name[], bool:silent)
StopLook(GetClientOfUserId(GetEventInt(event, "userid")));