Raised This Month: $62 Target: $400
 15% 

'Invalid hook callback specified' but works anyway?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kashinoda
Member
Join Date: Dec 2017
Old 06-08-2019 , 05:54   'Invalid hook callback specified' but works anyway?
Reply With Quote #1

Hi,

Wondering if anyone can help, I have a simple Weapon Select script which is meant to Unhook whenever a new map loads or !wpclear is called.

It works as intended by I receive this message when loading the plugin.

Quote:
L 06/08/2019 - 11:55:53: [SM] Exception reported: Invalid hook callback specified for game event "round_start"
L 06/08/2019 - 11:55:53: [SM] Blaming: WeaponSelect.smx
L 06/08/2019 - 11:55:53: [SM] Call stack trace:
L 06/08/2019 - 11:55:53: [SM] [0] UnhookEvent
L 06/08/2019 - 11:55:53: [SM] [1] Line 144, WeaponSelect.sp::OnMapStart
[SM] Plugin EZ Weapons reloaded successfully.


PHP Code:
#include <sourcemod>
#include <sdktools>
#include <smlib>

#pragma semicolon 1
#pragma tabsize 0
#pragma newdecls required

public Plugin myinfo 
{
    
name "EZ Weapons",
    
author "Kashinoda",
    
description "Set spawn guns using !wp <gun>",
    
url "https://github.com/kashinoda/",
};

// Weapon Array [0] Item Name, [1] Formatted name, [2] Lookup name, [3] Include Hemlet

char sWeapons[][][] = 
{
    { 
"weapon_ak47""AK-47""ak""1" },
    { 
"weapon_aug""AUG""aug""1" },
    { 
"weapon_awp""AWP""awp""1" },
    { 
"weapon_bizon""PP-Bizon""bizon""1" },
    { 
"weapon_cz75a""CZ-75 Auto""cz""1" },
    { 
"weapon_deagle""Desert Eagle""deag""1" },
    { 
"weapon_elite""Dual Berettas""dualies""1" },
    { 
"weapon_famas""FAMAS""famas""1" },
    { 
"weapon_fiveseven""Five-SeveN""57""1" },
    { 
"weapon_galilar""Galil AR""galil""1" },
    { 
"weapon_glock""Glock-18""glock""0" },
    { 
"weapon_hkp2000""P2000""p2000""0" },
    { 
"weapon_m249""M249""m249""1" },
    { 
"weapon_m4a1""M4A4""m4""1" },
    { 
"weapon_m4a1_silencer""M4A1-S""m4s""1" },
    { 
"weapon_mac10""MAC-10""mac10""1" },
    { 
"weapon_mag7""MAG-7""mag7""1" },
    { 
"weapon_mp7""MP7""mp7""1" },
    { 
"weapon_mp9""MP9""mp9""1" },
    { 
"weapon_negev""Negev""negev""1" },
    { 
"weapon_nova""Nova""nova""1" },
    { 
"weapon_p250""P250""p250""1" },
    { 
"weapon_p90""P90""p90""1" },
    { 
"weapon_sawedoff""Sawed-Off""shorty""1" },
    { 
"weapon_sg556""SG 553""sg""1" },
    { 
"weapon_ssg08""SSG 08""scout""1" },
    { 
"weapon_tec9""Tec-9""tec9""1" },
    { 
"weapon_ump45""UMP-45""ump""1" },
    { 
"weapon_usp_silencer""USP-S""usp""0" },
    { 
"weapon_xm1014""XM1014""xm""1" },
    { 
"weapon_revolver""R8 Revolver""r8""1" },
    { 
"weapon_mp5sd""MP5""mp5""1" },
};

bool bValidSelection;
int iSelectedWeapon;

public 
void OnPluginStart()
{
    
RegAdminCmd("wp"CMD_WPADMFLAG_GENERIC"");
    
RegAdminCmd("wplist"CMD_WPListADMFLAG_GENERIC"");
    
RegAdminCmd("wpclear"CMD_WPClearADMFLAG_GENERIC"");
}

public 
Action CMD_WP(int clientint args)
{
    
char sCmd[20];
    
GetCmdArg(1sCmdsizeof(sCmd));
    
int iWeaponCount sizeof(sWeapons);
    
bValidSelection false;

    
// Iterate through the array and see if any weapons match the command argument

    
for (int iWeaponLookup 0iWeaponLookup iWeaponCountiWeaponLookup++)
    {
        if (
StrEqual(sWeapons[iWeaponLookup][2], sCmd))
        {
            
PrintToChatAll(" \x10~ \x01[\x07GUN MODE\x01] \x10~ \x01[\x05%s \x0BNext Round!\x01] \x10~"sWeapons[iWeaponLookup][1]);
            
iSelectedWeapon iWeaponLookup;
            
bValidSelection true;
            
HookEvent("round_start"EquipPlayers);
        }
    }

    if (
bValidSelection == false)
    {
        
PrintToChatAll(" \x05Cannot find %s, type \x0B!wplist \x05to see correct syntax"sCmd);
    }
}

