Raised This Month: $ Target: $400
 0% 

About looping


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 10-14-2009 , 08:51   About looping
Reply With Quote #1

This called 2 times dunno why... I have only 1 worn item...
For example
Quote:
g_iPlayerItem[attacker][item_id] = 1
g_charcounter = 1
And why it called 2 times? ( I just do debug with client_print inside the task and saw it ,that prints 2 times )
PHP Code:
                for(new item_id 0item_id <= g_charcounter item_id++) 
                {
                    if ( 
g_iPlayerItemWorn[attacker][item_id] && g_iPlayerItem[attacker][item_id] > )
                    {
                        if ( 
item_data[item_id][CHAR_HASP] > )
                        {
                            
set_user_rendering(victimkRenderFxGlowShell02550kRenderTransAlpha20)
                        
                            
set_task1.0"Start_poison_damage"victim TASKID_POISONParamsizeof Param"b");
                            
set_taskfloat(item_data[item_id][CHAR_PDURATION]), "End_poison_damage"victim);
                        }
                    
                        if ( 
item_data[item_id][CHAR_DURABILITY] > )
                        {
                            
Set_Player_Item_Repair(attackeritem_idg_iPlayerItemRepair[attacker][item_id] - 1);
                        }
                    }
                } 
Fuller code :
PHP Code:
public fwd_TraceAttack(victimattackerFloat:damageFloat:direction[3], traceresultdamagebits)
{
    if ( 
attacker == victim || !(<= attacker <= g_iMaxPlayers) )
        return 
HAM_IGNORED;

    new 
counted_dexterityblock_value
    for (new 
item_id 0item_id <= g_charcounteritem_id++)
    {
        
block_value = (g_iPlayerItemWorn[victim][item_id] && g_iPlayerItem[victim][item_id] > && item_data[item_id][CHAR_BLOCK] > item_data[item_id][CHAR_BLOCK] : 0)
    }
    
    
counted_dexterity HEROES_DEXTERITY_PERSTAT[g_PlayerHero[victim]] * g_Dexterity[victim]; 
    new 
Float:counted_strength
    new 
Param[1];
    
Param[0] = attacker;
    
    new 
CsArmorType:iPlayerArmorType;
    new 
iArmor cs_get_user_armor(victimiPlayerArmorType);
    
counted_strength HEROES_STRENGTH_PERSTAT[g_PlayerHero[attacker]] * g_Strength[attacker];
    new 
Float:counted_at_strength = ((counted_strength 10.0) * 4.0);
    new 
Float:counted_defence = (iArmor counted_at_strength ? ( (iArmor counted_at_strength) * 5.0) : 0.0);
    new 
Floatcounted_damage;
    
counted_damage damage counted_strength Set_Player_Damage_Item(victimattacker) - counted_defence + ( g_PlayerHero[attacker] == PALADIN && g_iPaladinSkills[attacker][SKILL_SMITE] > && g_iCurSkill[attacker] == SKILL_SMITE &&
    
Player_WItemType(attackerTYPE_SHIELD) && g_CurrentMana[attacker] >= get_pcvar_num(d2_smite_cost_mana) ? PalSmiteDmg[g_iPaladinSkills[attacker][SKILL_SMITE] - 1] : 0.0 ) + 
    (
g_PlayerHero[attacker] == BARBARIAN && g_iBarbarianSkills[attacker][SKILL_BASH] > && g_iCurSkill[attacker] == SKILL_BASH && g_CurrentMana[attacker] >= get_pcvar_num(d2_bash_cost_mana) ? BarBashDmg[g_iBarbarianSkills[attacker][SKILL_BASH] - 1] : 0.0) +
    (
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_IMPALE] > && g_iCurSkill[attacker] == SKILL_IMPALE && g_CurrentMana[attacker] >= get_pcvar_num(d2_impale_cost_mana) ? AmazonImpaleDmg[g_iAmazonSkills[attacker][SKILL_IMPALE] - 1] : 0.0) + 
    ( 
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_CRITICAL_S] > && random_num0100 ) < AmazonCrit[g_iAmazonSkills[attacker][SKILL_CRITICAL_S] - 1] ? damage 0.0);

    if ( 
g_Player_NearEnt[attacker] || g_Player_NearEntAk[attacker] || g_Player_NearEntCh[attacker] )
    {
        return 
HAM_SUPERCEDE;
    }
    else
    {    

        if ( 
random_num(0get_pcvar_num(d2_max_random_value) ) < (counted_dexterity block_value) )
        {
            
set_hudmessage(01502550.050.3511.51.50.00.03)
            
ShowSyncHudMsg(victimg_SyncHudCreate_Avade "Attack Avaded!" )
            
ShowSyncHudMsg(attackerg_SyncHudCreate_Avade "Attack Missed!" )

            return 
HAM_SUPERCEDE;
        }

        else
        {
            if ( 
g_PlayerHero[victim] == NECROMANCER && g_iNecromancerSkills[victim][SKILL_BONEARMOR] > && g_AbsorbDamage[victim] > )
            {
                
Set_Player_BoneArmorDmg(victimg_AbsorbDamage[victim] - floatround(counted_damage));
                return 
HAM_SUPERCEDE;
            }
            else
            {
                for(new 
item_id 0item_id <= g_charcounter item_id++) 
                {
                    if ( 
g_iPlayerItemWorn[attacker][item_id] && g_iPlayerItem[attacker][item_id] > )
                    {
                        if ( 
item_data[item_id][CHAR_HASP] > )
                        {
                            
set_user_rendering(victimkRenderFxGlowShell02550kRenderTransAlpha20)
                        
                            
set_task1.0"Start_poison_damage"victim TASKID_POISONParamsizeof Param"b");
                            
set_taskfloat(item_data[item_id][CHAR_PDURATION]), "End_poison_damage"victim);
                        }
                    
                        if ( 
item_data[item_id][CHAR_DURABILITY] > )
                        {
                            
Set_Player_Item_Repair(attackeritem_idg_iPlayerItemRepair[attacker][item_id] - 1);
                        }
                    }
                }
                
                if ( 
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_IMPALE] > && g_iCurSkill[attacker] == SKILL_IMPALE
                
&& g_CurrentMana[attacker] >= get_pcvar_num(d2_impale_cost_mana) )
                {
                    
Set_Player_Mana(attackerg_CurrentMana[attacker] - get_pcvar_num(d2_impale_cost_mana) );

                    for(new 
item_id 0item_id <= g_charcounter item_id++) 
                    {
                        if ( 
g_iPlayerItemWorn[victim][item_id] && g_iPlayerItem[victim][item_id] > && item_data[item_id][CHAR_DURABILITY] > 0)
                        {
                            
Set_Player_Item_Repair(victimitem_idg_iPlayerItemRepair[victim][item_id] - ( AmazonImpaleDurab[g_iAmazonSkills[attacker][SKILL_IMPALE] - 1]) );
                        }
                    }
                }

                new 
