AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   hats not turning off (https://forums.alliedmods.net/showthread.php?t=335445)

mr_tnctproo 12-05-2021 06:06

hats not turning off
 
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");

    }



Napoleon_be 12-05-2021 06:19

Re: hats not turning off
 
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?

mr_tnctproo 12-05-2021 06:26

Re: hats not turning off
 
Quote:

Originally Posted by Napoleon_be (Post 2765101)
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.

JusTGo 12-05-2021 06:38

Re: hats not turning off
 
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?

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 
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");
    }




All times are GMT -4. The time now is 15:27.

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