mysql_tquery(mysql, "SELECT * FROM `cams` ORDER BY CamID ASC", "LoadCams");
enum SpeedTraps { Cam_ID, Float:CamX, Float:CamY, Float:CamZ, Float:CamAngle, CamSpeed, CamObj1, CamObj2 } new gCameras[MAX_CAMERAS][SpeedTraps]; CreateSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed) { gCameras[CamID][Cam_ID] = CamID+1; gCameras[CamID][CamX] = x; gCameras[CamID][CamY] = y; gCameras[CamID][CamZ] = z; gCameras[CamID][CamAngle] = rot; gCameras[CamID][CamSpeed] = MaxSpeed; gCameras[CamID][CamObj1] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot); //gCameras[CamID][CamObj2] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot + 180.0); } //Speed cam forward LoadCams(); public LoadCams() { new rows; printf("LoadCams was called"); cache_get_row_count(rows); { new i, DID; while(i < rows) { DID = cache_get_value_name_int(i, "Cam_ID", gCameras[DID][Cam_ID]); cache_get_value_name_float(i, "CamX", gCameras[DID][CamX]); cache_get_value_name_float(i, "CamY", gCameras[DID][CamY]); cache_get_value_name_float(i, "CamZ", gCameras[DID][CamZ]); cache_get_value_name_float(i, "CamAngle", gCameras[DID][CamAngle]); cache_get_value_name_int(i, "CamSpeed", gCameras[DID][CamSpeed]); CreateSpeedCamera(i, gCameras[DID][CamX], gCameras[DID][CamY], gCameras[DID][CamZ], gCameras[DID][CamAngle], gCameras[DID][CamSpeed]); i++; } } printf("Loaded %d cams", rows); return 1; } CMD:addcam(playerid, params[]) { new MaxSpeed; if(sscanf(params, "i", MaxSpeed)) return SendClientMessage(playerid, -1, "Usage: /addcam [Max Speed]"); new Float:x, Float:y, Float:z, Float:Angle, string[128]; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, Angle); SetPlayerPos(playerid, x, y + 1.0, z + 1.0); for(new i=0; i < MAX_CAMERAS; i++) { if(!gCameras[i][Cam_ID]) { CreateSpeedCamera(i, x, y, z-1.0, Angle, MaxSpeed); format(string, sizeof(string),"INSERT INTO `cams` VALUES (%d, %.4f, %.4f, %.4f, %.4f, %d);",i+1, x, y, z, Angle, MaxSpeed); mysql_tquery(mysql, string); format(string, sizeof(string), "You created a speed camera with ID: %i.", i+1); SendClientMessage(playerid, -1, string); return 1; } } format(string, sizeof(string), "You cannot create more than %i speedcameras.", MAX_CAMERAS); SendClientMessage(playerid, -1, string); return 1; }
DID = cache_get_value_name_int(i, "Cam_ID", gCameras[DID][Cam_ID]);
cache_get_value_name_int Description: Retrieves a value from the result set as a decimal number. Parameters: (row_idx, const column_name[], &destination) row_idx The row index (starts at '0'). const column_name[] The column name. &destination The variable to store the number into. Return Values: 1 on success, 0 on failure. |
cache_get_value_name_int(i, "Cam_ID", gCameras[DID][Cam_ID]);
gCameras[CamID][Cam_ID] = CamID+1;
mysql_tquery(mysql, "SELECT * FROM `cams`", "LoadCams");
enum SpeedTraps { Float:CamX, Float:CamY, Float:CamZ, Float:CamAngle, CamSpeed, CamObj1, CamObj2 } new gCameras[MAX_CAMERAS][SpeedTraps]; CreateSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed) { CamID++; gCameras[CamID][CamX] = x; gCameras[CamID][CamY] = y; gCameras[CamID][CamZ] = z; gCameras[CamID][CamAngle] = rot; gCameras[CamID][CamSpeed] = MaxSpeed; gCameras[CamID][CamObj1] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot); //gCameras[CamID][CamObj2] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot + 180.0); } //Speed cam forward LoadCams(CamID); public LoadCams(CamID) { new rows; printf("LoadCams was called"); cache_get_row_count(rows); { new i, DID; while(i < rows) { cache_get_value_name_float(i, "CamX", gCameras[DID][CamX]); cache_get_value_name_float(i, "CamY", gCameras[DID][CamY]); cache_get_value_name_float(i, "CamZ", gCameras[DID][CamZ]); cache_get_value_name_float(i, "CamAngle", gCameras[DID][CamAngle]); cache_get_value_name_int(i, "CamSpeed", gCameras[DID][CamSpeed]); CreateSpeedCamera(i, gCameras[DID][CamX], gCameras[DID][CamY], gCameras[DID][CamZ], gCameras[DID][CamAngle], gCameras[DID][CamSpeed]); i++; } } printf("Loaded %d cams", rows); return 1; } CMD:addcam(playerid, params[]) { new MaxSpeed; if(sscanf(params, "i", MaxSpeed)) return SendClientMessage(playerid, -1, "Usage: /addcam [Max Speed]"); new Float:x, Float:y, Float:z, Float:Angle, string[128]; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, Angle); SetPlayerPos(playerid, x, y + 1.0, z + 1.0); for(new i=0; i < MAX_CAMERAS; i++) { CreateSpeedCamera(i, x, y, z-1.0, Angle, MaxSpeed); format(string, sizeof(string),"INSERT INTO `cams` VALUES (%d, %.4f, %.4f, %.4f, %.4f, %d);",i+1, x, y, z, Angle, MaxSpeed); mysql_tquery(mysql, string); format(string, sizeof(string), "You created a speed camera with ID: %i.", i+1); SendClientMessage(playerid, -1, string); return 1; } format(string, sizeof(string), "You cannot create more than %i speedcameras.", MAX_CAMERAS); SendClientMessage(playerid, -1, string); return 1; }
cache_get_value_name_float(i, "Cam_ID", DID);
for(new i=1; i < MAX_CAMERAS; i++)
PHP код:
Without it, DID will always have the value 0 and you will still store all data at index 0 of the array, even if you have 1000 cameras. Put in as first line inside the while loop, before loading the other values. That way, you'll use DID as index for the array. And if you wanna keep to use the function CreateSpeedCamera, load all values into temporary variables like x, y, z, a and pass these to the function. No need to store them in the proper place first, then pass those same values towards the function, which will simply overwrite them with the same values again. Inside the addcam command: PHP код:
And remove all the "i+1" stuff, replace it by "i". Assigning an ID first and then adding 1 to it is confusing. Inside the CreateSpeedCamera function, remove the "CamID++;" line. You give the ID as parameter already, so why not use it directly? When you would be a teacher and you say to your class to open their book at page 47, do you expect your class to open the book at page 48? No, because you stated page 47 explicitly as parameter for opening the book. |
cache_get_value_name_float(i, "Cam_ID", DID);
warning 213: tag mismatch
enum SpeedTraps { Float:CamX, Float:CamY, Float:CamZ, Float:CamAngle, CamSpeed, CamObj1, CamObj2 } new gCameras[MAX_CAMERAS][SpeedTraps]; CreateSpeedCamera(CamID, Float:x, Float:y, Float:z, Float:rot, MaxSpeed) { gCameras[CamID][CamX] = x; gCameras[CamID][CamY] = y; gCameras[CamID][CamZ] = z; gCameras[CamID][CamAngle] = rot; gCameras[CamID][CamSpeed] = MaxSpeed; gCameras[CamID][CamObj1] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot); //gCameras[CamID][CamObj2] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, rot + 180.0); } //Speed cam forward LoadCams(); public LoadCams() { new rows; printf("LoadCams was called"); cache_get_row_count(rows); { new i, DID; while(i < rows) { cache_get_value_name_float(i, "CamX", gCameras[DID][CamX]); cache_get_value_name_float(i, "CamY", gCameras[DID][CamY]); cache_get_value_name_float(i, "CamZ", gCameras[DID][CamZ]); cache_get_value_name_float(i, "CamAngle", gCameras[DID][CamAngle]); cache_get_value_name_int(i, "CamSpeed", gCameras[DID][CamSpeed]); CreateSpeedCamera(i, gCameras[DID][CamX], gCameras[DID][CamY], gCameras[DID][CamZ], gCameras[DID][CamAngle], gCameras[DID][CamSpeed]); i++; } } printf("Loaded %d cams", rows); return 1; } CMD:addcam(playerid, params[]) { new MaxSpeed; if(sscanf(params, "i", MaxSpeed)) return SendClientMessage(playerid, -1, "Usage: /addcam [Max Speed]"); new Float:x, Float:y, Float:z, Float:Angle, string[128]; GetPlayerPos(playerid, x, y, z); GetPlayerFacingAngle(playerid, Angle); SetPlayerPos(playerid, x, y + 1.0, z + 1.0); for(new i=1; i < MAX_CAMERAS; i++) { CreateSpeedCamera(i, x, y, z-1.0, Angle, MaxSpeed); format(string, sizeof(string),"INSERT INTO `cams` VALUES (%.4f, %.4f, %.4f, %.4f, %d);",i, x, y, z, Angle, MaxSpeed); mysql_tquery(mysql, string); format(string, sizeof(string), "You created a speed camera with ID: %i.", i); SendClientMessage(playerid, -1, string); return 1; } format(string, sizeof(string), "You cannot create more than %i speedcameras.", MAX_CAMERAS); SendClientMessage(playerid, -1, string); return 1; }