Quote:
Originally Posted by Bugsy
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(id, level)
{
new nextskill;
nextskill = random(1, g_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(id, level)
/* 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(PLUGIN, VERSION, AUTHOR)
// Add your code here...
}
public filter_skill(id, SkillNotHave[MAX_SKILL])
{
static count=0;
for(new i=0; i < MAX_SKILL; i++)
{
if(g_PlayerSkill[id][i] == false)
SkillNotHave[count] = i //Save the skillid here
}
return count
}
public skillGet(id, level)
{
new Buffer[MAX_SKILL], skill_num, nextskill
skill_num = filter_skill(id, Buffer); //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.
__________________