mr_tnctproo |
12-05-2021 06:58 |
Re: hats not turning off
Quote:
Originally Posted by JusTGo
(Post 2765103)
You are removing/enabling the hats for all players with the current approach, do you want the player to remove only his hat or to not see all hats?
|
ah, and i want to not see all hats but only for this player. the rest of the players can see the hats on others
---------------------------
I've managed to fix it!
For anyone that will want this plugin in the future, here is source code for it:
PHP Code:
#include <amxmodx> #include <engine> #include <fakemeta>
new const MODEL[] = "models/kuleczky/dd2/santa_hat.mdl"; new szHats[33]; new iEntity, iMaxPlayers, iInfoTarget;
public plugin_precache() { precache_model(MODEL); } public client_connect(id) { szHats[id] = 0; } public plugin_init() { new const VERSION[] = "1.3"; register_plugin("Santa Hat", VERSION, "xPaw"); register_clcmd("say /hats", "ToggleHat"); iInfoTarget = engfunc(EngFunc_AllocString, "info_target"); iMaxPlayers = get_maxplayers(); }
public ToggleHat(id) { switch(szHats[id]) { case 0: { AddHat(); } case 1: { RemoveHat(); } } return PLUGIN_HANDLED; } AddHat() { for(new id = 1; id <= iMaxPlayers; id++) { iEntity = engfunc(EngFunc_CreateNamedEntity,iInfoTarget); if(pev_valid(iEntity)) { engfunc(EngFunc_SetModel, iEntity, MODEL); set_pev(iEntity, pev_movetype, MOVETYPE_FOLLOW); set_pev(iEntity, pev_aiment, id); set_pev(iEntity, pev_owner, id); entity_set_string(iEntity, EV_SZ_classname, "SantaHat"); szHats[id] = 1; client_print(id, print_chat, "Your hat has been added"); } } } RemoveHat() { for(new id = 1; id <= iMaxPlayers; id++) { iEntity = engfunc(EngFunc_CreateNamedEntity,iInfoTarget); set_pev(id, pev_renderfx, kRenderFxNone); set_pev(id, pev_rendercolor, 255,255,255); set_pev(id, pev_rendermode, kRenderNormal); set_pev(id, pev_renderamt, 0.0); szHats[id] = 0; remove_entity_name("SantaHat"); client_print(id, print_chat, "Your hat has been removed"); } }
I've added:
PHP Code:
entity_set_string(iEntity, EV_SZ_classname, "SantaHat");
to AddHat()
and I have changed RemoveHat() function from
PHP Code:
RemoveHat() { for(new id = 1; id <= iMaxPlayers; id++) { iEntity = engfunc(EngFunc_FindEntityByString, iEntity, "classname", iInfoTarget); engfunc(EngFunc_RemoveEntity, iEntity); szHats[id] = 0; client_print(id, print_chat, "Your hat has been removed");
} }
to
PHP Code:
RemoveHat() { for(new id = 1; id <= iMaxPlayers; id++) { iEntity = engfunc(EngFunc_CreateNamedEntity,iInfoTarget); set_pev(id, pev_renderfx, kRenderFxNone); set_pev(id, pev_rendercolor, 255,255,255); set_pev(id, pev_rendermode, kRenderNormal); set_pev(id, pev_renderamt, 0.0); szHats[id] = 0; remove_entity_name("SantaHat"); client_print(id, print_chat, "Your hat has been removed"); } }
|