SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/05/2020, 06:58 PM   #1
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Problem pSlot

Hello. I make vehicle slots for the player. I don't remember how it was possible to do it when the MySQL pSlot database is set to 4 and the player has 4 free slots. How can this be done to check the player if he has a free slot or all of it is occupied?
KamilPolska is offline   Reply With Quote
Old 15/05/2020, 08:28 PM   #2
RedGun2015
Huge Clucker
 
RedGun2015's Avatar
 
Join Date: Sep 2015
Location: Romania
Posts: 286
Reputation: 0
Default Re: Problem pSlot

You can do something like this:

PHP Code:

// 4 slots
new player_slots[MAX_PLAYERS][4];

for(new 
04x++)
{
    if(
player_slots[playerid][x] != 0)
    {
        
// slot taken (occupied)
    
}
    else
    {
        
// not taken (available)
    
}


__________________
Here - but - not really here.
RedGun2015 is offline   Reply With Quote
Old 31/05/2020, 09:24 PM   #3
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem pSlot

Yes, but I will have to create columns named VehSlot1, VehSlot2 and so on, right?
KamilPolska is offline   Reply With Quote
Old 31/05/2020, 09:49 PM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,712
Reputation: 1671
Default Re: Problem pSlot

You could, but you also could use one column and store the data of all 4 into one column.
Let's say someone has two vehicles; An NRG (522) and a turismo (451). Slots 3 and 4 are unused (0)
You could save that into one column as: "522 451 0 0"

Then, when loading the data, you can easily use sscanf to retrieve that data:

pawn Code:
//Retrieving the data from MySQL, storing the vehicle slots data into "l_playerVehicles[15]" (datatype should be VARCHAR(15) -max. length of 4 vehicles for this string is 15 characters)
new slot[4];
sscanf(l_playerVehicles, "dddd", slot[0], slot[1], slot[2], slot[3]);

if (slot[0])
{
    //Create vehicle for slot 1
}
if (slot[1])
{
    //Create vehicle for slot 2
}
if (slot[2])
{
    //Create vehicle for slot 3
}
if (slot[3])
{
    //Create vehicle for slot 4
}
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 13/06/2020, 08:32 AM   #5
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem pSlot

Is there any other way? I heard that you can use pCars[MAX_SLOTS] and pCarSlots when loading.
KamilPolska is offline   Reply With Quote
Old 13/06/2020, 08:58 AM   #6
SharpenBlade
Big Clucker
 
Join Date: May 2020
Posts: 182
Reputation: 23
Default Re: Problem pSlot

When loading player vehicles you could use the variable you mentioned to save the car id. I assume that you are loading only 4 cars for a player's name, so inside the loop you could just add
PHP Code:
pCars[playerid][i] = vehicleid
Declaring the variable:
PHP Code:
new pCarSlot[MAX_PLAYERS][4]; 
And when a player wants to buy a vehicle or whatever you could just check if any of the 4 slots are available:
PHP Code:
function CheckFreeSlots(playerid)
{
    new 
count = -1;
    for(new 
i4i++)
    {
        if(
pCarSlot[playerid][i] == INVALID_VEHICLE_IDcount ++;
    }
    return 
count;

Under OnPlayerConnect and Disconnect set pCarSlot to invalid vehicle id.
Usage of the function:
PHP Code:
new count CheckFreeSlots(playerid);
if(
count != -1)
{
    
//your code

Of course there are other methods, you have some above.
A simpliest method, checking in the database how many cars that player has.
PHP Code:
function CountPlayerVehicles(playerid)
{
    new 
countquery[128];
    
mysql_format(SQLquerysizeof(query), "SELECT COUNT(*) AS `total` FROM `vehicle` WHERE `owner` = '%e'"GetName(playerid)); //replace `vehicle` and `owner`with your database fields.
    
mysql_tquery(SQLquery"""");
    
cache_get_value_name_int(0"total"count);
    return 
count;

Usage:
PHP Code:
new count CountPlayerVehicles(playerid);
if(
count >= 4SendClientMessage(playerid, -1"Maximum slots reached!");
else 
//your code. 
SharpenBlade is offline   Reply With Quote
Old 13/06/2020, 10:18 AM   #7
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 494
Reputation: 5
Default Re: Problem pSlot

Well. I understood a little. How will buying slots look like, i.e. enlarging the slot after purchase.

Code: https://pastebin.com/jj07VDK4
KamilPolska is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[SOLVED] 3 problem's! (1 problem still unsolved, but stopped solving.) Mechscape Help Archive 9 24/12/2009 08:47 PM


All times are GMT. The time now is 10:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.