AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Console Keeps Saying Index Out of Bounds (https://forums.alliedmods.net/showthread.php?t=339077)

asdian 08-14-2022 08:41

Console Keeps Saying Index Out of Bounds
 
1 Attachment(s)
I am remaking my old weapon plugin with new system, that is merging them into one single plugin. That's pretty hard for me, really X'D and now i'm facing this problem. Console keeps saying "index out of bounds" and i dont know which one. I have checked many times but still couldn't find the problem.

Error code :

Code:

L 08/14/2022 - 19:29:26: [AMXX] Displaying debug trace (plugin "zp_skull_weapon_all_v3.amxx", version "3.0")
L 08/14/2022 - 19:29:26: [AMXX] Run time error 4: index out of bounds
L 08/14/2022 - 19:29:26: [AMXX]    [0] zp_skull_weapon_all_v3.sma::IsHaveSkull (line 1043)
L 08/14/2022 - 19:29:26: [AMXX]    [1] zp_skull_weapon_all_v3.sma::HamF_ItemDeploy_Post (line 796)

The code :

Code:


#define TOTAL_SKULL 9

enum _:WhichSkull
{
        IS_SK1 = 0,
        IS_SK3,
        IS_SK4,
        IS_SK5,
        IS_SK6,
        IS_SK7,
        IS_SK8,
        IS_SK9,
        IS_SK11
}

new g_had_wpnskull[33][TOTAL_SKULL]


public HamF_ItemDeploy_Post(ent)
{
        if(!pev_valid(ent))
                return
       
        static id, ActiveSlot
        id = pev(ent, pev_owner)
        ActiveSlot = ExecuteHam(Ham_Item_ItemSlot, ent)
       
        if(!IsHaveSkull(id, SLOT_PRI) || !IsHaveSkull(id, SLOT_SEC)) // -> Line 796
                return
               
        static iCsWpnPri, iCsWpnPri2, iCsWpnSec, iCSW;
        iCSW = get_pdata_int(ent,43,4)
        iCsWpnPri = Get_SkullCSW(id, SLOT_PRI)
        iCsWpnPri2 = Get_SkullCSW(id, SLOT_PRI, 1)
        iCsWpnSec = Get_SkullCSW(id, SLOT_SEC)
       
        set_pev(id, pev_viewmodel2, V_MODEL_SKULL[ActiveSlot == 1 ? g_type1[id] : g_type2[id]])
        set_pev(id, pev_weaponmodel2, P_MODEL_SKULL[ActiveSlot == 1 ? g_type1[id] : g_type2[id]])
       
        set_weapon_anim(id, Get_SkullDeployAnim(id, ActiveSlot))
        set_nextattack(ent, id, Get_SkullDeployTime(id, ActiveSlot))
       
        if(ActiveSlot == SLOT_PRI && g_had_wpnskull[id][IS_SK3])
        {
                if(iCSW == iCsWpnPri2)
                {
                        g_skull3_changing[id] = !g_skull3_mode[id]
                        set_weapon_anim(id, g_skull3_mode[id] ? ANIM_DRAW_B : ANIM_CHANGE_TO_B)
                        set_nextattack(ent, id, g_skull3_mode[id] ? 1.0 : 3.03)
                } else if(iCSW == iCsWpnPri) {
                        g_skull3_changing[id] = g_skull3_mode[id]
                        set_weapon_anim(id, g_skull3_mode[id] ? ANIM_CHANGE_TO_A : ANIM_DRAW_A)
                        set_nextattack(ent, id, g_skull3_mode[id] ? 3.03 : 1.0)
                }
        }
}

public IsHaveSkull(id, ActiveSlot)
{
        if(ActiveSlot == SLOT_PRI && g_had_wpnskull[id][IS_SK3]) return 1 // -> Line 1043
        if(ActiveSlot == SLOT_SEC && g_had_wpnskull[id][IS_SK1]) return 1
        return 0
}

What do you guys think is the problem?

PS. ignore the mess please, still WIP

jimaway 08-14-2022 09:12

Re: Console Keeps Saying Index Out of Bounds
 
Code:
id = pev(ent, pev_owner) if (!is_user_connected(id))     return

Natsheh 08-14-2022 10:41

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by jimaway (Post 2786426)
Code:
id = pev(ent, pev_owner) if (!is_user_connected(id))     return

That is not a solution, Ham Item Deploy is never called without a valid player owner..


Post the full code.

Also try not hard code your script, for example try to give 43 offset it's proper name.

asdian 08-14-2022 10:41

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by Natsheh (Post 2786433)
That is not a solution, Ham Item Deploy is never called without a valid player owner..


Post the full code.

i already attached the .sma

it's 1700+ line long, so i think it's not good to copy-paste all of them here

Quote:

Also try not hard code your script, for example try to give 43 offset it's proper name.
got it :up:

Natsheh 08-14-2022 10:51

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by asdian (Post 2786434)
i already attached the .sma

it's 1700+ line long, so i think it's not good to copy-paste all of them here

Make sure you don't have another plugin modifying the weapons owner.

Also try debugging the owner output. ( it's value )

asdian 08-14-2022 11:15

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by Natsheh (Post 2786435)
Make sure you don't have another plugin modifying the weapons owner.

i dont have any other weapon plugins installed

Quote:

Originally Posted by Natsheh (Post 2786435)
Also try debugging the owner output. ( it's value )

where to put ?

fysiks 08-14-2022 15:34

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by asdian (Post 2786437)
where to put ?

By debugging he means to output the value to either the server console (if you have access to the server console) or to a log file (via log_amx) if you don't. You do this where ever you need to know the value of a variable.

asdian 01-17-2023 07:16

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by Natsheh (Post 2786433)
Also try not hard code your script, for example try to give 43 offset it's proper name.

what's wrong with hard code?

fysiks 01-17-2023 22:23

Re: Console Keeps Saying Index Out of Bounds
 
Quote:

Originally Posted by asdian (Post 2797389)
what's wrong with hard code?

Magic Numbers. tl;dr, it is not clear what the value actually means making it hard for people to understand why you chose that number. This will even affect the person who originally wrote the code in the future when they forget why they used that number.

lexzor 01-18-2023 06:56

Re: Console Keeps Saying Index Out of Bounds
 
PHP Code:

enum _:WhichSkull (+=1)
{
    
IS_SK1 0,
    
IS_SK3,
    
IS_SK4,
    
IS_SK5,
    
IS_SK6,
    
IS_SK7,
    
IS_SK8,
    
IS_SK9,
    
IS_SK11
}

new 
g_had_wpnskull[33][WhichSkull



All times are GMT -4. The time now is 11:35.

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