Raised This Month: $12 Target: $400
 3% 

hats not turning off


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mr_tnctproo
Junior Member
Join Date: Mar 2014
Location: UK
Old 12-05-2021 , 06:06   hats not turning off
Reply With Quote #1

Hello,
I edited Santa Hat that's made by xPaw

I've added client command /hats to enable and disable the hats.
The problem is that it enables the hats but after typing /hats, it doesn't remove them.

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);
            
szHats[id] = 1;
            
client_print(idprint_chat"Your hat has been added");
        }
    }
}
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");

    }

mr_tnctproo is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 12-05-2021 , 06:19   Re: hats not turning off
Reply With Quote #2

Nvm, i'll edit this post when i'm done researching your problem.

EDIT: Why don't u just use amx_santahat 0 and restart the map?
__________________

Last edited by Napoleon_be; 12-05-2021 at 06:21.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
mr_tnctproo
Junior Member
Join Date: Mar 2014
Location: UK
Old 12-05-2021 , 06:26   Re: hats not turning off
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
Nvm, i'll edit this post when i'm done researching your problem.

EDIT: Why don't u just use amx_santahat 0 and restart the map?
because I want each player to be able to choose whether they want the hats on or not.
mr_tnctproo is offline
JusTGo
Veteran Member
Join Date: Mar 2013
Old 12-05-2021 , 06:38   Re: hats not turning off
Reply With Quote #4

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?
__________________
JusTGo is offline
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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode