Seeking for help in a simple command
#2

Quote:
Originally Posted by AHN
Посмотреть сообщение
I have created a SQL database for vehicles, it's A-okay yet nothing wrong with it.
Vehicles in the database have a unique ID specified in the DB and when it's spawned it gets another ID from the server(vehicleid).
Here's an image from the DB, for the sake of deep explanation.

And as I said, in the server when it's spawned it gets another ID(vehicleid).

Now what I want is creating a simple command letting me know the vehicleid by writing on the ID on the database.
Here's what I've done:-

On Vehicle Spawn:
Код:
        CarData[carid][carVehicle] = CreateVehicle(CarData[carid][carModel], CarData[carid][carPos][0], CarData[carid][carPos][1], CarData[carid][carPos][2], CarData[carid][carPos][3], CarData[carid][carColor1], CarData[carid][carColor2], (CarData[carid][carOwner] != 0) ? (-1) : (1200000));
        // The spawning line. "CarData[carid][carVehicle]" outputs server's vehicleid.
        CarData[carid][carSrvID] = CarData[carid][carVehicle];
        // Storing server's vehicleid in another column on the database.
I've added a Column in the database to store server's vehicleid when a car spawns `carSrvID`
This works well and stores the ID but what I wrote in the command is the following:

Код:
CMD:getservervehid(playerid, params[])
{
	new enteredID;
	new string[64];
	new gottenid;
	
	if (sscanf(params, "d", enteredID)) return SendSyntaxMessage(playerid, "/getservervehid [ID]");
	
    format(string, sizeof(string), "SELECT * FROM `cars` WHERE `carID` = '%d'", enteredID); //Will select the car with the DB ID.
    mysql_tquery(g_iHandle, string);
    
	gottenid = cache_get_field_int(gottenid, "carSrvID");
	
	SendServerMessage(playerid, "IDgotten > %d.", gottenid);
	return 1;
}
It always outputs 0 on the message. What was specifically wrong on the code above? I still can't figure it out. Hoping that somebody will help me out.
Thanks.
Firstly...
How are you getting the field when you haven't even defined rows & fields..
Try
PHP код:
new rows,fieldsid_stringgottenid;
cache_get_data(rows,fields);
if(
rows >= 1) {
     
cache_get_row(00id_string);
      
gottenid strval(id_string);
} else {
     
printf("0 Rows Found");

The above code is based on a guess that your CARID = your primary key...
So Due to you're selecting a designated ID...
The ROW ID = 0
the Colum (IF ITS YOUR PRIMARY KEY) = 0
Then you store it..
then you assign strval when retrive
Reply


Messages In This Thread
Seeking for help in a simple command - by AHN - 22.06.2015, 20:50
Re: Seeking for help in a simple command - by Prokill911 - 22.06.2015, 21:00
Re: Seeking for help in a simple command - by AHN - 22.06.2015, 21:53
Re: Seeking for help in a simple command - by AHN - 23.06.2015, 22:14
Re: Seeking for help in a simple command - by AHN - 25.06.2015, 16:51

Forum Jump:


Users browsing this thread: 1 Guest(s)