Raised This Month: $32 Target: $400
 8% 

Better way to check if exist other than for loop


Post New Thread Reply   
 
Thread Tools Display Modes
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
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-20-2021 , 05:42   Re: Better way to check if exist other than for loop
Reply With Quote #12

if you want to use an unknown/infinite amount of skills use dynamic arrays.

i'd suggest to take alook at oxcicrom xp/skill plugin.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-20-2021 at 05:43.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 04-21-2021 , 21:40   Re: Better way to check if exist other than for loop
Reply With Quote #13

Quote:
Originally Posted by Natsheh View Post
if you want to use an unknown/infinite amount of skills use dynamic arrays.

i'd suggest to take alook at oxcicrom xp/skill plugin.
I did read his and it somewhat like my second attempt
Also, what he used is not random but manually so he doesn't have to think about it doing multiple loop because it "randomly" fall into the obtained skill multiple time
__________________
My plugin:

Last edited by Celena Luna; 04-21-2021 at 21:46.
Celena Luna is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 04-22-2021 , 04:22   Re: Better way to check if exist other than for loop
Reply With Quote #14

Quote:
Originally Posted by Celena Luna View Post
I did read his and it somewhat like my second attempt
Also, what he used is not random but manually so he doesn't have to think about it doing multiple loop because it "randomly" fall into the obtained skill multiple time
Did you tried the code that I gave you in post #5?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 04-22-2021 , 05:41   Re: Better way to check if exist other than for loop
Reply With Quote #15

Quote:
Originally Posted by Shadows Adi View Post
Did you tried the code that I gave you in post #5?
- Player have max 30 level (which is why the second number is 30)
- g_TotalSkill is the number of skill that registered via a native #9
PHP Code:
g_PlayerSkill[Playerid][PlayerLevel] = skillid 
it's what I tried to do not
PHP Code:
g_PlayerSkill[Playerid][Skillid
But it did give me some ideas to try out:

- I did modified to what I need but it will make the number of skill pre-defined rather than dynamic (tbh, I am fine with that at this point)
__________________
My plugin:

Last edited by Celena Luna; 04-22-2021 at 05:43.
Celena Luna is offline
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 23:10.


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