Speedcameras is not loading (R40)
#1

It's not loading anything from the LoadCams.

Код:
    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;
}
Reply
#2

bump
Reply
#3

First of all:
PHP код:
DID cache_get_value_name_int(i"Cam_ID"gCameras[DID][Cam_ID]); 
Taken from the wiki:
Quote:

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.

Using the return-value will make all your speedcams use index 1 of the array, overwriting every other speedcam already loaded.

Second:
While loading the data, you're already storing the data in the proper place (aside from the wrong value of DID because of using the return-value of "cache_get_value_name_int").
Then you're using CreateSpeedCamera to overwrite the same values for the same camera.

Third:
PHP код:
cache_get_value_name_int(i"Cam_ID"gCameras[DID][Cam_ID]); 
Using this, you're storing the cameraID as you read it.
Inside CreateSpeedCamera, you're using:
PHP код:
gCameras[CamID][Cam_ID] = CamID+1
That's just confusing.

While reading, it may be speedcam with ID 5.
First line stores "5" (reading directly from database), while the CreateSpeedCamera function stores "6" (CamID + 1).

Fourth:
You don't actually need to store the ID because you can use the array's index as the ID of the camera.
Just don't set your Cam_ID column to auto_increment (so your code can determine the ID of the camera instead of MySQL itself), but you already have the correct setting if I look at your query.

Fifth:
You start using index 0 of your gCameras array, but you assign it ID 1 (i+1).
That's confusing as well.

Just use your gCameras index as the ID of the camera.
You can simply remove the Cam_ID value from your enum (and of course, remove all code that related to that variable).
Reply
#4

And this:
ORDER BY CamID ASC

You don't need to order anything hence it's an auto_inc value, if it isn't you're doing it wrong.
Reply
#5

idk what is it?


Код:
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;
}
it should be like this?
https://sampforum.blast.hk/showthread.php?tid=629410
Reply
#6

PHP код:
cache_get_value_name_float(i"Cam_ID"DID); 
You still need this to load the ID from the database.
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 код:
for(new i=1MAX_CAMERASi++) 
Start assigning ID's starting from 1 instead of 0.
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.
Reply
#7

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
PHP код:
cache_get_value_name_float(i"Cam_ID"DID); 
You still need this to load the ID from the database.
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 код:
for(new i=1MAX_CAMERASi++) 
Start assigning ID's starting from 1 instead of 0.
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.
ok but tho i have 1 error:

Код:
            cache_get_value_name_float(i, "Cam_ID", DID);
Код:
warning 213: tag mismatch
Reply
#8

cache_get_value_name_float(i, "Cam_ID", DID);
Reply
#9

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
cache_get_value_name_float(i, "Cam_ID", DID);
Still the same error




Код:
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;
}
Reply
#10

bump

still won't load it like it's not calling the funtion
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)