AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 4 (Done) (https://forums.alliedmods.net/showthread.php?t=229003)

Jhob94 10-30-2013 17:10

Run time error 4 (Done)
 
I am using this:
PHP Code:

public plugin_init() {
    
RegisterHam(Ham_TakeDamage"player""ham_TakeDamage_Pre")
}

public 
ham_TakeDamage_Pre(victiminflictorattackerFloat:damagedamage_bits)
{
    if(!
is_user_connected(victim) || !is_user_connected(attacker))
        return 
HAM_IGNORED
        
    
if(g_Knife[attacker] && is_user_alive(attacker) && inflictor == attacker && get_user_weapon(attacker) == CSW_KNIFE)
    {        
        if(
damage >= && damage 30)
            
SetHamParamFloat(4250.0)
        
        else if(
damage >= 30)
            
SetHamParamFloat(4500.0)
    }
    
    return 
HAM_IGNORED



getting this error:
Code:

L 10/30/2013 - 21:40:38: [AMXX] Displaying debug trace (plugin "zbheroex_melee_combat.amxx")
L 10/30/2013 - 21:40:38: [AMXX] Run time error 4: index out of bounds
L 10/30/2013 - 21:40:38: [AMXX]    [0] Untitled.sma::ham_TakeDamage_Pre (line 162) // In that code, line 7


YamiKaitou 10-30-2013 17:20

Re: Run time error 4
 
In that code, line 7 is this
Code:

    if(!is_user_connected(victim) || !is_user_connected(attacker)
I see no error there.

But, given the error message, I'm going to assume that it is actually pointing to this line
Code:

if(g_Knife[attacker] && is_user_alive(attacker) && inflictor == attacker && get_user_weapon(attacker) == CSW_KNIFE)
The error is because attacker is out of range for the array g_Knife

Jhob94 10-30-2013 17:52

Re: Run time error 4
 
Quote:

Originally Posted by YamiKaitou (Post 2054845)
In that code, line 7 is this
Code:

    if(!is_user_connected(victim) || !is_user_connected(attacker)
I see no error there.

But, given the error message, I'm going to assume that it is actually pointing to this line
Code:

if(g_Knife[attacker] && is_user_alive(attacker) && inflictor == attacker && get_user_weapon(attacker) == CSW_KNIFE)
The error is because attacker is out of range for the array g_Knife

So how to fix it?

YamiKaitou 10-30-2013 17:56

Re: Run time error 4
 
Well, make g_Knife larger

Jhob94 10-30-2013 18:02

Re: Run time error 4
 
Quote:

Originally Posted by YamiKaitou (Post 2054865)
Well, make g_Knife larger

new g_Knife[33]

What value should i put then?

YamiKaitou 10-30-2013 18:07

Re: Run time error 4
 
Depends on the value of attacker

fysiks 10-30-2013 18:15

Re: Run time error 4
 
Quote:

Originally Posted by Jhob94 (Post 2054868)
new g_Knife[33]

What value should i put then?

Increasing it is a solution but is likely not the right solution (for it to be "complete" this way you would need to make it the same size as the number of entities that the game can load). It usually happens when an entity is doing the damage where that entity has some entity number greater than 32. Most people that come across this problem just need to filter those entities out.

Jhob94 10-30-2013 18:36

Re: Run time error 4
 
Quote:

Originally Posted by fysiks (Post 2054874)
Most people that come across this problem just need to filter those entities out.

How?

fysiks 10-30-2013 19:50

Re: Run time error 4
 
Quote:

Originally Posted by Jhob94 (Post 2054882)
How?

The same way you do it for anything else. Check if it's a value that you want, if not, don't run the code.

Also, this is an extremely common question here so you can find many threads that talk about it.

ConnorMcLeod 10-31-2013 01:43

Re: Run time error 4
 
Your code is fine, can't throw a bound error on g_Knife[attacker] if g_Knife size is 33 and if you check is_user_connected(attacker) first.
I'm pretty sure the error is somewhere else or that you think you are using that code but you are wrong.

Since you can't give us the exact line it is extremly difficult to say.


All times are GMT -4. The time now is 23:19.

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