MySQL not saving data.(somewheres a mistake) -
GuitarMan - 01.12.2014
Hello.
So the thing is, after buying a car ingame, there is an option to change cars color. After changing the color, it saves the color data into database. Everythings fine with that. But after respraying my car into mechanics garage, it does not save anything and i can't find to seem whats wrong with the code. Also, in tuning, after Mechanic offers me to respray my veh, it shows the new color. If i decline it does not change it back to the old one. The problem is, after tuning if i restart my client, it does not save the tuned color although it should. Il just copy the whole code down here.
:Offering to respray my car.
PHP код:
case D_JOB+79:
{
if(!response) return TuningList(playerid);
new color[2], playerd = GetPVarInt(playerid, "PlayerTuning"), c = GetPVarInt(playerd, "CREVEH");
if(sscanf(inputtext, "p<,>ii",color[0], color[1])) return ShowPlayerDialog(playerid, D_JOB+79, 1, "Krasa", "Ievadiet krasu1 un krasu2 transporta caur komatu:", "Pienemt", "Atpakal");
if(color[0] < 0 || color[0] > 252)
{
ShowPlayerDialog(playerid, D_JOB+79, 1, "Color", "Write in the color1 and color 2 ids", "Accept", "Back");
return SendClientMessage(playerid, COLOR_GREY, "ID цвета от 0 до 252!");
}
if(color[1] < 0 || color[1] > 252)
{
ShowPlayerDialog(playerid, D_JOB+79, 1, "Color", "Write in the color1 and color2 ids", "accept", "Decline");
return SendClientMessage(playerid, COLOR_GREY, "ID krasai no 0 lidz 252!");
}
ChangeVehicleColor(c, color[0], color[1]);
SetPVarInt(playerid, "TuningColor1", color[0]);
SetPVarInt(playerid, "TuningColor2", color[1]);
SendMes(playerid, COLOR_BLUE, "You offered %s' to buy this color. Cost: %i eur", sendername(playerd), VEHICLE_COLOR);
SendMes(playerd, COLOR_BLUE, "Mechanic %s Offered you to buy this color. Cost: %i ls", sendername(playerid), VEHICLE_COLOR);
format(string, 200, "Mechanic %s Offered you to buy this color. Cost: %i ls\n\nDo you agree?", sendername(playerid), VEHICLE_COLOR);
ShowPlayerDialog(playerd, D_JOB+80, 0, "Color", string, "yes", "no");
}
The Respray script:
PHP код:
case D_JOB+80:
{
new playerd = GetPVarInt(playerid, "TuningPlayer");
if(response)
{
if(GetMoney(playerid) < VEHICLE_COLOR)
{
SendClientMessage(playerid, COLOR_GREY, "Not enough cash!");
SendMes(playerd, COLOR_BLUE, " %s Not enough cash", sendername(playerid));
ChangeVehicleColor(GetPVarInt(playerid, "CREVEH"), CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][0], CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][1]);
DeletePVar(playerd, "TuningColor1");
DeletePVar(playerd, "TuningColor2");
return 1;
}
GiveMoney(playerid, -VEHICLE_COLOR);
FracBank[11] += VEHICLE_COLOR;
SetOtherInt("mechbank", FracBank[11]);
SetPVarInt(playerd, "TuningMoney", GetPVarInt(playerd, "TuningMoney") + VEHICLE_COLOR);
CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][0] = GetPVarInt(playerd, "TuningColor1");
CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][1] = GetPVarInt(playerd, "TuningColor2");
format(CarInfo[GetPVarInt(playerid, "CREVEH")][cColors], 16, "%d, %d", CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][0], CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][1]);
SetCarsStr(CarInfo[GetPVarInt(playerid, "CREVEH")][id], "colors", CarInfo[GetPVarInt(playerid, "CREVEH")][cColors]);
SendMes(playerid, COLOR_BLUE, "You accepted the offer for : %i ls", VEHICLE_COLOR);
SendMes(playerd, COLOR_BLUE, "%sYou accepted the offer for %i ls", sendername(playerid), VEHICLE_COLOR);
}
else
{
SendMes(playerd, COLOR_BLUE, "%s declinde the offer", sendername(playerid));
ChangeVehicleColor(GetPVarInt(playerid, "CREVEH"), CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][0], CarInfo[GetPVarInt(playerid, "CREVEH")][cColor][1]);
}
DeletePVar(playerd, "TuningColor1");
DeletePVar(playerd, "TuningColor2");
}
This is the script, that saves it into the DB:
PHP код:
stock SetCarsStr(idx, stolb[], znach[])
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_CARS" SET %s = '%s' WHERE id = '%d' LIMIT 1", stolb, znach, idx);
return mysql_query(Query);
}
And this is where the " CREVEH" pVar is made:
PHP код:
stock LoadMyCar(playerid)
{
if(GetPlayerHouse(playerid) == 0) return 1;
if(GetPlayerCar(playerid) == 0) return 1;
new c = GetPVarInt(playerid, "PlayerCars");
new carid = CreateVehicle(CarInfo[c][cModel], CarInfo[c][cX], CarInfo[c][cY], CarInfo[c][cZ], CarInfo[c][cFa], CarInfo[c][cColor][0], CarInfo[c][cColor][1], 90000);
CarDoors(carid, CarInfo[c][cLock]);
Fuel[carid] = CarInfo[c][cFuel];
// SetVehicleHealth(carid, CarInfo[c][cHeal]);
Engine[carid] = false;
Lights[carid] = false;
switch(CarInfo[c][cLock])
{
case 0: IsLocked[carid] = false;
case 1: IsLocked[carid] = true;
}
SetPVarInt(playerid,"CREVEH",carid);
This is where the Table "cars" is defined.:
PHP код:
#define TABLE_CARS "cars"
And this is a screen shot of the "cars" db.
Re: MySQL not saving data.(somewheres a mistake) -
swiftyrus - 01.12.2014
em.. you tuned vehicle in TransFender/Loco Low Co/another_garage?
Re: MySQL not saving data.(somewheres a mistake) -
GuitarMan - 01.12.2014
Nop, in a custom made tuning place, but it actualy works just like one of those.
Re: MySQL not saving data.(somewheres a mistake) -
zT KiNgKoNg - 01.12.2014
Have you bothered to check the mysql_log.txt file that is generated if you've told it too.
Re: MySQL not saving data.(somewheres a mistake) -
GuitarMan - 01.12.2014
Sure.So after buying a car, it saves all the data without any probs.
PHP код:
stock BuyCar(playerid, idx)
{
if(GetPlayerHouse(playerid) == 1)
{
new Float:x, Float:y, Float:z, Float:fa,cost[MAX_PLAYERS],model[MAX_PLAYERS], h = GetPVarInt(playerid, "PlayerHouse");
switch(InShop[playerid])
{
case 1: cost[playerid]=GetInflationPrice(carsC[pPressed[playerid]][1]), model[playerid]=carsC[pPressed[playerid]][0], x=542.2341, y=-1291.1302, z=17.2422, fa=0.9819;
case 2: cost[playerid]=GetInflationPrice(carsB[pPressed[playerid]][1]), model[playerid]=carsB[pPressed[playerid]][0], x=-1957.9304, y=305.4497, z=35.4688, fa=179.9544;
case 3: cost[playerid]=GetInflationPrice(carsA[pPressed[playerid]][1]), model[playerid]=carsA[pPressed[playerid]][0], x=2200.7061, y=1392.0594, z=10.8203, fa=180.9670;
}
if(PlayerInfo[playerid][pBank] < cost[playerid]) return SendClientMessage(playerid, COLOR_GREY, YouDoNotHaveEnoughMoney);
InShop[playerid] = 0;
TogglePlayerControllable(playerid,true);
Exchequer+=cost[playerid];
format(query, 64, "UPDATE "TABLE_PICK" SET exchequer = %d", Exchequer);
PlayerInfo[playerid][pBank] -= cost[playerid];
TextDrawHideForPlayer(playerid,VehNazv[playerid]);
TextDrawHideForPlayer(playerid,VehCost[playerid]);
TextDrawHideForPlayer(playerid,PressA);
TextDrawHideForPlayer(playerid,PressD);
TextDrawHideForPlayer(playerid,PressH);
TextDrawHideForPlayer(playerid,PressC);
TextDrawHideForPlayer(playerid,PressB);
TextDrawHideForPlayer(playerid,VehBox);
t_SetPlayerPos(playerid,x,y,z);
SetPlayerFacingAngle(playerid,fa);
AC_BS_SetPlayerInterior(playerid,0);
AC_BS_SetPlayerVirtualWorld(playerid,0);
SetCameraBehindPlayer(playerid);
strmid(CarInfo[idx][cOwner],sendername(playerid),0,strlen(sendername(playerid)),MAX_PLAYER_NAME);
CarInfo[idx][cModel]=model[playerid];
CarInfo[idx][cCost]=cost[playerid];
CarInfo[idx][cLock]=1;
CarInfo[idx][cX] = HouseInfo[h][hCarx];
CarInfo[idx][cY] = HouseInfo[h][hCary];
CarInfo[idx][cZ] = HouseInfo[h][hCarz];
CarInfo[idx][cFa] = HouseInfo[h][hCarfa];
CarInfo[idx][cHeal] = 1000;
CarInfo[idx][cFuel] = 200;
CarInfo[idx][cColor][0]=colors[playerid][0];
CarInfo[idx][cColor][1]=colors[playerid][1];
CarInfo[idx][id] = idx;
SetPVarInt(playerid, "PlayerCars", CarInfo[idx][id]);
format(CarInfo[idx][cColors], 16, "%d, %d",CarInfo[idx][cColor][0],CarInfo[idx][cColor][1]);
strmid(CarInfo[idx][cOwner],sendername(playerid),0,strlen(sendername(playerid)),MAX_PLAYER_NAME);
SendMes(playerid, TEAM_BLUE_COLOR, "Jus nopirkat transportlidzekli: %s par %d Eiro",VehicleNameS[GetVehicleModel(veh[playerid])-400],CarInfo[idx][cCost]);
SendClientMessage(playerid,TEAM_BLUE_COLOR,"Jusu transportlidzeklis piegadats pie majas!");
DestroyVehicle(veh[playerid]);
format(query,sizeof(query),"UPDATE "TABLE_CARS" SET clock = %i, model = %i,cost = %i,colors = '%s', x = '%f', y='%f', z='%f', fa='%f', fuel = %i, heal = '%f' WHERE id = %i",CarInfo[idx][cLock],CarInfo[idx][cModel],
CarInfo[idx][cCost],CarInfo[idx][cColors],CarInfo[idx][cX], CarInfo[idx][cY], CarInfo[idx][cZ], CarInfo[idx][cFa], CarInfo[idx][cFuel], CarInfo[idx][cHeal], idx);
mysql_query(query);
Also, MySQL log shows:
PHP код:
00:53:34] >> mysql_query( Connection handle: 1 )
[00:53:34] CMySQLHandler::Query(UPDATE cars SET clock = 1, model = 458,cost = 480000,colors = '0, 0', x = '1848.738647', y='-1926.755737', z='13.207628', fa='89.873275', fuel = 200, heal = '1000.000000' WHERE id = 1) - Successfully executed.
BUT, if i change the color in tuning, MySQL log gives no info. It just doesnt record anything.
Re: MySQL not saving data.(somewheres a mistake) -
zT KiNgKoNg - 01.12.2014
Well giving us the buy 'command/function' isn't going to help us, help you now is it.
Also if you translated each of your 'Text' or so on into English such as "exchequer", it'll also help us figure out what is what, and what goes where. (Or post in the language sections at the bottom which corresponds with said language).
Re: MySQL not saving data.(somewheres a mistake) -
GuitarMan - 14.12.2014
The thing is its in Latvian language.
I will try to explain every thing.
This sets the info into MySQL database:
PHP код:
stock SetCarsStr(idx, stolb[], znach[])
{
new Query[128];
format(Query, sizeof(Query), "UPDATE "TABLE_CARS" SET %s = '%s' WHERE id = '%d' LIMIT 1", stolb, znach, idx);
return mysql_query(Query);
}
This is where the Pvar CREVEH is made:
PHP код:
stock LoadMyCar(playerid)
{
if(GetPlayerHouse(playerid) == 0) return 1;
if(GetPlayerCar(playerid) == 0) return 1;
new c = GetPVarInt(playerid, "PlayerCars");
new carid = CreateVehicle(CarInfo[c][cModel], CarInfo[c][cX], CarInfo[c][cY], CarInfo[c][cZ], CarInfo[c][cFa], CarInfo[c][cColor][0], CarInfo[c][cColor][1], 90000);
CarDoors(carid, CarInfo[c][cLock]);
Fuel[carid] = CarInfo[c][cFuel];
SetVehicleHealth(carid, CarInfo[c][cHeal]);
Engine[carid] = false;
Lights[carid] = false;
switch(CarInfo[c][cLock])
{
case 0: IsLocked[carid] = false;
case 1: IsLocked[carid] = true;
}
SetPVarInt(playerid,"CREVEH",carid);
if(CarInfo[c][cVehcoms][0]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][0]);
if(CarInfo[c][cVehcoms][1]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][1]);
if(CarInfo[c][cVehcoms][2]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][2]);
if(CarInfo[c][cVehcoms][3]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][3]);
if(CarInfo[c][cVehcoms][4]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][4]);
if(CarInfo[c][cVehcoms][5]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][5]);
if(CarInfo[c][cVehcoms][6]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][6]);
if(CarInfo[c][cVehcoms][7]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][7]);
if(CarInfo[c][cVehcoms][8]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][8]);
if(CarInfo[c][cVehcoms][9]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][9]);
if(CarInfo[c][cVehcoms][10]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][10]);
if(CarInfo[c][cVehcoms][11]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][11]);
if(CarInfo[c][cVehcoms][12]!=0) AddVehicleComponent(carid, CarInfo[c][cVehcoms][12]);
if(CarInfo[c][cVehcoms][13]!=0) AddVehicleComponent(carid,CarInfo[c][cVehcoms][13]);
if(CarInfo[c][cPaintjob]!=0) ChangeVehiclePaintjob(carid, CarInfo[c][cPaintjob]);
return true;
}
the ccolors:
PHP код:
enum cInfo
{
id,
cModel,
Float:cX,
Float:cY,
Float:cZ,
Float:cFa,
Float:cHeal,
cFuel,
cColors[16],
cColor[2],
cOwner[MAX_PLAYER_NAME],
cLock,
cCost,
cVehcom[127],
cVehcoms[14],
cPaintjob
};
Ugh i guess there are tons of things to copy.
Heres the whole gamemode. If theres anything i need to translate or if theres anything in the script that you dont know what its ment for, il explain it.
http://www.mediafire.com/view/sd6esp...d0/newmode.pwn