CsTeams:iTeam cs_get_user_team(victim)
                if( 
iTeam == cs_get_user_team(attacker) )
                {
                    
cs_set_user_team(victimiTeam == CS_TEAM_T CS_TEAM_CT CS_TEAM_T)
                    
ExecuteHamB(Ham_TraceAttackvictimattackerdamagedirectiontraceresultdamagebits)
                    
cs_set_user_team(victimiTeam)
                    return 
HAM_SUPERCEDE;
                }
            }
        }
    }

        return 
HAM_IGNORED;
}
public 
Start_poison_damage(Param[], victim)
{
    
victim -= TASKID_POISON;

    new 
attacker Param[0];

    if ( !
is_user_alive(victim) || !is_user_connected(attacker) )
        return;

    for(new 
item_id 0item_id <= g_charcounter item_id++) 
    {
        
Dmg_Kill_Player(victimattackerfloat(item_data[item_id][CHAR_PDAMAGE]), "poison");
    }

    
client_printcolor(attacker"damage")
}
public 
End_poison_damage(victim)
{
    if ( 
task_existsvictim TASKID_POISON ) )
    {
        if ( 
is_user_connected(victim) )
        {
            
set_user_rendering(victim);
        }

        
remove_taskvictim TASKID_POISON );
    }

__________________

Last edited by xbatista; 10-14-2009 at 08:59.
xbatista is offline
Send a message via Skype™ to xbatista
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-14-2009 , 09:26   Re: About looping
Reply With Quote #2

It is looping twice because your condition allows <= g_charcounter so it will hit at 0 and 1. If you want only once change it to < g_charcounter.
PHP Code:
for(new item_id 0item_id g_charcounter item_id++) 
__________________
Bugsy is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 10-14-2009 , 09:30   Re: About looping
Reply With Quote #3

