View Single Post
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