public 
void EquipPlayers(Event event, const char[] namebool dontBroadcast)
{
    for (
int iClient 1iClient <= MaxClientsiClient++)
    {
        if (
IsClientConnected(iClient) && IsClientInGame(iClient))
        {
            
// Iterate though primary and secondary weapon slots (0=Primary, 1=Secondary, 2=Knife, 3=Grenade, 4=C4)
            
for (int iSlot 0iSlot 2iSlot++)
            {
                
int iEntity;

                
// Grab the entity value for every valid client and every non-empty weapon slot

                
while ((iEntity GetPlayerWeaponSlot(iClientiSlot)) != -1)
                {
                    
// Remove that entity from the client then kill it

                    
RemovePlayerItem(iClientiEntity);
                    
AcceptEntityInput(iEntity"Kill");
                }
            }

            
GivePlayerItem(iClientsWeapons[iSelectedWeapon][0], 0);
            
GivePlayerItem(iClient"weapon_flashbang"0);
            
GivePlayerItem(iClient"weapon_flashbang"0);
            
SetEntProp(iClientProp_Data"m_ArmorValue"1001);

            if (
StrEqual(sWeapons[iSelectedWeapon][3], "0"))
            {
                
SetEntProp(iClientProp_Send"m_bHasHelmet"0);
            }

            else
            {
                
SetEntProp(iClientProp_Send"m_bHasHelmet"1);
            }
        }
    }
}

public 
Action CMD_WPList(int clientint args)
{
    
PrintToChatAll(" \x07Usage: \x01!wp <gun>\x05 awp, scout, ak, m4, m4s, sg, aug, deag, usp, glock, galil, famas, mac10, mp9, mp7, ump, bizon, p90, mp5, m249, mag7, negev, nova, shorty, xm, 57, dualies, p250, tec9, cz, r8, p2000");
}

public 
Action CMD_WPClear(int clientint args)
{
    
PrintToChatAll(" \x05Cleared spawn weapons");
    
UnhookEvent("round_start"EquipPlayers);
}

