AMXX-BG.INFO pmodel.inc Raw include

pmodel.inc

Original include source with line numbers.

Back Download .inc
1 #if defined P_MODEL_INCLUDED
2 #endinput
3 #endif
4 #define P_MODEL_INCLUDED
5
6 #include <fakemeta>
7 #include <cstrike>
8
9 stock __PlayerModels[33][64];
10 stock __SetClientKeyValue = INVALID_HANDLE;
11
12 /*
13 * Precaches player model.
14 * Also attempts to precache the "T" file if it exists.
15 *
16 * model[] model name (e.g. "vip").
17 * late set to true if precaching model not in plugin_precache().
18 *
19 * @return model index.
20 */
21 stock PrecachePlayerModel(const model[], bool:late = false)
22 {
23 new path[128], ret;
24 formatex(path, charsmax(path), "models/player/%s/%s.mdl", model, model);
25 late ? (ret = engfunc(EngFunc_PrecacheModel, path)) : (ret = precache_model(path));
26
27 formatex(path, charsmax(path), "models/player/%s/%sT.mdl", model, model);
28
29 if (file_exists(path))
30 late ? engfunc(EngFunc_PrecacheModel, path) : precache_model(path);
31
32 return ret;
33 }
34
35 /*
36 * Initializes usage of player models.
37 *
38 * use true - use player models, false - stop using player models.
39 *
40 * @NOTE Must call before using SetPlayerModel(). Recommended in plugin_init().
41 */
42 stock UsePlayerModels(bool:use = true)
43 {
44 if (use)
45 {
46 if (__SetClientKeyValue == INVALID_HANDLE)
47 __SetClientKeyValue = register_forward(FM_SetClientKeyValue, "__OnSetClientKeyValue");
48 }
49 else
50 {
51 if (__SetClientKeyValue != INVALID_HANDLE)
52 {
53 unregister_forward(FM_SetClientKeyValue, __SetClientKeyValue);
54 __SetClientKeyValue = INVALID_HANDLE;
55 }
56 }
57 }
58
59 /*
60 * Sets player model.
61 *
62 * client player index.
63 * model[] model name (e.g. "vip"). Leave empty to reset model.
64 */
65 stock SetPlayerModel(client, const model[] = "")
66 {
67 model[0] != EOS ? copy(__PlayerModels[client], charsmax(__PlayerModels[]), model) : (__PlayerModels[client][0] = EOS);
68 set_user_info(client, "model", model);
69 }
70
71 public __OnSetClientKeyValue(client, const buffer[], const key[], const value[])
72 {
73 if (__PlayerModels[client][0] == EOS || !(CS_TEAM_T <= cs_get_user_team(client) <= CS_TEAM_CT) || !equal(key, "model"))
74 return FMRES_IGNORED;
75
76 set_user_info(client, "model", __PlayerModels[client]);
77
78 return FMRES_SUPERCEDE;
79 }