[MySQL] Need help with vehicle system
#1

So, the idea is, that a player can buy up to 3 vehicles of his choice. I've got a table vehicle, where all the bought vehicles are stored.

Sorry for the big image, [SPOILER][/SPOILER] not working for me .

I'm worried what will happen if, let's say, some player sells his car (ID 23) to dealership (not implemented, just a idea), and the code has to delete the vehicles row from database?

What will happen to all the other rows? If I had about 30, what happens when I delete the 23rd?

Will there be a missing ID in between 22nd and 24th row? I think that would cause problems.

I'm a new scripter to SA:MP, pawn, programming in general, so I have a hard time to figure this out.

And, sorry for my bad English .
Reply
#2

Absolutely nothing will happen to the other rows. Of course there will be a missing ID between the 22nd and the 24th row which should cause no problems at all. That is just an auto increment identifier for each row. The other rows will keep their initial auto increment IDs. For instance, if you have 30 rows and you delete the 23rd the next auto increment ID won't be 23 but 31 and so on.
Reply
#3

So then it is okay to have missing IDs? Will try creating a few rows, then delete some to test this out.

Still working fine. Good to know that it won't break anything.
Reply
#4

Quote:
Originally Posted by RageCraftLV
Посмотреть сообщение
So then it is okay to have missing IDs? Will try creating a few rows, then delete some to test this out.

Still working fine. Good to know that it won't break anything.
As long as you get the auto increment ID from each row in your script and you work with it when performing some MySQL instruction like UPDATE, DELETE, etc. No problem whatsoever. There's no problem in having holes in the auto increment column.
Reply
#5

Instead of deleting unused rows, I suggest creating a new column for this table called "active" and set value to 0 if that row won't be used in the future. That way you don't have to create same stuff over again if mistake is to happen. Avoid deleting anything from tables as long as you are 100% sure you won't need such data in the future.
Reply
#6

Quote:
Originally Posted by Konewka
Посмотреть сообщение
Instead of deleting unused rows, I suggest creating a new column for this table called "active" and set value to 0 if that row won't be used in the future. That way you don't have to create same stuff over again if mistake is to happen. Avoid deleting anything from tables as long as you are 100% sure you won't need such data in the future.
So you are suggesting that I create 3 vehicle rows for every player and set them active or not? Sounds like a pretty good idea.
Reply
#7

Quote:
Originally Posted by RageCraftLV
Посмотреть сообщение
So you are suggesting that I create 3 vehicle rows for every player and set them active or not? Sounds like a pretty good idea.
No, don't care about missing rows.
Don't set rows as active or inactive because they just take useless memory space.
You can do that if you want to restore a player vehicle after it got deleted.

When you INSERT vehicle's data get the auto incremented ID and insert it into an enum.
Use that for saving, it's an unique ID which won't get repeated until you drop the table and create it again.
Reply
#8

Missing rows won't make a problem, however the habit of doing this for player vehicles might be good. For example, I have a table with faction cars, job cars and player-owned cars, I delete rows from faction and job cars because they don't have a monetary value and it's not a data that would be needed even if it gets deleted somehow I can just create a new faction car, however for player-owned vehicles since they have a value and no-one wants to accidently give a new car to someone(a.k.a money in-game) for him being a liar but somehow has proof of a non-existing vehicle, that's why I handle player-owned cars just the same way as others but instead of deleting information I simply set the vehicle as inactive, therefore it's still there and I can literally restore it by changing 1 variable and I have a 100% proof he really had this car. It's still really up to you, it won't make a problem no matter which way you choose.
Reply
#9

I think that I will go the row deactivation route. Thanks for the help, guys!
Reply
#10

if you have auto increment in id, you can have 1 2 3 4 5 lets say. if you delete row 3 from database, next time you load vehicles there will be loaded 4 vehicles. no matter what you do. A vehicles database id number cannot be in game vehicle idbecause in case of creating cars with code, it will collide with your saved cars. DB id's are commonly used for saving vehicles again like after color change or if you put gun in it. so deleting a row doesnt affect your gameplay in anyway.

If you are interested in getting more info about it ask me in pm i will give you my skype so i can explain better
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)