Posts: 372
Threads: 98
Joined: Mar 2011
Reputation:
0
I have in player enum pVeh[4] instead of pVehID1, pVehID2, pVehID3...
I think that is better to use 1 variable instead of more of them. Is that correct? Is approaching to the variable easier (like example pVeh[0] = idofvehicle, pVeh[1] = ..., ... instead ov those multiple ones?
How is pVeh[4] stored in mysql?
Posts: 10,066
Threads: 38
Joined: Sep 2007
Reputation:
0
A new row for each entry. Meaning you will probably need a second table.
Posts: 156
Threads: 0
Joined: Jun 2016
Quote:
How is pVeh[4] stored in mysql?
|
It's upto what data type you used to declare the array, as it seems, you were adding vehicle ids to it, then it should be int. So when you save the value of that specific array index into MySQL DB, it would be an int data type.
I might have got your question wrong, so do clarify it, if this isn't what you expecting for.
Posts: 372
Threads: 98
Joined: Mar 2011
Reputation:
0
Than it's better if I make 3/4 variables for each pVehID?
Edit:
ShihabSoft, I just saw your post after I sent my reply.
pVeh variable will contain integer (vehicle id of player). How will I store array into mysql?
Also I have one more example. I have variable pElite and it works for factions.
Short description: Player was leader and now he is elite of that faction. Because there is multiple factions (for example 5) I need to have pElite variable holder for every faction. For example:
pElite[0] = 0; //civilian, can't be elite
pElite[1] = 1; //is elite of faction ID 1
pElite[2] = 0; //isn't elite of faction ID 2
So, how do I store all of these variables into 1 array in MYSQL?
Posts: 156
Threads: 0
Joined: Jun 2016
Well as @cool mentioned, arrays are slow rather variable in terms of access time. But yea, for this just an enum would be enough.
Posts: 372
Threads: 98
Joined: Mar 2011
Reputation:
0
Look my last post up, it's edited.
Posts: 156
Threads: 0
Joined: Jun 2016
You could just loop through the pElite array and create a parseable string out of it.
for example, as shown in your code
Quote:
pElite[0] = 0; //civilian, can't be elite
pElite[1] = 1; //is elite of faction ID 1
pElite[2] = 0; //isn't elite of faction ID 2
|
The string from the for loop would look like "0;1;0" (if you know how to implement that for loop).
Then just save it to a column called pElite in the player table, for retreiving and parse, just grab the string from the colum pElite and use split function with delemeter ";", you would get an array like
str[0] = 0;
str[1] = 1;
str[2] = 2;
You could then assign it to your main pElite array. It's not much complicated, as the way I've described it.
Posts: 637
Threads: 23
Joined: Feb 2013
Reputation:
0
then you may need a [playerid] index. new pElite[MAX_PLAYERS][4];
Because you want to check if any player was in that faction.
Posts: 156
Threads: 0
Joined: Jun 2016
Quote:
cache_get_value(0, "Elite", pEliteString[playerid]);
new ch[5] = ";";
new d = 0;
while(pEliteString[playerid][d] != EOS)
{
if(!strcmp(pEliteString[playerid][d], ch)) printf("pEliteString every char that isn't ch var: ", pEliteString[playerid][d]);
d++;
}
|
That was my idea
BTW, you're comparing a character with a string. You could just use the == operator for that.
PHP код:
new ch = ';';
if(pEliteString[playerid][d] == ch) //do something.
btw, you don't have to hassle around that, you could just use the split function with delemiter ";", like shown below
PHP код:
stock split(const src[], dest[][], const delimiter) //Define this function somewhere else, found at sa-mp wiki
{
new n_pos,num,old,str[1];
str[0] = delimiter;
while(n_pos != -1)
{
n_pos = strfind(src,str,false,n_pos+1);
strmid(dest[num++], src, (!num)?0:old+1,(n_pos==-1)?strlen(src):n_pos,256);
old=n_pos;
}
return 1;
}
new output[20][1]; // 20 == number of maximum ";" would apper, 1 == size of the string between each ";" (in this case it seem to be just 1 or 0, so just defined as 1 at max.
split(pEliteString[playerid],output,';');
Posts: 156
Threads: 0
Joined: Jun 2016
Quote:
printf("pEliteString loop: %s, %s, %s", pEliteString[playerid][0], pEliteString[playerid][1], pEliteString[playerid][2]);
|
lol are you kidding me? Just use the output array that you defined before, instead of the same string, that's where your output is, from the split function.