public 
void OnMapStart()
{
    
UnhookEvent("round_start"EquipPlayers);

__________________

Last edited by Kashinoda; 06-08-2019 at 08:00.
Kashinoda is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 06-08-2019 , 09:07   Re: 'Invalid hook callback specified' but works anyway?
Reply With Quote #2

You're trying to unhook an event that isn't hooked.
CliptonHeist is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-08-2019 , 13:34   Re: 'Invalid hook callback specified' but works anyway?
Reply With Quote #3

Quote:
Originally Posted by Kashinoda View Post
Hi,

Wondering if anyone can help, I have a simple Weapon Select script which is meant to Unhook whenever a new map loads or !wpclear is called.

It works as intended by I receive this message when loading the plugin.





PHP Code:
#include <sourcemod>
#include <sdktools>
#include <smlib>

#pragma semicolon 1
#pragma tabsize 0
#pragma newdecls required

public Plugin myinfo 
{
    
name "EZ Weapons",
    
author "Kashinoda",
    
description "Set spawn guns using !wp <gun>",
    
url "https://github.com/kashinoda/",
};

// Weapon Array [0] Item Name, [1] Formatted name, [2] Lookup name, [3] Include Hemlet

char sWeapons[][][] = 
{
    { 
"weapon_ak47""AK-47""ak""1" },
    { 
"weapon_aug""AUG""aug""1" },
    { 
"weapon_awp""AWP""awp""1" },
    { 
"weapon_bizon""PP-Bizon""bizon""1" },
    { 
"weapon_cz75a""CZ-75 Auto""cz""1" },
    { 
"weapon_deagle""Desert Eagle""deag""1" },
    { 
"weapon_elite""Dual Berettas""dualies""1" },
    { 
"weapon_famas""FAMAS""famas""1" },
    { 
"weapon_fiveseven""Five-SeveN""57""1" },
    { 
"weapon_galilar""Galil AR""galil""1" },
    { 
"weapon_glock""Glock-18""glock""0" },
    { 
"weapon_hkp2000""P2000""p2000""0" },
    { 
"weapon_m249""M249""m249""1" },
    { 
"weapon_m4a1""M4A4""m4""1" },
    { 
"weapon_m4a1_silencer""M4A1-S""m4s""1" },
    { 
"weapon_mac10""MAC-10""mac10""1" },
    { 
"weapon_mag7""MAG-7""mag7""1" },
    { 
"weapon_mp7""MP7""mp7""1" },
    { 
"weapon_mp9""MP9""mp9""1" },
    { 
"weapon_negev""Negev""negev""1" },
    { 
"weapon_nova""Nova""nova""1" },
    { 
"weapon_p250""P250""p250""1" },
    { 
"weapon_p90""P90""p90""1" },
    { 
"weapon_sawedoff""Sawed-Off""shorty""1" },
    { 
"weapon_sg556""SG 553""sg""1" },
    { 
"weapon_ssg08""SSG 08""scout""1" },
    { 
"weapon_tec9""Tec-9""tec9""1" },
    { 
"weapon_ump45""UMP-45""ump""1" },
    { 
"weapon_usp_silencer""USP-S""usp""0" },
    { 
"weapon_xm1014""XM1014""xm""1" },
    { 
"weapon_revolver""R8 Revolver""r8""1" },
    { 
"weapon_mp5sd""MP5""mp5""1" },
};

bool bValidSelection;
int iSelectedWeapon;

public 
void OnPluginStart()
{
    
RegAdminCmd("wp"CMD_WPADMFLAG_GENERIC"");
    
RegAdminCmd("wplist"CMD_WPListADMFLAG_GENERIC"");
    
RegAdminCmd("wpclear"CMD_WPClearADMFLAG_GENERIC"");
}

public 
Action CMD_WP(int clientint args)
{
    
char sCmd[20];
    
GetCmdArg(1sCmdsizeof(sCmd));
    
int iWeaponCount sizeof(sWeapons);
    
bValidSelection false;

    
// Iterate through the array and see if any weapons match the command argument

    
for (int iWeaponLookup 0iWeaponLookup iWeaponCountiWeaponLookup++)
    {
        if (
StrEqual(sWeapons[iWeaponLookup][2], sCmd))
        {
            
PrintToChatAll(" \x10~ \x01[\x07GUN MODE\x01] \x10~ \x01[\x05%s \x0BNext Round!\x01] \x10~"sWeapons[iWeaponLookup][1]);
            
iSelectedWeapon iWeaponLookup;
            
bValidSelection true;
            
HookEvent("round_start"EquipPlayers);
        }
    }

    if (
bValidSelection == false)
    {
        
PrintToChatAll(" \x05Cannot find %s, type \x0B!wplist \x05to see correct syntax"sCmd);
    }
}

public 
void EquipPlayers(Event event, const char[] namebool dontBroadcast)
{
    for (
int iClient 1iClient <= MaxClientsiClient++)
    {
        if (
IsClientConnected(iClient) && IsClientInGame(iClient))
        {
            
// Iterate though primary and secondary weapon slots (0=Primary, 1=Secondary, 2=Knife, 3=Grenade, 4=C4)
            
for (int iSlot 0iSlot 2iSlot++)
            {
                
int iEntity;

                
// Grab the entity value for every valid client and every non-empty weapon slot

                
while ((iEntity GetPlayerWeaponSlot(iClientiSlot)) != -1)
                {
                    
// Remove that entity from the client then kill it

                    
RemovePlayerItem(iClientiEntity);
                    
AcceptEntityInput(iEntity"Kill");
                }
            }

            
GivePlayerItem(iClientsWeapons[iSelectedWeapon][0], 0);
            
GivePlayerItem(iClient"weapon_flashbang"0);
            
GivePlayerItem(iClient"weapon_flashbang"0);
            
SetEntProp(iClientProp_Data"m_ArmorValue"1001);

            if (
StrEqual(sWeapons[iSelectedWeapon][3], "0"))
            {
                
SetEntProp(iClientProp_Send"m_bHasHelmet"0);
            }

            else
            {
                
SetEntProp(iClientProp_Send"m_bHasHelmet"1);
            }
        }
    }
}

public 
Action CMD_WPList(int clientint args)
{
    
PrintToChatAll(" \x07Usage: \x01!wp <gun>\x05 awp, scout, ak, m4, m4s, sg, aug, deag, usp, glock, galil, famas, mac10, mp9, mp7, ump, bizon, p90, mp5, m249, mag7, negev, nova, shorty, xm, 57, dualies, p250, tec9, cz, r8, p2000");
}

public 
Action CMD_WPClear(int clientint args)
{
    
PrintToChatAll(" \x05Cleared spawn weapons");
    
UnhookEvent("round_start"EquipPlayers);
}

public 
void OnMapStart()
{
    
UnhookEvent("round_start"EquipPlayers);

https://forums.alliedmods.net/showpo...2&postcount=12
__________________
8guawong is offline
Kashinoda
Member
Join Date: Dec 2017
Old 06-09-2019 , 08:19   Re: 'Invalid hook callback specified' but works anyway?
Reply With Quote #4

Thanks guys
__________________
Kashinoda 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 20:59.


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