Raised This Month: $ Target: $400
 0% 

index out of bounds.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 03-04-2009 , 04:56   index out of bounds.
Reply With Quote #1

Writes me index out of bounds :/
PHP Code:
new CriticalLevel[33]
#define ch_perlevel 2 
PHP Code:

new counted_hit CriticalLevel[i_Attacker] * ch_perlevel // This is in Hamtake damage.
if(random_num(099) < counted_hit)
{
 
XXXXX

xbatista is offline
Send a message via Skype™ to xbatista
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-04-2009 , 05:56   Re: index out of bounds.
Reply With Quote #2

Attacker can be an entity so > max_clients value. Just check if Attacher is a player. ( 1 <= id <= max_clients )
Arkshine is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 03-04-2009 , 06:02   Re: index out of bounds.
Reply With Quote #3

Thanks !
xbatista is offline
Send a message via Skype™ to xbatista
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 03-04-2009 , 08:30   Re: index out of bounds.
Reply With Quote #4

PHP Code:
bool:is_player(ent)
{
    static 
max_clientsmax_clients get_maxplayers()
    
    if((
<= ent <= max_clients) && is_user_connected(ent))
        return 
true
    
return false

__________________
Join US - custom Zombie Server - Custom Addons:



Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 03-04-2009 , 08:36   Re: index out of bounds.
Reply With Quote #5

Code:
#define is_player(%1) (1 <= %1 <= g_maxplayers)
__________________

anakin_cstrike is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-04-2009 , 08:38   Re: index out of bounds.
Reply With Quote #6

Your code is useless and wrong, Sn!ff3r. Wrong in the way of you should do a check to see if max_clients is already saved ( better to save it out of this function though ) and is_user_connected is not needed. And using a macro would be more appropriate.

Code:
new max_clients ; [...] max_clients = get_maxplayers() [...] #define IsPlayer(%1)  ( 1 <= %1 <= max_clients )
Arkshine is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 03-04-2009 , 08:38   Re: index out of bounds.
Reply With Quote #7

OK ok thanks
Example ^^
PHP Code:
    if(is_user_connected(i_Attacker) || is_user_connected(i_Victim))
    {    
        if( ( 
<= i_Victim <= g_maxplayers) && ( <= i_Attacker <= g_maxplayers) )
        {
                    if(
random_num(099) < counted_hit && CriticalLevel[i_Attacker] > && get_pcvar_num(ch_enable) == && ateam == && ateam != get_user_team i_Victim ) && i_Victim != i_Attacker)
            {
                new 
floatrounded floatround(damage)
                new 
floatrounded2 floatround(counted_dmg)
                
ExecuteHam(Ham_TakeDamagei_Victim0i_Attackercounted_dmg0);
                
client_printcolor(i_Attacker"/ctrNormal damage:/g%d, /ctrCritical damage:/g%d, /ctrTotal damage:/g%d."floatroundedfloatrounded2floatrounded floatrounded2)
            }
            }


Last edited by xbatista; 03-04-2009 at 08:41.
xbatista is offline
Send a message via Skype™ to xbatista
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 03-04-2009 , 08:54   Re: index out of bounds.
Reply With Quote #8

1. You don't need 'is_user_connected'.
2. Just use the macro wich i and ark have post.
3. You can avoid using 2 variables (floatround)
__________________

anakin_cstrike is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 03-04-2009 , 09:05   Re: index out of bounds.
Reply With Quote #9

Quote:
2. Just use the macro wich i and ark have post.
What? ^^ don't understand

Okey full code:
PHP Code:
 new counted_hit CriticalLevel[i_Attacker] * ch_perlevel
    
new counted_health_vampire VampireLevel[i_Attacker] * vm_perlevel
    
new Float:counted_dmg random_float(43.5105.5)
   if(
is_user_connected(i_Attacker) || is_user_connected(i_Victim)) 
    {     
        if( ( 
<= i_Victim <= g_maxplayers) && ( <= i_Attacker <= g_maxplayers) ) 
        { 
                    if(
random_num(099) < counted_hit && CriticalLevel[i_Attacker] > && get_pcvar_num(ch_enable) == && ateam == && ateam != get_user_team i_Victim ) && i_Victim != i_Attacker
            { 
                new 
floatrounded floatround(damage
                new 
floatrounded2 floatround(counted_dmg
                
ExecuteHam(Ham_TakeDamagei_Victim0i_Attackercounted_dmg0); 
                
client_printcolor(i_Attacker"/ctrNormal damage:/g%d, /ctrCritical damage:/g%d, /ctrTotal damage:/g%d."floatroundedfloatrounded2floatrounded floatrounded2
            } 
            } 

xbatista is offline
Send a message via Skype™ to xbatista
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 03-04-2009 , 09:09   Re: index out of bounds.
Reply With Quote #10

Code:
 if(is_user_connected(i_Attacker) || is_user_connected(i_Victim))  
  {      
      if( ( 1 <= i_Victim <= g_maxplayers) && ( 1 <= i_Attacker <= g_maxplayers) )  
      { 
->
Code:
if(IsPlayer(i_Victim) && IsPlayer(i_Attacker))
{
Also remember to remove the one } from there. And ofc you have to use the macro & global variable arkshine posted.
SnoW is offline
Send a message via MSN to SnoW
Reply



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 16:58.


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