[SOLVED]Need help assigning IDs -
superrobot48 - 23.05.2014
So am planning to create a gang system which needs IDs can anyone please teach me how to assign IDs to each gang and load them? i know there are a lot of FS out there but i still like to create my own 1! so guys please help me
EDIT: +REP will surely be given
Re : Need help assigning IDs -
S4t3K - 23.05.2014
Use an enumerator + an array, then put all the vars about the gangs inside, such as
PHP код:
enum 1gangInfo
{
gangID,
gangLeader,
gangMembers,
gangName[],
};
new infoGang[MAX_GANGS][1gangInfo];
Then, when you create a gang with an InGame command, use a for loop to check if a gang id is free (start your gangs id from 1), and if it is, use it !
PHP код:
new g;
for(g = 0; g < MAX_GANGS; g++)
{
if(infoGang[g][gangID] == 0) break;
}
infoGang[g][gangID] = g;
// etc
if you need more explainations, then just ask.
Re: Need help assigning IDs -
Rittik - 23.05.2014
Take a global variable
Код:
new gangid;//insert this at the top of your gamemode
When player registers/creates a gang ,create an increment to the variable like this
Re: Need help assigning IDs -
superrobot48 - 23.05.2014
Quote:
Originally Posted by S4t3K
Use an enumerator + an array, then put all the vars about the gangs inside, such as
PHP код:
enum 1gangInfo
{
gangID,
gangLeader,
gangMembers,
gangName[],
};
new infoGang[MAX_GANGS][1gangInfo];
Then, when you create a gang with an InGame command, use a for loop to check if a gang id is free (start your gangs id from 1), and if it is, use it !
PHP код:
new g;
for(g = 0; g < MAX_GANGS; g++)
{
if(infoGang[g][gangID] == 0) break;
}
infoGang[g][gangID] = g;
// etc
if you need more explainations, then just ask.
|
The first part is okay , but explain the 2nd part please, Thankyou for your very fast reply
Quote:
Originally Posted by Rittik
Take a global variable
Код:
new gangid;//insert this at the top of your gamemode
When player registers/creates a gang ,create an increment to the variable like this
|
That might be a bit hard
Re : Need help assigning IDs -
S4t3K - 23.05.2014
The incrementation is more simple than you shows.
PHP код:
new gangid = 8;
gangid++; // Gangid's value is 9
// You can also use the incrementation before the var name
++gangid; // Without using the incrementation before, gangid's value is also 9. Else, it will be 10.
The difference between the "++" pos (before or after) is explained through a condition :
PHP код:
new stuff = 15;
new myAge = 16;
if(myAge == ++stuff) // Will be true
if(myAge == stuf++) // Will be false
In the first condition, stuff is incremented before the condition is checked.
In the second one, stuff is incremented after the condition is checked.
But on both, stuff will be 16 after checking.
EDIT :
The second part is very simple.
It's used to get the lowest gang id from 0, which will be useful to order the gangs using their IDs.
The loop checks each value of the array (MAX_GANGS is not defined of course, define it as the value as you want.
G is initialized, then g is compared to MAX_GANGS, and if g is smaller than MAX_GANGS, g will be incremented.
After doing everything which is between the brackets of the for loop, the program will come back to the comparison, etc, etc.
My loop checks (inside) if gangID's value is 0. If it is, the loops stop and I use g out of the loop (I don't like working in the loops, it's a personnal habits, if you prefer to work in, do as you want), which value is the value of the array which not contains a gang created (a bit hard to understand, anyway), and it's used as an external ID to complete and assign values to the enumerator.
Re: Re : Need help assigning IDs -
superrobot48 - 23.05.2014
Quote:
Originally Posted by S4t3K
The incrementation is more simple than you shows.
PHP код:
new gangid = 8;
gangid++; // Gangid's value is 9
// You can also use the incrementation before the var name
++gangid; // Without using the incrementation before, gangid's value is also 9. Else, it will be 10.
The difference between the "++" pos (before or after) is explained through a condition :
PHP код:
new stuff = 15;
new myAge = 16;
if(myAge == ++stuff) // Will be true
if(myAge == stuf++) // Will be false
In the first condition, stuff is incremented before the condition is checked.
In the second one, stuff is incremented after the condition is checked.
But on both, stuff will be 16 after checking.
|
Yes i know the addition and all but lets think about the saving / loading system tooo!
Re : Need help assigning IDs -
S4t3K - 23.05.2014
i've edited my message, read above.
Re: Need help assigning IDs -
superrobot48 - 23.05.2014
Thanks you SO MUCH!
SOLVED