25.10.2017, 18:25
hello everyone i am trying to make a vehicle ownership system with sql this is what i have done so far
script creates the table but refuses to save data it should save data when i use /aveh command but its not working
Код:
#define SCRIPT_CARS 100 new LoadedVehicles = 0; new DB: VehicleDB; enum vInfo { vOwner[MAX_PLAYER_NAME], vOwnerID, vForSale, vModel, vCol1, vCol2, vPrice, Float:vPosX, Float:vPosY, Float:vPosZ, Float:vPosA, } new VehicleInfo[SCRIPT_CARS][vInfo]; public OnFilterScriptInit() { print("\n--------------------------------------"); print(" Blank Filterscript by your name here"); print("--------------------------------------\n"); VehicleDB = db_open("vehicles.db"); if ((VehicleDB = db_open("vehicles.db")) == DB: 0) { print("Failed to open a connection to \"server.db\""); } else { db_query(VehicleDB, "PRAGMA synchronous = OFF"); db_query(VehicleDB, "CREATE TABLE IF NOT EXISTS vehicles (owner VARCHAR(24) COLLATE NOCASE, ownerid INTEGER PRIMARY KEY AUTOINCREMENT, forsale INTEGER DEFAULT 1 NOT NULL, model INTEGER DEFAULT 0 NOT NULL, color1 INTEGER DEFAULT 0 NOT NULL, color2 INTEGER DEFAULT 0 NOT NULL, price INTEGER DEFAULT 0 NOT NULL, posx FLOAT, posy FLOAT, posz FLOAT, posa FLOAT)"); } LoadVehicles(); return 1; } public OnFilterScriptExit() { db_close(VehicleDB); return 1; } CMD:aveh(playerid, params[]) { new model,color,color2,Float:cPos[4], price; if(sscanf(params, "iiii", model, price, color,color2)) return SendClientMessage(playerid, -1, "/aveh [model] [price] [color] [color]"); if(model < 400 || model > 611) return SendClientMessage(playerid,-1, "vehicle IDs between 400 - 611!"); if(color> 255 || color< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255"); if(color2> 255 || color2< 0) return SendClientMessage(playerid, 0xFFFFFF, "Car color ID's: 0-255"); GetPlayerPos(playerid, cPos[0], cPos[1], cPos[2]); GetPlayerFacingAngle(playerid, cPos[3]); CreateVehicle(model, cPos[0], cPos[1]-3, cPos[2], cPos[3], color, color2, -1); LoadedVehicles ++; new Query[208]; format(Query, sizeof Query, "INSERT INTO vehicles (owner, ownerid, price, forsale, model, x, y, z, a) VALUES ('%s', '%d', '%d', '%d', '%d','%f', '%f', '%f', '%f')", "NONE", -1, price, 1, model, cPos[0], cPos[1], cPos[2], cPos[3]); db_query(VehicleDB, Query); return 1; } stock LoadVehicles() { new DBResult: Result, id, buf[255]; format(buf, sizeof buf, "SELECT * FROM vehicles"); Result = db_query(VehicleDB, buf); if (db_num_rows(Result)) { id = LoadedVehicles; sscanf(buf, "p<|>e<s[25]iiiiiiiifffff>", VehicleInfo[id][vOwner], VehicleInfo[id][vOwnerID], VehicleInfo[id][vForSale], VehicleInfo[id][vModel], VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], VehicleInfo[id][vPrice], VehicleInfo[id][vPosX], VehicleInfo[id][vPosY], VehicleInfo[id][vPosZ], VehicleInfo[id][vPosA]); CreateVehicle(VehicleInfo[id][vModel],VehicleInfo[id][vPosX],VehicleInfo[id][vPosY],VehicleInfo[id][vPosZ],VehicleInfo[id][vPosA],VehicleInfo[id][vCol1], VehicleInfo[id][vCol2], 60*10000); LoadedVehicles = LoadedVehicles+1; } db_free_result(Result); }