|
| 1 | +#include <amxmodx> |
| 2 | +#include <amxmisc> |
| 3 | +#include <hamsandwich> |
| 4 | +#include <reapi> |
| 5 | +#include <fakemeta> |
| 6 | +#include <xs> |
| 7 | + |
| 8 | +#define PLUGIN "[API] Player Model" |
| 9 | +#define VERSION "0.9.0" |
| 10 | +#define AUTHOR "Hedgehog Fog" |
| 11 | + |
| 12 | +new g_rgszPlayerModel[MAX_PLAYERS + 1][32]; |
| 13 | +new g_rgszCustomPlayerModel[MAX_PLAYERS + 1][256]; |
| 14 | + |
| 15 | +public plugin_init() { |
| 16 | + register_plugin(PLUGIN, VERSION, AUTHOR); |
| 17 | + |
| 18 | + RegisterHamPlayer(Ham_Spawn, "HamHook_Player_Spawn_Post", .Post = 1); |
| 19 | + |
| 20 | + register_forward(FM_SetClientKeyValue, "FMHook_SetClientKeyValue"); |
| 21 | +} |
| 22 | + |
| 23 | +public plugin_natives() { |
| 24 | + register_library("api_player_model"); |
| 25 | + register_native("PlayerModel_Get", "Native_GetPlayerModel"); |
| 26 | + register_native("PlayerModel_Set", "Native_SetPlayerModel"); |
| 27 | + register_native("PlayerModel_Reset", "Native_ResetPlayerModel"); |
| 28 | + register_native("PlayerModel_Update", "Native_UpdatePlayerModel"); |
| 29 | +} |
| 30 | + |
| 31 | +public Native_GetPlayerModel(iPluginId, iArgc) { |
| 32 | + new pPlayer = get_param(1); |
| 33 | + |
| 34 | + set_string(2, g_rgszCustomPlayerModel[pPlayer], get_param(3)); |
| 35 | +} |
| 36 | + |
| 37 | +public Native_SetPlayerModel(iPluginId, iArgc) { |
| 38 | + new pPlayer = get_param(1); |
| 39 | + get_string(2, g_rgszCustomPlayerModel[pPlayer], charsmax(g_rgszCustomPlayerModel[])); |
| 40 | +} |
| 41 | + |
| 42 | +public Native_ResetPlayerModel(iPluginId, iArgc) { |
| 43 | + new pPlayer = get_param(1); |
| 44 | + @Player_ResetModel(pPlayer); |
| 45 | +} |
| 46 | + |
| 47 | +public Native_UpdatePlayerModel(iPluginId, iArgc) { |
| 48 | + new pPlayer = get_param(1); |
| 49 | + @Player_UpdateModel(pPlayer); |
| 50 | +} |
| 51 | + |
| 52 | +public client_connect(pPlayer) { |
| 53 | + copy(g_rgszCustomPlayerModel[pPlayer], charsmax(g_rgszCustomPlayerModel[]), NULL_STRING); |
| 54 | + copy(g_rgszPlayerModel[pPlayer], charsmax(g_rgszPlayerModel[]), NULL_STRING); |
| 55 | +} |
| 56 | + |
| 57 | +public HamHook_Player_Spawn_Post(pPlayer) { |
| 58 | + @Player_UpdateModel(pPlayer); |
| 59 | +} |
| 60 | + |
| 61 | +public FMHook_SetClientKeyValue(pPlayer, const szInfoBuffer[], const szKey[], const szValue[]) { |
| 62 | + if (equal(szKey, "model")) { |
| 63 | + copy(g_rgszPlayerModel[pPlayer], charsmax(g_rgszPlayerModel[]), szValue); |
| 64 | + |
| 65 | + if (!equal(g_rgszCustomPlayerModel[pPlayer], NULL_STRING)) { |
| 66 | + return FMRES_SUPERCEDE; |
| 67 | + } |
| 68 | + |
| 69 | + return FMRES_IGNORED; |
| 70 | + } |
| 71 | + |
| 72 | + return FMRES_IGNORED; |
| 73 | +} |
| 74 | + |
| 75 | +public @Player_UpdateModel(this) { |
| 76 | + if (!equal(g_rgszCustomPlayerModel[this], NULL_STRING)) { |
| 77 | + new iModelIndex = engfunc(EngFunc_ModelIndex, g_rgszCustomPlayerModel[this]); |
| 78 | + set_user_info(this, "model", ""); |
| 79 | + set_pev(this, pev_modelindex, iModelIndex); |
| 80 | + set_member(this, m_modelIndexPlayer, iModelIndex); |
| 81 | + } else { |
| 82 | + @Player_ResetModel(this); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +public @Player_ResetModel(this) { |
| 87 | + if (equal(g_rgszPlayerModel[this], NULL_STRING)) { |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + static szPath[MAX_RESOURCE_PATH_LENGTH]; |
| 92 | + format(szPath, charsmax(szPath), "models/player/%s/%s.mdl", g_rgszPlayerModel[this], g_rgszPlayerModel[this]); |
| 93 | + |
| 94 | + new iModelIndex = engfunc(EngFunc_ModelIndex, szPath); |
| 95 | + set_user_info(this, "model", g_rgszPlayerModel[this]); |
| 96 | + set_pev(this, pev_modelindex, iModelIndex); |
| 97 | + set_member(this, m_modelIndexPlayer, iModelIndex); |
| 98 | + copy(g_rgszCustomPlayerModel[this], charsmax(g_rgszCustomPlayerModel[]), NULL_STRING); |
| 99 | +} |
0 commit comments