I'm a new scripter and I got one question
#1

Well, hello all. I'm learning pawno from zero, and I've started to script my own gamemode.
I know a little bit MYSQL so I've downloaded one of the plugins and made a well-done account system.
Nowadays, I'm working on my own vehicle system, and it all worked great, untill I tried to do the next thing;
I'm trying to set one of the field in my database to a non-static string, whitch I can't do. If I make the string static and types something into it, it works fine. An example of my code would be:
The funcion whitch I use in order to insert a new field into my MYSQL database table:
pawn Код:
command(createvehicle, playerid, params[])
{
    #pragma unused params
    new color1, color2, Float:PositionX, Float:PositionY, Float:PositionZ, Float:AngleZ;
    /*if(pStats[playerid][pAdminLevel] < 3)
        return SendClientMessage(playerid, COLOR_GREY, ADMIN_CMD_ERROR);*/

    if(!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, COLOR_BRIGHTRED, "You are not in a vehicle, nothing was saved!");

    new vehicleid = GetPlayerVehicleID(playerid);
    new ModelID = GetVehicleModel(vehicleid);
    GetVehiclePos(vehicleid, PositionX, PositionY, PositionZ);
    GetVehicleZAngle(vehicleid, AngleZ);
    new plate[10];
    plate = CreateVehiclePlate();
    print(plate);
    //plate = "123456789";
    color1 = color2 = 0;

    format(Query, sizeof(Query), "INSERT INTO `vehicles` (Model, PosX, PosY, PosZ, Angle, Color1, Color2, Plate) VALUES(%d, %f, %f, %f, %f, %d, %d, %s)", ModelID, PositionX, PositionY, PositionZ, AngleZ, color1, color2, plate);
    mysql_query(Query);
    SendClientMessage(playerid, COLOR_BRIGHTRED, "You have added a new vehicle to the Database");
    return 1;
}
This code would work for me if I would uncomment the "plate = "123456789";" line, and would comment the "plate = CreateVehiclePlate();" line. I just don't know why it doesn't work when I use my function in order to recieve my plate, but even after I print it with "print()" function, it works great. Here is my CreateVehiclePlate() function:
pawn Код:
CreateVehiclePlate()
{
    new string[10];
    new vehicles;
    new plate[10];
    //format(string, sizeof(string), "SELECT * FROM vehicles WHERE Plate = '%s'", String);
    mysql_query("SELECT * FROM vehicles");
    //vehicles = ; // 000000
    vehicles = mysql_num_rows(mysql_store_result());
    format(Query, sizeof(Query), "Vehicles in Database: %d", vehicles);


    if(vehicles > 99999)
    {
        format(string, sizeof(string), "SA-%d", vehicles);
    }
    else if(vehicles > 9999)
    {
        format(string, sizeof(string), "SA-0%d", vehicles);
    }
    else if(vehicles > 999)
    {
        format(string, sizeof(string), "SA-00%d", vehicles);
    }
    else if(vehicles > 99)
    {
        format(string, sizeof(string), "SA-000%d", vehicles);
    }
    else if(vehicles > 9)
    {
        format(string, sizeof(string), "SA-0000%d", vehicles);
    }
    else if(vehicles > 0)
    {
        format(string, sizeof(string), "SA-00000%d", vehicles);
    }
    else
    {
        format(string, sizeof(string), "SA-000000", vehicles);
    }

    plate = string;
    return plate;
}

In my MYSQL database the field properties:
Name: Plate | Type: varchar | Length: 12


Any ideas? Thank you.
Reply
#2

What you mean doesn't work? What happens?
Reply
#3

Just doesn't do anything.. its like I've never used the INSERT line. As soon as I change it to static string, it works fine.
Reply
#4

EDIT:Ifail
Reply
#5

Its not the problem here.. I've made another "/spawncar" cmd whitch spawns the car only, with the needed registration plate - and it works fine. Only when I call the function in my MYSQL usement Its like doesn't apply the INSERT line.
Reply
#6

You know there is a magic function in MySql plugin R5 called
pawn Код:
mysql_debug(1);
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
You know there is a magic function in MySql plugin R5 called
pawn Код:
mysql_debug(1);
From now on I know that, thanks for the suggestion - problem solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)