House car spawning[MYSQL]
#1

I need some help with my house car spawning. My brain is dieing because of it lol i cant seem to find out how to make it work. I got this under OnPlayerConnect:
pawn Код:
GetPlayerName(playerid, name, sizeof(name));
    new xPosVeh[60], yPosVeh[60], zPosVeh[60], ModelID[10], Rotation[20];
    format(str, sizeof(str), "SELECT `HouseID` FROM `Houses` WHERE `Owner`='%s'", name);
    mysql_query(str);
    mysql_get_field("HouseID", str);
    mysql_free_result();
    if(!sscanf(str, "d", integer))
    {
        if(integer != 0) //Player has a house...
        {
            format(str, sizeof(str), "SELECT * FROM `Vehicles` WHERE `HouseID`= '%d'", integer);
            mysql_query(str);
            if(mysql_num_rows() != 0)
            {
                while(mysql_num_rows()) //Loop xD
                {
                    AVehicle[playerid][vehicleID][numId] = Vehicle_Create(AVehicle[playerid][vehicleID][CarModel], AVehicle[playerid][vehicleID][CarPos_X], AVehicle[playerid][vehicleID][CarPos_Y], AVehicle[playerid][vehicleID][CarPos_Z],
                                                              AVehicle[playerid][vehicleID][CarPos_Rot], AVehicle[playerid][vehicleID][Color1], AVehicle[playerid][vehicleID][Color2], 300);

                }
            }
        }
    }
Ofcourse i get errors of:
Код:
AVehicleData[playerid][VehicleID][numId]
But i dont know how to fix it and make it load. Also how to save the vehicle ids to a variable. Hopefully someone can help me!
Reply
#2

Okay i edited it. Now i got this:
pawn Код:
GetPlayerName(playerid, name, sizeof(name));
    //new xPosVeh[60], yPosVeh[60], zPosVeh[60], ModelID[10], Rotation[20];
    format(str, sizeof(str), "SELECT `HouseID` FROM `Houses` WHERE `Owner`='%s'", name);
    mysql_query(str); //Send the query to the SQLite system integrated in SA:MP
    mysql_get_field("HouseID", str); //Gets the first field of the row returned (HouseID)
    mysql_free_result(); //No need to explain...
    if(!sscanf(str, "d", integer))
    {
        if(integer != 0) //Player has a house...
        {
            format(str, sizeof(str), "SELECT * FROM `Vehicles` WHERE `HouseID`= '%d'", integer);
            mysql_query(str);
            if(mysql_num_rows() != 0)
            {
                while(mysql_num_rows()) //Loop xD
                {
                    //Do what you want with the vehicle :P
                    //Use db_get_field or db_get_field_assoc
                    //Remember to store the vehicle IDs in a variable so you can delete them in OnPlayerDisconnect
                    mysql_get_field("Model", AVehicle[playerid][CarModel]);
                    mysql_get_field("X", AVehicle[playerid][CarPos_X]);
                    mysql_get_field("Y", AVehicle[playerid][CarPos_Y]);
                    mysql_get_field("Z", AVehicle[playerid][CarPos_Z]);
                    mysql_get_field("Rot", AVehicle[playerid][CarPos_Rot]);
                    mysql_get_field("Color1", AVehicle[playerid][Color1]);
                    mysql_get_field("Color2", AVehicle[playerid][Color2]);
                    AVehicle[playerid][numId] = Vehicle_Create(AVehicle[playerid][CarModel], AVehicle[playerid][CarPos_X], AVehicle[playerid][CarPos_Y], AVehicle[playerid][CarPos_Z],
                                                              AVehicle[playerid][CarPos_Rot], AVehicle[playerid][Color1], AVehicle[playerid][Color2], 300);
                }
            }
        }
    }
I think this should work. But now i got a problem how to save the id. So when he logs out the cars get removed. Does anyone know how?
Reply
#3

I had an idea to make it save the owner on the vehicle when he disconnects the server gm searches for all cars with that owner and delete them 1 problem. How do i make all the vehicles have their own Owner state?
Reply
#4

Bump. Help please.
Reply
#5

That code does not go under onplayerconnect go learn how to script lol...and mysql will be the hardest if ur trying to make it save owner and house id and or car id...sorry im on my phone, and stop bumping
Reply
#6

So you are the boss here? This board is called scripting help sir and you are not helping me with scripting... Atleast tell me where it does go then....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)