CMD:spawncar(playerid,params[]) { if(Player[playerid][AdminLevel] <= 2) return SendClientMessage(playerid,-1,"You aren't an admin!");//Check if the player is currently rcon logged in. new CarPrice,id = CarsCount,CarModel[128], tmp[128];//Creating the house price for the selected value in the command, and the last house id created. if(sscanf(params,"is",CarPrice, CarModel)) return SendClientMessage(playerid,-1,"USAGE: /spawncar <price> <model>");//Checking if the player uses the correct syntax. The parameter "i" in sscanf means integer, also could be used as "d". new Float:x,Float:y,Float:z, Float: Angle;//Creating the floats, to store the player's position. GetPlayerPos(playerid,x,y,z);//Getting the player's position and storing it GetPlayerFacingAngle(playerid, Angle); Vehicle[id][VehicleID] = id;//Setting the house price to the selected one. Vehicle[id][Model] = CarModel;//Setting the house price to the selected one. Vehicle[id][PosX] = x;//Setting the house price to the selected one. Vehicle[id][PosY] = y;//Setting the house price to the selected one. Vehicle[id][PosZ] = z;//Setting the house price to the selected one. Vehicle[id][PosA] = Angle;//Setting the house price to the selected one. Vehicle[id][Color1] = 133;//Setting the house price to the selected one. Vehicle[id][Color2] = 133;//Setting the house price to the selected one. Vehicle[id][Respawn] = -1;//Setting the house price to the selected one. Vehicle[id][OwnerID] = 0;//Setting the house price to the selected one. Vehicle[id][Owned] = 0;//Setting the house price to the selected one. Vehicle[id][Freezed] = 1;//Setting the house price to the selected one. Vehicle[id][Price] = CarPrice;//Setting the house price to the selected one. new CarID = GetCarIDFromName(CarModel); if (CarID == -1) return SendClientMessage(playerid, -1, "Invalid car name"); Player[playerid][pSpawnVehicle] = CreateVehicle(CarID, x, y, z, Angle, Vehicle[id][Color1], Vehicle[id][Color2], -1); LinkVehicleToInterior(Player[playerid][pSpawnVehicle], GetPlayerInterior(playerid)); format(tmp, sizeof(tmp), "[CAR FOR SALE]\n{FFFFFF}Owner: Dealership \nPrice: $%d",Vehicle[id][Price]); Create3DTextLabel(tmp, COLOR_SYNTAX,x,y,z, 40.0,0,0); SendClientMessage(playerid,-1,"Car spawned"); CarsCount++; new query[256]; mysql_format(g_SQL, query, sizeof(query), "INSERT INTO `cars_system` (`Model`,`PosX`, `PosY`, `PosZ`, `PosA`, `Color1`, `Color2`,`Respawn`,`OwnerID`,`Owned`,`Freezed`,`Price`) VALUES ('%i',%f,%f,%f,%f,'%i','%i','%i','%i','%i','%i','%i')",CarID,Vehicle[id][PosX],Vehicle[id][PosY],Vehicle[id][PosZ],Vehicle[id][PosA],Vehicle[id][Color1],Vehicle[id][Color2],Vehicle[id][Respawn],Vehicle[id][OwnerID],Vehicle[id][Owned],Vehicle[id][Freezed],Vehicle[id][Price]); mysql_tquery(g_SQL, query, "NewHouseReload", ""); return 1; }
Debug the command and see where the code stops and print what values few variables hold.
By the way you don't get an unknown command, do you? That'd be because of run time error and there's currently an issue with "id" if exceeds the size of "Vehicle" array. Another two reason why it wouldn't spawn a vehicle are: - "CarID" is an invalid modelid and CreateVehicle returns INVALID_VEHICLE_ID. - Limit was reached (returns the same). |
sscanf warning: Strings without a length are deprecated, please add a destination size.
if(sscanf(params,"is[128]",CarPrice, CarModel))
GetCarIDFromName(vehicle_name[]) { for(new i = 0; i < 211; i++) { if ( strfind(VehicleNames[i], vehicle_name, true) != -1 ) return i + 400; } return -1; }