View Single Post
mr_tnctproo
Junior Member
Join Date: Mar 2014
Location: UK
Old 12-05-2021 , 06:58   Re: hats not turning off
Reply With Quote #5

Quote:
Originally Posted by JusTGo View Post
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 
iEntityiMaxPlayersiInfoTarget;

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 1id <= iMaxPlayersid++)
    {
        
iEntity engfunc(EngFunc_CreateNamedEntity,iInfoTarget);
        if(
pev_valid(iEntity))
        {
            
engfunc(EngFunc_SetModeliEntityMODEL);
            
set_pev(iEntitypev_movetypeMOVETYPE_FOLLOW);
            
set_pev(iEntitypev_aimentid);
            
set_pev(iEntitypev_ownerid);
            
entity_set_string(iEntityEV_SZ_classname"SantaHat");
            
szHats[id] = 1;
            
client_print(idprint_chat"Your hat has been added");
        }
    }
}
RemoveHat()
{
    for(new 
id 1id <= iMaxPlayersid++)
    {
        
iEntity engfunc(EngFunc_CreateNamedEntity,iInfoTarget);
        
set_pev(idpev_renderfxkRenderFxNone);
        
set_pev(idpev_rendercolor255,255,255);
        
set_pev(idpev_rendermodekRenderNormal);
        
set_pev(idpev_renderamt0.0);
        
szHats[id] = 0;
        
remove_entity_name("SantaHat");
        
client_print(idprint_chat"Your hat has been removed");
    }

I've added:
PHP Code:
entity_set_string(iEntityEV_SZ_classname"SantaHat"); 
to AddHat()

and I have changed RemoveHat() function from
PHP Code:
RemoveHat()
{
    for(new 
id 1id <= iMaxPlayersid++)
    {
        
iEntity engfunc(EngFunc_FindEntityByStringiEntity"classname"iInfoTarget);
        
engfunc(EngFunc_RemoveEntityiEntity);
        
szHats[id] = 0;
        
client_print(idprint_chat"Your hat has been removed");

    }

to
PHP Code:
RemoveHat()
{
    for(new 
id 1id <= iMaxPlayersid++)
    {
        
iEntity engfunc(EngFunc_CreateNamedEntity,iInfoTarget);
        
set_pev(idpev_renderfxkRenderFxNone);
        
set_pev(idpev_rendercolor255,255,255);
        
set_pev(idpev_rendermodekRenderNormal);
        
set_pev(idpev_renderamt0.0);
        
szHats[id] = 0;
        
remove_entity_name("SantaHat");
        
client_print(idprint_chat"Your hat has been removed");
    }


Last edited by mr_tnctproo; 12-06-2021 at 09:56. Reason: Fixed it
mr_tnctproo is offline