21.01.2011, 17:03
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:
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:
In my MYSQL database the field properties:
Name: Plate | Type: varchar | Length: 12
Any ideas? Thank you.
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;
}
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.