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
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 04-20-2021 , 00:48   Re: Better way to check if exist other than for loop
Reply With Quote #11

Quote:
Originally Posted by Bugsy View Post
Ok, how do I determine what skills have already been used and which are free? Which variables store this?

I don't want to waste time (again) with assumptions.
my plan at first was like this"
PHP Code:
#define MAX_LEVLE 30

//Player have 30 level, each time they level up, they will register a new skill into this variable
new g_PlayerSkill[33][MAX_LEVEL], g_TotalSkill

...

public 
getSkill(idlevel)
{
    new 
nextskill
    
nextskill random(1g_TotalSkill//0 was register as placeholder so it start from 1
    
if(!IsHaveSkill(nextskill)) //Check
        
g_PlayerSkill[id][level-1] = nextskill //level - 1 because level start giving skill at level 1 => if level then g_PlayerSkill[id][0] will be unused;
    
else
    {
        
/* here is the problem */
        
getSkill(idlevel
        
/* When the level is higher, the chance of hitting the skill player already got is so high 
        that if a lot of player level up at the same time, lag or even crash will happened */
    

After reading suggestion, I did thought about getting the skill that not have first (Not tested):
PHP Code:
#define MAX_SKILL 45
#define MAX_LEVEL 30
new bool:g_PlayerSkill[33][MAX_SKILL]
new 
g_PlayerSkill_Level[33][MAX_LEVEL]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
// Add your code here...
}

public 
filter_skill(idSkillNotHave[MAX_SKILL])
{
    static 
count=0;
    for(new 
i=0MAX_SKILLi++)
    {
        if(
g_PlayerSkill[id][i] == false
            
SkillNotHave[count] = //Save the skillid here
    
}
    return 
count
}

public 
skillGet(idlevel)
{
    new 
Buffer[MAX_SKILL], skill_numnextskill
    skill_num 
filter_skill(idBuffer); //Getting number of skill available + the array contain all of those skill
    
nextskill random(skill_num); //Ranom it
    
g_PlayerSkill[id][Buffer[nextskill]] = true
    
g_PlayerSkill_Level[id][level-1] = Buffer[nextskill]

Not sure it is better or not since I have to use 1 more 2D Array for this.

Of course
PHP Code:
g_PlayerSkill[33][g_TotalSkill//This is not gonna happened 
so I have to use MAX_SKILL which will be a pain in the future if the skill number increase and I can't count how much it is.
__________________
My plugin:

Last edited by Celena Luna; 04-20-2021 at 04:04.
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 01:37.


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