SA-MP Forums Archive
Unlimited number of houses,vehicles,etc. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Unlimited number of houses,vehicles,etc. (/showthread.php?tid=657435)



Unlimited number of houses,vehicles,etc. - GospodinX - 07.08.2018

Hi guys

I need idea how to make unlimited number of cars,vehicles etc(For player).Now I have "slots",for example
Quote:

Vehicle1
Vehicle2
Vehicle3
Vehicle4

,for houses
Quote:

House1
House2
..

Now I don't know what is best way to make unlimited system.For example now when i want to "print"(on stats etc) player vehicles I do just this:
Код:
new id = PlayerInfo[playerid][Vehicle1];
VehicleInfo[id][Model]
I don't know how to do it if i make "unlimited system"(if i don't store ID of vehicles in player variable..)

I need every time to do for loop and check which vehicles are in player property(with strcmp) is there any better possibility

I use MySQL!

Thanks


Re: Unlimited number of houses,vehicles,etc. - IdonTmiss - 07.08.2018

Well making an "unlimited" number of something isn't technically possible in SA:MP, there's a trick to make "unlimited" vehicles and it goes something like this

OnPlayerConnect
PHP код:
//So here u check if player has a vehicle and spawn it, something like this?
if(PlayerInfo[pCar1] == Whatever)
{
CreateVehicle...

OnPlayerDisconnect
PHP код:
// So here u again check if player has a vehicle
if(PlayerInfo[pCar1] == Whatever)
{
DestroyVehicle...

EDIT: If u wanted players to have unlimited number of vehicles that's an another story ( Like they can purchase 500 cars or something like that )


Re: Unlimited number of houses,vehicles,etc. - Kraeror - 07.08.2018

Here you are an example for the code, you can replace what is in your script I mean the variable names or something like this(There are more details in the code):
PHP код:
#include <a_samp>
#define MAX_VEHICLES 1000 //The limit is 100 now (you can not create something unlimited you can just edit the limit to 100000 or something like that)
public OnPlayerConnect(playerid)
{
    for(new 
0<= MAX_VEHICLESi++) //It is the loop, so now your ID starts from 0 to your MAX_VEHICLES number which is 1000 for now
    
{
        if(
strcmp(your parameters))
        {
            
//Before creating the vehicle you have to load all the stuff from your database HERE<<<<
            
CreateVehicle(VehicleInfo[i][Model], VehicleInfo[i][X], VehicleInfo[i][Y], VehicleInfo[i][Z], VehicleInfo[i][Rotation], VehicleInfo[i][Color1], VehicleInfo[i][Color2], VehicleInfo[i][rDelay]);
        }
    }




Re: Unlimited number of houses,vehicles,etc. - BornHuman - 07.08.2018

Depending upon how many variables you have for your cars, I would suggest creating a different enumerator. When I wrote my roleplay script, this is what I did.

Код:
enum PlayerVehicleData
{
    CarDatabaseID[MAX_PLAYER_VEHICLES],
    CarID[MAX_PLAYER_VEHICLES],
    CarModel[MAX_PLAYER_VEHICLES],
    Float:CarX[MAX_PLAYER_VEHICLES],
    Float:CarY[MAX_PLAYER_VEHICLES],
    Float:CarZ[MAX_PLAYER_VEHICLES],
    Float:CarA[MAX_PLAYER_VEHICLES],
    CarColour[MAX_PLAYER_VEHICLES],
    CarColour2[MAX_PLAYER_VEHICLES],
    CarVW[MAX_PLAYER_VEHICLES],
    CarInt[MAX_PLAYER_VEHICLES],
    CarFuel[MAX_PLAYER_VEHICLES],
    CarMod0[MAX_PLAYER_VEHICLES],
    CarMod1[MAX_PLAYER_VEHICLES],
    CarMod2[MAX_PLAYER_VEHICLES],
    CarMod3[MAX_PLAYER_VEHICLES],
    CarMod4[MAX_PLAYER_VEHICLES],
    CarMod5[MAX_PLAYER_VEHICLES],
    CarMod6[MAX_PLAYER_VEHICLES],
    CarMod7[MAX_PLAYER_VEHICLES],
    CarMod8[MAX_PLAYER_VEHICLES],
    CarMod9[MAX_PLAYER_VEHICLES],
    CarMod10[MAX_PLAYER_VEHICLES],
    CarMod11[MAX_PLAYER_VEHICLES],
    CarMod12[MAX_PLAYER_VEHICLES],
    CarMod13[MAX_PLAYER_VEHICLES],
    CarPaintJob[MAX_PLAYER_VEHICLES],
    CarPlate1[8],
    CarPlate2[8],
    CarPlate3[8],
    CarPlate4[8],
    CarPlate5[8]
}
And you can #define MAX_PLAYER_VEHICLES to whatever you want, making it "unlimited" even though it will actually have some sort of limit. Just be careful with the IDs, because having an unlimited amount of vehicles means that if you mismatch the ID's you could be in trouble.


Re: Unlimited number of houses,vehicles,etc. - GospodinX - 07.08.2018

Quote:

EDIT: If u wanted players to have unlimited number of vehicles that's an another story ( Like they can purchase 500 cars or something like that )

Yes I mean on it.I don't know what is best way for it.I just know for Kraeror example(for loop + strcmp)


Re: Unlimited number of houses,vehicles,etc. - GospodinX - 08.08.2018

I will try with bump last time.Is there any better way to do it?I know for loop + strcmp but i'm not sure that it's good.I will need to use loop+strcmp many times.When player want to see stats i will have many loops:

-Loop for houses,for flats,cottages,vehicles etc.It's many loops to check what player have in property.

When player enter in some property,want to sell property etc.