Raised This Month: $ Target: $400
 0% 

Better way to check if exist other than for loop


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 04-16-2021 , 06:02   Better way to check if exist other than for loop
Reply With Quote #1

PHP Code:
new g_PlayerSkill[33][30];

public 
SkillGain(idlevel)
{
    static 
nextskillnextskill random_num(,g_TotalSkill)
    if(!
IsPlayerHasSkill(idnextskill))
    {
        
Set_Skill(idnextskilltrue)
        
g_PlayerSkill[id][level-1] = nextskill
    
}
    else
        
SkillGain(idlevel)    
}

public 
IsPlayerHasSkill(idskillid)
{
    for(new 
i=0i<30i++)
    {
        if(
g_PlayerSkill[id][i] == skillid)
        {
            return 
true
        
}
    }

    return 
false

While running this part, when the number of player's skill obtained is closer to g_TotalSkill, the random might run into the existed skill id multiple time and costing a lot of resource + lag
Is there better way to check it?
__________________
My plugin:

Last edited by Celena Luna; 04-16-2021 at 06:11.
Celena Luna is offline
 



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 17:38.


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