Raised This Month: $32 Target: $400
 8% 

KnifeModels Error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MayroN
Senior Member
Join Date: Aug 2017
Location: Kyiv
Old 05-24-2018 , 07:34   KnifeModels Error
Reply With Quote #1

Tell me how to fix the error

PHP Code:
L 05/24/2018 02:20:06Invalid cellvector handle provided (1:9:9
L 05/24/2018 02:20:06: [AMXXDisplaying debug trace (plugin "KnifeModels.amxx"
L 05/24/2018 02:20:06: [AMXXRun time error 10native error (native "ArrayGetArray"
L 05/24/2018 02:20:06: [AMXX] [0KnifeModels.sma::player_spawn (line 80
PHP Code:
public player_spawn(id

if(
is_user_bot(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id]) 

g_bFirstTime[id] = false 
new iRandom random_num(0g_iKnivesNum);
g_iKnife[id] = iRandom;
ArrayGetArray(g_aKnivesiRandomg_eKnife[id]);
OnSelectKnife(id);


All code
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <formatin>
#include <hamsandwich>

#define PLUGIN_VERSION "2.0"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"

enum
{
    
SOUND_NONE 0,
    
SOUND_DEPLOY,
    
SOUND_HIT,
    
SOUND_HITWALL,
    
SOUND_SLASH,
    
SOUND_STAB
}

enum _:Knives
{
    
NAME[32],
    
V_MODEL[128],
    
P_MODEL[128],
    
DEPLOY_SOUND[128],
    
HIT_SOUND[128],
    
HITWALL_SOUND[128],
    
SLASH_SOUND[128],
    
STAB_SOUND[128],
    
FLAG,
    
bool:HAS_CUSTOM_SOUND
}

new 
mcbTEST
new Array:g_aKnives,
    
bool:g_bFirstTime[33],
    
g_eKnife[33][Knives],
    
g_iKnife[33],
    
g_pAtSpawn,
    
g_iKnivesNum,
    
g_iSayText

public plugin_init()
{
    
register_plugin("Knife Models"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXKnifeModels"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
    if(!
g_iKnivesNum)
        
set_fail_state("No knives found in the configuration file.")
    
    
register_dictionary("KnifeModels.txt")
    
    
register_event("CurWeapon""OnSelectKnife""be""1=1""2=29")
    
RegisterHam(Ham_CS_RoundRespawn"player""OnPlayerSpawn"1)
    
register_forward(FM_EmitSound,    "OnEmitSound")
    
    
register_clcmd("knife""ShowMenu")
    
    
g_pAtSpawn register_cvar("km_open_at_spawn""1")
    
g_iSayText get_user_msgid("SayText")
}

public 
client_authorized(id

if(
is_user_bot(id)) set_task(0.1"register_bot"id);

public 
register_bot(id

RegisterHamFromEntity(Ham_Spawnid"player_spawn"1


public 
player_spawn(id

if(
is_user_bot(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id]) 

g_bFirstTime[id] = false 
new iRandom random_num(0g_iKnivesNum);
g_iKnife[id] = iRandom;
ArrayGetArray(g_aKnivesiRandomg_eKnife[id]);
OnSelectKnife(id);

}

public 
client_connect(id)
{
        
client_cmd(id"bind ^"x^" ^"knife^"")     
    return 
PLUGIN_CONTINUE
}

public 
plugin_precache()
{
    
g_aKnives ArrayCreate(Knives)
    
ReadFile()
}

public 
plugin_end()
    
ArrayDestroy(g_aKnives)

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/KnifeModels.ini"szConfigsName)
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[160], szKey[32], szValue[128]
        new 
eKnife[Knives]
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS';': continue
                case 
'[':
                {
                    if(
szData[strlen(szData) - 1] == ']')
                    {
                        if(
g_iKnivesNum)
                            
PushKnife(eKnife)
                            
                        
g_iKnivesNum++
                        
replace(szDatacharsmax(szData), "[""")
                        
replace(szDatacharsmax(szData), "]""")
                        
copy(eKnife[NAME], charsmax(eKnife[NAME]), szData)
                    }
                    else continue
                }
                default:
                {
                    
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '=')
                    
trim(szKey); trim(szValue)
                    
                    if(
equal(szKey"FLAG"))
                        
eKnife[FLAG] = read_flags(szValue)
                    else if(
equal(szKey"V_MODEL"))
                    {
                        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"P_MODEL"))
                    {
                        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"DEPLOY_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HIT_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HITWALL_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"SLASH_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"STAB_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                }
            }
        }
        
        if(
g_iKnivesNum)
            
PushKnife(eKnife)
        
        
fclose(iFilePointer)
    }
}

public 
client_putinserver(id)
{
    
g_bFirstTime[id] = true
    ArrayGetArray
(g_aKnives0g_eKnife[id])
    
g_iKnife[id] = 0
}

public 
OnEmitSound(idiChannel, const szSample[])
{
    if(!
is_user_connected(id) || !g_eKnife[id][HAS_CUSTOM_SOUND] || !is_knife_sound(szSample))
        return 
FMRES_IGNORED
    
    
switch(detect_knife_sound(szSample))
    {
        case 
SOUND_DEPLOY: if(g_eKnife[id][DEPLOY_SOUND][0]) { play_knife_sound(idg_eKnife[id][DEPLOY_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HIT: if(g_eKnife[id][HIT_SOUND][0]) { play_knife_sound(idg_eKnife[id][HIT_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HITWALL: if(g_eKnife[id][HITWALL_SOUND][0]) { play_knife_sound(idg_eKnife[id][HITWALL_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_SLASH: if(g_eKnife[id][SLASH_SOUND][0]) { play_knife_sound(idg_eKnife[id][SLASH_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_STAB: if(g_eKnife[id][STAB_SOUND][0]) { play_knife_sound(idg_eKnife[id][STAB_SOUND][0]); return FMRES_SUPERCEDE; }
    }
    
    return 
FMRES_IGNORED
}

public 
ShowMenu(id)
{
    new 
szTitle[128]
    
formatex(szTitlecharsmax(szTitle), "%L"id"KM_MENU_TITLE")
    
        
mcbTEST menu_makecallback("mcb_TEST")
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
eKnife[Knives], iFlags get_user_flags(id), ig_iKnivesNumi++)
    {
        
ArrayGetArray(g_aKnivesieKnife)
        
        if(
eKnife[FLAG] == ADMIN_ALL || iFlags eKnife[FLAG])
            
menu_additem(iMenuformatin("%s %s"eKnife[NAME], g_iKnife[id] == formatin(""id"") : formatin("")), eKnife[NAME], .callback mcbTEST)
        else
            
menu_additem(iMenuformatin(""eKnife[NAME], id""), eKnife[NAME], eKnife[FLAG], .callback mcbTEST)
    }
    
    if(
menu_pages(iMenu) > 1)
        
menu_setprop(iMenuMPROP_TITLEformatin("%s"szTitleid""))
    
        
menu_setprop(iMenuMPROP_PERPAGE0);     
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
mcb_TEST(idmenuitem)
{
if(
item == g_iKnife[id]) return ITEM_DISABLED

return ITEM_ENABLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        if(
g_iKnife[id] == iItem)
            
ColorChat(id"%L"id"")
        else
        {
            
g_iKnife[id] = iItem
            ArrayGetArray
(g_aKnivesiItemg_eKnife[id])
            
            if(
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
                
OnSelectKnife(id)
            
            new 
szName[32], iUnused
            menu_item_getinfo
(iMenuiItemiUnusedszNamecharsmax(szName), .callback iUnused)
            
ColorChat(id"%L"id"KM_CHAT_SELECTED"szName)
        }
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
OnPlayerSpawn(id)
{
    if(
is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])
    {
        
g_bFirstTime[id] = false
        ShowMenu
(id)
    }
}

public 
OnSelectKnife(id)
{
    
set_pev(idpev_viewmodel2g_eKnife[id][V_MODEL])
    
set_pev(idpev_weaponmodel2g_eKnife[id][P_MODEL])
}

PushKnife(eKnife[Knives])
{
    if(!
eKnife[V_MODEL][0])
        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), DEFAULT_V)
        
    if(!
eKnife[P_MODEL][0])
        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), DEFAULT_P)
        
    
ArrayPushArray(g_aKniveseKnife)
}

bool:is_knife_sound(const szSample[])
    return 
bool:equal(szSample[8], "kni"3)

detect_knife_sound(const szSample[])
{
    static 
iSound
    iSound 
SOUND_NONE
    
    
if(equal(szSample"weapons/knife_deploy1.wav"))
        
iSound SOUND_DEPLOY
    
else if(equal(szSample[14], "hit"3))
        
iSound szSample[17] == 'w' SOUND_HITWALL SOUND_HIT
    
else if(equal(szSample[14], "sla"3))
        
iSound SOUND_SLASH
    
else if(equal(szSample[14], "sta"3))
        
iSound SOUND_STAB
        
    
return iSound
}

play_knife_sound(id, const szSound[])
    
engfunc(EngFunc_EmitSoundidCHAN_WEAPONszSound1.0ATTN_NORM0PITCH_NORM)
    
ColorChat(const id, const szInput[], any:...)
{
    new 
iPlayers[32], iCount 1
    
static szMessage[191]
    
vformat(szMessagecharsmax(szMessage), szInput3)
    
format(szMessage[0], charsmax(szMessage), "%L %s"id id LANG_PLAYER"KM_CHAT_PREFIX"szMessage)
    
    
replace_all(szMessagecharsmax(szMessage), "!g""^4")
    
replace_all(szMessagecharsmax(szMessage), "!n""^1")
    
replace_all(szMessagecharsmax(szMessage), "!t""^3")
    
    if(
id)
        
iPlayers[0] = id
    
else
        
get_players(iPlayersiCount"ch")
    
    for(new 
iiCounti++)
    {
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEg_iSayText_iPlayers[i])
            
write_byte(iPlayers[i])
            
write_string(szMessage)
            
message_end()
        }
    }

Thanks a lot for your help
MayroN is offline
Send a message via ICQ to MayroN Send a message via Skype™ to MayroN
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-24-2018 , 08:03   Re: KnifeModels Error
Reply With Quote #2

Why are you registering a separate player spawn event for bots when there's already one for all players? That error doesn't make any sense. It says that the array is not created yet, but the creation is in plugin_precache() which should be called before the spawn event.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
MayroN
Senior Member
Join Date: Aug 2017
Location: Kyiv
Old 05-24-2018 , 08:28   Re: KnifeModels Error
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
Why are you registering a separate player spawn event for bots when there's already one for all players? That error doesn't make any sense. It says that the array is not created yet, but the creation is in plugin_precache() which should be called before the spawn event.
Write please, as correctly need to
MayroN is offline
Send a message via ICQ to MayroN Send a message via Skype™ to MayroN
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-24-2018 , 09:48   Re: KnifeModels Error
Reply With Quote #4

???
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
MayroN
Senior Member
Join Date: Aug 2017
Location: Kyiv
Old 05-24-2018 , 12:16   Re: KnifeModels Error
Reply With Quote #5

Quote:
Originally Posted by OciXCrom View Post
???

PHP Code:
public OnPlayerSpawn(id

    if(
is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id]) 
    { 
        
g_bFirstTime[id] = false 
        ShowMenu
(id
    }
    if(
is_user_bot(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])  
    {  
        
g_bFirstTime[id] = false  
        
new iRandom random_num(0g_iKnivesNum); 
        
g_iKnife[id] = iRandom
        
ArrayGetArray(g_aKnivesiRandomg_eKnife[id]); 
        
OnSelectKnife(id);
    }

But it still error and random knives no

Last edited by MayroN; 05-24-2018 at 12:23.
MayroN is offline
Send a message via ICQ to MayroN Send a message via Skype™ to MayroN
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 05-24-2018 , 13:51   Re: KnifeModels Error
Reply With Quote #6

Your index is out of array's bounds.

It throws the error when you try to look into the 9th cell of the array, but the array has only 9 items (cell indices: 0..8 ).

Assuming your g_iKnivesNum variable is reliable (stores the number of knives accurately), this should fix it:

PHP Code:
new iRandom random_num(0g_iKnivesNum 1); 

Last edited by akcaliberg; 05-24-2018 at 14:01.
akcaliberg is offline
MayroN
Senior Member
Join Date: Aug 2017
Location: Kyiv
Old 05-24-2018 , 14:53   Re: KnifeModels Error
Reply With Quote #7

Quote:
Originally Posted by akcaliberg View Post
PHP Code:
new iRandom random_num(0g_iKnivesNum 1); 
Thanks for your good advice
+Found an even better option.Replaced it
PHP Code:
public player_spawn(id)  
{  
if(
is_user_bot(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])  
{  
g_bFirstTime[id] = false  
new iRandom random_num(0g_iKnivesNum); 
g_iKnife[id] = iRandom
ArrayGetArray(g_aKnivesiRandomg_eKnife[id]); 
OnSelectKnife(id); 
}  

By that
PHP Code:
public player_spawn(id

        if(
is_user_bot(id))
        
g_iKnife[id] = random_num(0g_iKnivesNum -1);
        
ArrayGetArray(g_aKnivesg_iKnife[id], g_eKnife[id]); 

It's better.And the mistake disappeared
MayroN is offline
Send a message via ICQ to MayroN Send a message via Skype™ to MayroN
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 19:14.


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