MySQL Queries (Vehicle System).
#1

Okay, so I'm trying to make a vehicle system for my script, but I'm having a wee' bit of trouble ((Sorry if I have sloppy code!!))

pawn Код:
public CreateVeh(model, Float:X, Float:Y, Float:Z, Float:F, colour1, colour2, playerid)
{
    new vID, qString[512], conversion[4];
    vInfo[vID][vModel] = model;
    vInfo[vID][vPosX] = X;
    vInfo[vID][vPosY] = Y;
    vInfo[vID][vPosZ] = Z;
    vInfo[vID][vAngle] = F;
    vInfo[vID][vColour1] = colour1;
    vInfo[vID][vColour2] = colour2;

    mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[vID][vModel], vInfo[vID][vPosX], vInfo[vID][vPosY], vInfo[vID][vPosZ], vInfo[vID][vAngle], vInfo[vID][vColour1], vInfo[vID][vColour2]);
    for(new i = 1; i < sizeof(vInfo); i++)
    {
        valstr(conversion, i);
        if(maxHit == 1) {
            break;
        } else {
            mysql_format(mysql, qString, sizeof(qString),"SELECT * FROM `vehicles` WHERE `ID` = '%s'", conversion);
            mysql_tquery(mysql, qString, "CheckVehicle", "i", i);
        }
    }
    maxHit = 0;
    return 1;
}

public CheckVehicle(vehicleid, playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(cache_get_row_int(0, 1) == 0 && maxHit == 0)
    {
        printf("%i", vehicleid);
        return maxHit = 1;
    }
    return 1;
}



When the command /createveh [model] [colour1] [colour2] is typed, the script then initiates the CreateVeh function. This is then supposed to read the MySQL and get the lowest row which can have a new input.. Therefore, when the CreateVeh function runs, it checks the table `vehicles` for every ID within the maximum vehicle limit (temporarily 20), and for each ID, it checks whether the model number is NOT equal to 0, if it is, it's supposed to 'break' the CheckVeh loop and report the available ID (in this case, print it to the console to debug);

The problem is this;
A) I'm having to use a Public "maxHit" variable to check whether it has hit the lowest value (to prevent it reading EVERY value without a record in).

B) It's not setting the "maxHit" variable back to 0 everytime the CreateVeh is complete (Causing the player to have to type the /createveh command twice..)

C) I'm sure there would be another method to do something like this without the need for an additional variable / function?.. However, tquery seems to like sending the command to another function to carry out the rest of the command.



+REP for helpful comments!

Thanks.
Reply


Messages In This Thread
MySQL Queries (Vehicle System). - by Ryan_Undering - 21.02.2014, 12:25
Re: MySQL Queries (Vehicle System). - by Ryan_Undering - 21.02.2014, 15:36
Re: MySQL Queries (Vehicle System). - by Konstantinos - 21.02.2014, 15:53
Re: MySQL Queries (Vehicle System). - by Ryan_Undering - 21.02.2014, 16:16
Re: MySQL Queries (Vehicle System). - by Konstantinos - 21.02.2014, 16:32
Re: MySQL Queries (Vehicle System). - by Ryan_Undering - 21.02.2014, 16:48

Forum Jump:


Users browsing this thread: 1 Guest(s)