AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ham_Spawn not called (https://forums.alliedmods.net/showthread.php?t=244153)

GuskiS 07-14-2014 11:32

Ham_Spawn not called
 
Why isn't Ham_Spawn called when player survives the round? Atleast this isn't working:
PHP Code:

public Ham_Spawn_post(id)
{
    if(
is_user_alive(id))
    {
        
message_begin(MSG_ONEg_pMsgHideWeapon_id);
        
write_byte(8);
        
message_end();
    }


It only works if player was dead or just have joined server. After that, I keep seeing my radar, hp, ap.
I wonder, why is that.

EDIT: Let me rephrase it, that message isn't called after player spawn, just after death(in new round) and if he just joined.

Nextra 07-14-2014 11:51

Re: Ham_Spawn not called
 
It is definitely called for everyone immediately after the new round is set up. Please post a complete example plugin.

GuskiS 07-14-2014 12:16

Re: Ham_Spawn not called
 
Thats the whole plugin :D
Ok my bad, it is called, but that message doesn't work in that Ham_Spawn. Wrote in first post a bit clearer.
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

new const g_szPriWeapGive[][] =
{
    
"weapon_ak47",
    
"weapon_m4a1",
    
"weapon_awp",
    
"weapon_m3"
};

new const 
g_szPriWeapName[][] =
{
    
"CV-47",
    
"M4A1",
    
"Magnum",
    
"12 Gauge"
};

new const 
g_iPriWeapAmmo[] =
{
    
90,
    
90,
    
30,
    
32
};

new const 
g_szSecWeapGive[][] =
{
    
"weapon_usp",
    
"weapon_glock18",
    
"weapon_elite",
    
"weapon_deagle"
};

new const 
g_szSecWeapName[][] =
{
    
"K&M .45",
    
"9X19mm",
    
".40 Dual",
    
"Night Hawk"
};

new const 
g_iSecWeapAmmo[] =
{
    
100,
    
120,
    
120,
    
35
};

new 
g_iPlayerWeaps[33], g_pMsgHideWeapon;

public 
plugin_init()
{
    
register_plugin("[TH] Weapons menu""1.0.0""GuskiS");
    
RegisterHam(Ham_Spawn"player""Ham_Spawn_post"1true);
    
g_pMsgHideWeapon get_user_msgid("HideWeapon");
}

public 
Ham_Spawn_post(id)
{
    if(
is_user_alive(id))
    {
        
message_begin(MSG_ONEg_pMsgHideWeapon_id);
        
write_byte(8);
        
message_end();

        
show_weapon_menu(id);
    }
}

public 
show_weapon_menu(id)
{
    if(
is_user_alive(id) && !th_get_playerdata(idPD_HIDDEN))
    {
        static 
menuoption[64], data[3];
        
menu menu_create("Weapon menu""show_weapon_menu_handle");

        if(!
g_iPlayerWeaps[id])
        {
            for(new 
0sizeof(g_szPriWeapName); i++)
            {
                
formatex(optioncharsmax(option), "%s"g_szPriWeapName[i]);
                
num_to_str(idatacharsmax(data));
                
menu_additem(menuoptiondata0);
            }
        }
        else
        {
            for(new 
0sizeof(g_szSecWeapName); i++)
            {
                
formatex(optioncharsmax(option), "%s"g_szSecWeapName[i]);
                
num_to_str(idatacharsmax(data));
                
menu_additem(menuoptiondata0);
            }
        }

        
menu_display(idmenu);
    }
}

public 
show_weapon_menu_handle(idmenuitem)
{
    if(
item == MENU_EXIT || !is_user_alive(id) || th_get_playerdata(idPD_HIDDEN))
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
accesscallbacknum[3];
    
menu_item_getinfo(menuitemaccessnumcharsmax(num), __callback);
    
menu_destroy(menu);

    new 
pick str_to_num(num);
    if(!
g_iPlayerWeaps[id])
    {
        
ham_give_weapon(idg_szPriWeapGive[pick]);
        
cs_set_user_bpammo(idget_weaponid(g_szPriWeapGive[pick]), g_iPriWeapAmmo[pick]);
        
g_iPlayerWeaps[id] = true;
        
show_weapon_menu(id);
    }
    else
    {
        
ham_give_weapon(idg_szSecWeapGive[pick]);
        
cs_set_user_bpammo(idget_weaponid(g_szSecWeapGive[pick]), g_iSecWeapAmmo[pick]);
        
g_iPlayerWeaps[id] = false;
    }

    return 
PLUGIN_HANDLED;



NikKOo31 07-14-2014 12:23

Re: Ham_Spawn not called
 
Have you tried adding client prints to actually know if it is being called or not?

GuskiS 07-14-2014 12:27

Re: Ham_Spawn not called
 
Menu shows up.

klippy 07-14-2014 16:27

Re: Ham_Spawn not called
 
How about adding some delay to it? Perhaps a task with 0.1 or 0.2 second delay. Maybe it gets overridden with a new message for some reason?

GuskiS 07-14-2014 17:47

Re: Ham_Spawn not called
 
Hmm, will try to block it, and send when I need.

NikKOo31 07-14-2014 20:13

Re: Ham_Spawn not called
 
In my experience, prints are always better

PHP Code:

public Ham_Spawn_post(id)
{
    
client_print(idprint_chat"[debug] ham spawn was executed")
    
    if(
is_user_alive(id))
    {
        
message_begin(MSG_ONEg_pMsgHideWeapon_id);
        
write_byte(8);
        
message_end();

        
show_weapon_menu(id);
        
client_print(idprint_chat"[debug] the menu will show up now")
    }
    else
        
client_print(idprint_chat"[debug] the menu won't show because you are not alive yet and KliPPy was right")


Then you will know if the problem is ham_spawn or maybe the menu (?

GuskiS 07-14-2014 21:22

Re: Ham_Spawn not called
 
Like I said, menu is working, the message isn't.

hornet 07-14-2014 23:32

Re: Ham_Spawn not called
 
It can't be the whole plugin because you have removed some things like custom includes.
I tested both the message by itself, and your plugin with the undefined funcs commented out. Both work fine.
Also FYI not going to work until game commencing.


All times are GMT -4. The time now is 21:06.

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