Raised This Month: $12 Target: $400
 3% 

Solved Console Keeps Saying Index Out of Bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 08-14-2022 , 08:41   Console Keeps Saying Index Out of Bounds
Reply With Quote #1

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
Attached Files
File Type: sma Get Plugin or Get Source (zp_skull_weapon_all_v3.sma - 72 views - 48.7 KB)

Last edited by asdian; 02-09-2023 at 19:27.
asdian is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 08-14-2022 , 09:12   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #2

Code:
id = pev(ent, pev_owner) if (!is_user_connected(id))     return
jimaway is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-14-2022 , 10:41   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
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.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-14-2022 at 10:43.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 08-14-2022 , 10:41   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
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

Last edited by asdian; 08-14-2022 at 10:53. Reason: to make it clearer
asdian is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-14-2022 , 10:51   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #5

Quote:
Originally Posted by asdian View Post
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 )
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-14-2022 at 10:52.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 08-14-2022 , 11:15   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
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 View Post
Also try debugging the owner output. ( it's value )
where to put ?
asdian is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-14-2022 , 15:34   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #7

Quote:
Originally Posted by asdian View Post
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.
__________________

Last edited by fysiks; 08-14-2022 at 15:35.
fysiks is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 01-17-2023 , 07:16   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
Also try not hard code your script, for example try to give 43 offset it's proper name.
what's wrong with hard code?
asdian is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-17-2023 , 22:23   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #9

Quote:
Originally Posted by asdian View Post
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.
__________________

Last edited by fysiks; 01-17-2023 at 22:24.
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-18-2023 , 06:56   Re: Console Keeps Saying Index Out of Bounds
Reply With Quote #10

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
lexzor 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:45.


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