How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
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?
Re: How is pVeh[4] stored in mysql? -
Vince - 06.05.2017
A new row for each entry. Meaning you will probably need a second table.
Re: How is pVeh[4] stored in mysql? -
coool - 06.05.2017
Quote:
Originally Posted by Saddin
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?
|
Arrays are slower than variables.
Re: How is pVeh[4] stored in mysql? -
ShihabSoft - 06.05.2017
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.
Re: How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
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?
Re: How is pVeh[4] stored in mysql? -
ShihabSoft - 06.05.2017
Well as @cool mentioned, arrays are slow rather variable in terms of access time. But yea, for this just an enum would be enough.
Re: How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
Look my last post up, it's edited.
Re: How is pVeh[4] stored in mysql? -
ShihabSoft - 06.05.2017
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.
Re: How is pVeh[4] stored in mysql? -
Vince - 06.05.2017
Quote:
Originally Posted by Saddin
pVeh variable will contain integer (vehicle id of player). How will I store array into mysql?
|
If you store your vehicles in MySQL and a vehicle can only be owned by one player then all you need to do is add an "owner" column to the vehicle table. This column will store the unique id of the player (not the playerid you get in-game, but the id that is assigned with auto increment).
Quote:
Originally Posted by Saddin
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?
|
I don't quite get it. Who or what can be elite? The faction itself or one or more players of that faction? And can a player be a member of more than one faction? If there is only one elite per faction then it's the same story as the vehicles, add a column to the faction table and store the player's unique id. If there's more than one elite per faction then you need a new table with at least two columns: factionid and userid. See my tutorial on association tables for that.
Re: How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
Quote:
Originally Posted by Vince
I don't quite get it. Who or what can be elite? The faction itself or one or more players of that faction? And can a player be a member of more than one faction? If there is only one elite per faction then it's the same story as the vehicles, add a column to the faction table and store the player's unique id. If there's more than one elite per faction then you need a new table with at least two columns: factionid and userid. See my tutorial on association tables for that.
|
pElite is variable for every player who was leader of some faction.
Example:
I was leader of Faction ID 2, when I'm done with leadership I get elite status in that faction.
Than I can go to other Faction and get leader in for example Faction ID 4, after I'm done there I will get again elite status in that faction.
So at the end it should be something like this:
pElite[2] = 1; // i am elite of faction ID 2
pElite[4] = 1; // i am elite of faction ID 4
Many players can be Elite. Every player that is leader he will get elite of that faction.
I will look now for your tutorial and try to understand it.
Re: How is pVeh[4] stored in mysql? -
coool - 06.05.2017
then you may need a [playerid] index. new pElite[MAX_PLAYERS][4];
Because you want to check if
any player was in that faction.
Re: How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
Quote:
Originally Posted by coool
then you may need a [playerid] index. new pElite[MAX_PLAYERS][4];
Because you want to check if any player was in that faction.
|
I'm already storing it in player enum:
PHP код:
//Player stats
enum pInfo
{
...
pElite[10], //10 factions, 10 elite variables for each faction
...
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Re: How is pVeh[4] stored in mysql? -
Saddin - 06.05.2017
I tried something but it won't work.
Somewhere ondialogresponse for DIALOG_LOGIN:
PHP код:
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++;
}
Mysql string variable:
Re: How is pVeh[4] stored in mysql? -
ShihabSoft - 07.05.2017
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,';');
Re: How is pVeh[4] stored in mysql? -
Saddin - 07.05.2017
PHP код:
cache_get_value(0, "Elite", pEliteString[playerid]);
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,';');
printf("pEliteString loop: %s, %s, %s", pEliteString[playerid][0], pEliteString[playerid][1], pEliteString[playerid][2]);
Output in log: pEliteString loop: 0;0;0;0;0;0;0;0, ;0;0;0;0;0;0;0, 0;0;0;0;0;0;0
Not doing good job...
I need every number that is not ";" to store in pElite[0], pElite[1] ...
How to do it?
Re: How is pVeh[4] stored in mysql? -
ShihabSoft - 07.05.2017
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.
Re: How is pVeh[4] stored in mysql? -
Saddin - 07.05.2017
Quote:
Originally Posted by ShihabSoft
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.
|
tried that but even worse:
Output: pEliteString loop: 00;0;0;0;0;0;0, 0;0;0;0;0;0;0, ;0;0;0;0;0;0
Re: How is pVeh[4] stored in mysql? -
Vince - 07.05.2017
Don't do this. This violates first normal form. You should store your elites in a separate table. Something like this:
http://sqlfiddle.com/#!9/495bb0/2
Re: How is pVeh[4] stored in mysql? -
Saddin - 07.05.2017
Quote:
Originally Posted by Vince
|
That is perfect. I understand that and know what are you talking about but don't have enough knowledge to implement something by myself. Any starting tutorials?