How is pVeh[4] stored in mysql?
#1

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?
Reply
#2

A new row for each entry. Meaning you will probably need a second table.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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?
Reply
#6

Well as @cool mentioned, arrays are slow rather variable in terms of access time. But yea, for this just an enum would be enough.
Reply
#7

Look my last post up, it's edited.
Reply
#8

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.
Reply
#9

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.
Reply
#10

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.
Reply
#11

then you may need a [playerid] index. new pElite[MAX_PLAYERS][4];
Because you want to check if any player was in that faction.
Reply
#12

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]; 
Reply
#13

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 
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:
Reply
#14

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,';'); 
Reply
#15

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?
Reply
#16

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.
Reply
#17

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
Reply
#18

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
Reply
#19

Quote:
Originally Posted by Vince
Посмотреть сообщение
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
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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)