AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   index out of bounds. (https://forums.alliedmods.net/showthread.php?t=86905)

xbatista 03-04-2009 04:56

index out of bounds.
 
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



Arkshine 03-04-2009 05:56

Re: index out of bounds.
 
Attacker can be an entity so > max_clients value. Just check if Attacher is a player. ( 1 <= id <= max_clients )

xbatista 03-04-2009 06:02

Re: index out of bounds.
 
Thanks !

Sn!ff3r 03-04-2009 08:30

Re: index out of bounds.
 
PHP Code:

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



anakin_cstrike 03-04-2009 08:36

Re: index out of bounds.
 
Code:
#define is_player(%1) (1 <= %1 <= g_maxplayers)

Arkshine 03-04-2009 08:38

Re: index out of bounds.
 
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 )

xbatista 03-04-2009 08:38

Re: index out of bounds.
 
OK ok thanks :D
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)
            }
            }



anakin_cstrike 03-04-2009 08:54

Re: index out of bounds.
 
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)

xbatista 03-04-2009 09:05

Re: index out of bounds.
 
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
            } 
            } 



SnoW 03-04-2009 09:09

Re: index out of bounds.
 
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.


All times are GMT -4. The time now is 16:58.

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