thanks
__________________
xbatista is offline
Send a message via Skype™ to xbatista
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 10-14-2009 , 12:42   Re: About looping
Reply With Quote #4

bump , I've tryied ,the same :/
__________________

Last edited by xbatista; 10-14-2009 at 13:14.
xbatista is offline
Send a message via Skype™ to xbatista
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-14-2009 , 19:23   Re: About looping
Reply With Quote #5

Then your error lies elsewhere. The below will print 0 once in server console.

PHP Code:
const g_charcounter 1

for(new item_id 0item_id g_charcounter item_id++) 
    
server_print"%d" item_id ); 
__________________
Bugsy is offline
01010111
BANNED
Join Date: Oct 2009
Old 10-15-2009 , 01:15   Re: About looping
Reply With Quote #6

Remember condition is checked after executing for first time the code in the for.
01010111 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-15-2009 , 01:25   Re: About looping
Reply With Quote #7

Depending on what you want to do, use :

for(new item_id = 0; item_id < g_charcounter ; item_id++)

or

for(new item_id = 1; item_id <= g_charcounter ; item_id++)


That's up to you to know which one match your code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 10-15-2009 , 07:06   Re: About looping
Reply With Quote #8

Oh my god! TraceAttack called twice?
I do a debug on the top of TraceAttack and I get printed twice...
PHP Code:
public fwd_TraceAttack(victimattackerFloat:damageFloat:direction[3], traceresultdamagebits)
{
    if ( 
attacker == victim || !(<= attacker <= g_iMaxPlayers) )
        return 
HAM_IGNORED;

    
client_printcolor(attacker"damage")

    new 
counted_dexterityblock_value
    for (new 
item_id 0item_id <= g_charcounteritem_id++)
    {
        
block_value = (g_iPlayerItemWorn[victim][item_id] && g_iPlayerItem[victim][item_id] > && item_data[item_id][CHAR_BLOCK] > item_data[item_id][CHAR_BLOCK] : 0)
    }
    
    
counted_dexterity HEROES_DEXTERITY_PERSTAT[g_PlayerHero[victim]] * g_Dexterity[victim]; 
    new 
Float:counted_strength
    new 
Param[2];
    
Param[0] = attacker;
    
    new 
CsArmorType:iPlayerArmorType;
    new 
iArmor cs_get_user_armor(victimiPlayerArmorType);
    
counted_strength HEROES_STRENGTH_PERSTAT[g_PlayerHero[attacker]] * g_Strength[attacker];
    new 
Float:counted_at_strength = ((counted_strength 10.0) * 4.0);
    new 
Float:counted_defence = (iArmor counted_at_strength ? ( (iArmor counted_at_strength) * 5.0) : 0.0);
    new 
Floatcounted_damage;
    
counted_damage damage counted_strength Set_Player_Damage_Item(victimattacker) - counted_defence + ( g_PlayerHero[attacker] == PALADIN && g_iPaladinSkills[attacker][SKILL_SMITE] > && g_iCurSkill[attacker] == SKILL_SMITE &&
    
Player_WItemType(attackerTYPE_SHIELD) && g_CurrentMana[attacker] >= get_pcvar_num(d2_smite_cost_mana) ? PalSmiteDmg[g_iPaladinSkills[attacker][SKILL_SMITE] - 1] : 0.0 ) + 
    (
g_PlayerHero[attacker] == BARBARIAN && g_iBarbarianSkills[attacker][SKILL_BASH] > && g_iCurSkill[attacker] == SKILL_BASH && g_CurrentMana[attacker] >= get_pcvar_num(d2_bash_cost_mana) ? BarBashDmg[g_iBarbarianSkills[attacker][SKILL_BASH] - 1] : 0.0) +
    (
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_IMPALE] > && g_iCurSkill[attacker] == SKILL_IMPALE && g_CurrentMana[attacker] >= get_pcvar_num(d2_impale_cost_mana) ? AmazonImpaleDmg[g_iAmazonSkills[attacker][SKILL_IMPALE] - 1] : 0.0) + 
    ( 
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_CRITICAL_S] > && random_num0100 ) < AmazonCrit[g_iAmazonSkills[attacker][SKILL_CRITICAL_S] - 1] ? damage 0.0);

    if ( 
g_Player_NearEnt[attacker] || g_Player_NearEntAk[attacker] || g_Player_NearEntCh[attacker] )
    {
        return 
HAM_SUPERCEDE;
    }
    else
    {    

        if ( 
random_num(0get_pcvar_num(d2_max_random_value) ) < (counted_dexterity block_value) )
        {
            
set_hudmessage(01502550.050.3511.51.50.00.03)
            
ShowSyncHudMsg(victimg_SyncHudCreate_Avade "Attack Avaded!" )
            
ShowSyncHudMsg(attackerg_SyncHudCreate_Avade "Attack Missed!" )

            return 
HAM_SUPERCEDE;
        }

        else
        {
            if ( 
g_PlayerHero[victim] == NECROMANCER && g_iNecromancerSkills[victim][SKILL_BONEARMOR] > && g_AbsorbDamage[victim] > )
            {
                
Set_Player_BoneArmorDmg(victimg_AbsorbDamage[victim] - floatround(counted_damage));
                return 
HAM_SUPERCEDE;
            }
            else
            {
                for(new 
item_id 0item_id <= g_charcounter item_id++) 
                {
                    
Param[1] = item_id;
                
                    if ( 
g_iPlayerItemWorn[attacker][item_id] && g_iPlayerItem[attacker][item_id] > )
                    {
                        if ( 
item_data[item_id][CHAR_HASP] > )
                        {
                            
set_user_rendering(victimkRenderFxGlowShell02550kRenderTransAlpha20)
                        
                            
set_task1.0"Start_poison_damage"victim TASKID_POISONParamsizeof Param"b");
                            
set_taskfloat(item_data[item_id][CHAR_PDURATION]), "End_poison_damage"victim);
                        }
                    
                        if ( 
item_data[item_id][CHAR_DURABILITY] > )
                        {
                            
Set_Player_Item_Repair(attackeritem_idg_iPlayerItemRepair[attacker][item_id] - 1);
                        }
                    }
                }
                
                if ( 
g_PlayerHero[attacker] == AMAZON && g_iAmazonSkills[attacker][SKILL_IMPALE] > && g_iCurSkill[attacker] == SKILL_IMPALE
                
&& g_CurrentMana[attacker] >= get_pcvar_num(d2_impale_cost_mana) )
                {
                    
Set_Player_Mana(attackerg_CurrentMana[attacker] - get_pcvar_num(d2_impale_cost_mana) );

                    for(new 
item_id 0item_id <= g_charcounter item_id++) 
                    {
                        if ( 
g_iPlayerItemWorn[victim][item_id] && g_iPlayerItem[victim][item_id] > && item_data[item_id][CHAR_DURABILITY] > 0)
                        {
                            
Set_Player_Item_Repair(victimitem_idg_iPlayerItemRepair[victim][item_id] - ( AmazonImpaleDurab[g_iAmazonSkills[attacker][SKILL_IMPALE] - 1]) );
                        }
                    }
                }

                new 
CsTeams:iTeam cs_get_user_team(victim)
                if( 
iTeam == cs_get_user_team(attacker) )
                {
                    
cs_set_user_team(victimiTeam == CS_TEAM_T CS_TEAM_CT CS_TEAM_T)
                    
ExecuteHamB(Ham_TraceAttackvictimattackerdamagedirectiontraceresultdamagebits)
                    
cs_set_user_team(victimiTeam)
                    return 
HAM_SUPERCEDE;
                }
            }
        }
    }

        return 
HAM_IGNORED;

Oh my god ,how you didn't saw this?
PHP Code:
ExecuteHamB(Ham_TraceAttackvictimattackerdamagedirectiontraceresultdamagebits
-->
PHP Code:
ExecuteHam(Ham_TraceAttackvictimattackerdamagedirectiontraceresultdamagebits
As I read the 'HamB' called mainly.
Now all my bugs dissapear.
That was not LOOP problem lol
__________________

Last edited by xbatista; 10-15-2009 at 07:18.
xbatista is offline
Send a message via Skype™ to xbatista
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-15-2009 , 10:34   Re: About looping
Reply With Quote #9

Don't call a hamB in the same ham function callback or you risk to make an infinite loop.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 10-15-2009 , 10:43   Re: About looping
Reply With Quote #10

Then why you do it in your FFA plugin? :O
__________________
xbatista is offline
Send a message via Skype™ to xbatista
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 22:43.


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