Jump to content

[Help] How I can do this ?


Recommended Posts

Hi there , I created a script just for practice , and I created also a players table in mysql , and I created a connection.

So I created a row like this to get player cars , I know I know its not right to make vehicles for player in this way , but I said I want to learn about it

Here is my row with vehicles name in players table its default have this values
0:0,0:0,0:0
I think its like a table in mysql Im not sure , I just think it

Ok this is three slots for player vehicles
I wanna to import for it by a function and export too
For example , player bought 3 Infernus , I want to make the row to it after bought
411:3,0:0,0:0
and when slot number one is full going on slot number two
For example again , the player bought another vehicle likes two elegy car
411:3,562:2,0:0
and when player login with onPlayerLogin Event , server create that infernus's


also I put that database sql code for import to view better !

 

-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Apr 25, 2021 at 06:11 PM
-- Server version: 10.4.14-MariaDB
-- PHP Version: 7.4.10

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `mta_server`
--

-- --------------------------------------------------------

--
-- Table structure for table `players`
--

CREATE TABLE `players` (
  `id` int(11) NOT NULL,
  `nick` varchar(32) NOT NULL,
  `password` varchar(64) NOT NULL,
  `money` int(11) NOT NULL DEFAULT 0,
  `vehicles` text NOT NULL DEFAULT '0:0,0:0,0:0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `players`
--

INSERT INTO `players` (`id`, `nick`, `password`, `money`, `vehicles`) VALUES
(1, 'Amell', '46fa16h46e16e84f9e84g6a10e0e1a3s0f56i0jjg6', 26544, '0:0,0:0,0:0');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `players`
--
ALTER TABLE `players`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `players`
--
ALTER TABLE `players`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

 

thanks in advance !

Edited by RevManR
Link to post
  • Moderators
On 25/04/2021 at 18:14, RevManR said:

For example , player bought 3 Infernus , I want to make the row to it after bought
411:3,0:0,0:0
and when slot number one is full going on slot number two
For example again , the player bought another vehicle likes two elegy car
411:3,562:2,0:0

I am not sure why you would invent a new format for your data. You can just use JSON, supported by PHP, JavaScript, Nodejs and even MTA.

local vehicles = {
	{model = 411, slot = 1},
	{model = 562, slot = 2}, 
  	{model = 562, slot = 3},
}

local dataString = toJSON(vehicles) -- text
-- https://wiki.multitheftauto.com/wiki/ToJSON
-- https://wiki.multitheftauto.com/wiki/FromJSON

Normally I wouldn't use JSON for my vehicles, since you want MySQL to take care of that by having a separated vehicle table. Which allows me to fire MySQL queries to find the data, instead of having Lua parsing the JSON data and blocking the MTA thread. But if you are not very familiar with MySQL, JSON is the second best option.

 

 

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...