SA-MP Forums Archive
Scripting help (Vehicle system) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Scripting help (Vehicle system) (/showthread.php?tid=545628)



Scripting help (Vehicle system) **Not solved** - dazman14 - 09.11.2014

I've been scripting for years but i'm clueless as to why this script doesn't work proparly. Propably a simple mistake somewhere... So my problem is that GetVehicleSQLID isn't working i did a debug using command /carsql that i made. I've taken the relevant code out of my script to get some help on this.

here is the debug command (I use this in a car) :
and it returned SERVER: Command does not exist

Код:
command(carsql, playerid, params[])
{
	new string[100];
    new vehid = GetPlayerVehicleID(playerid);
	
	format(string, sizeof(string), "The sql id of this vehicle is: %d. ", GetVehicleSQLID(vehid));
	SendClientMessage(playerid, COLOR_WHITE, string);
	
	
	
	return 1;
}
enum:

Код:
enum VehicleStats{
id,
perm,
model,
Float:vx,
Float:vy,
Float:vz,
Float:va,
c1,
c2,
plate[8],
lock,
GameID
};
new Vehicle[MAX_VEHICLE][VehicleStats];
Vehilce spawning:

Код:
 
stock LoadDynamicVehicles()
{
	new Str[128], VehicleID, i = 0;
	
    mysql_query("SELECT * FROM `vehicles`");
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>iiiffffiis[10]", VehicleID, Vehicle[i][perm], Vehicle[i][model], Vehicle[i][vx], Vehicle[i][vy], Vehicle[i][vz], Vehicle[i][va], Vehicle[i][c1], Vehicle[i][c2], Vehicle[i][plate]);

            
			
			SetVehicleNumberPlate(Vehicle[i][GameID] = CreateVehicle(Vehicle[i][model], Vehicle[i][vx], Vehicle[i][vy], Vehicle[i][vz], Vehicle[i][va], Vehicle[i][c1], Vehicle[i][c2], -1), Vehicle[i][plate]);
            SetVehicleToRespawn(i);
			Vehicle[i][id] = VehicleID;
            i++;
			
		}
    }
    mysql_free_result();
    printf("--- %i vehicle(s) loaded from the MySQL Database. ---", i);
	return 1;
}
GetVehicleSQLID(vehid):

Код:
GetVehicleSQLID(vehid)
{
   new result;
   for (new i = 0; i < MAX_VEHICLES; i++)
   {
	  if(vehid == Vehicle[i][GameID])
	  {
		  result = i;
	  }
   }
   return result;
}
I appreciate all the help you guys give. I never really ask for it as i seem to solve problems rather well but this one has got me.

My main questionm is: What is causing GetVehicleSQLID to not work?


Darren (Dazman14)


Re: Scripting help (Vehicle system) - Dziugsas - 09.11.2014

Its not the function that doesnt work its command , have you tried CMD:carsql(playerid,params[])...?


Re: Scripting help (Vehicle system) - dazman14 - 09.11.2014

Quote:
Originally Posted by Dziugsas
Посмотреть сообщение
Its not the function that doesnt work its command , have you tried CMD:carsql(playerid,params[])...?
There is no difference to my command setup than the one above. I already have working commands. The script has a problem getting the cars sql ID. Even though the function as you said looks fine.


Re: Scripting help (Vehicle system) - Dziugsas - 09.11.2014

if your cmd is working why do you get SERVER: Command does not exist?


Re: Scripting help (Vehicle system) - dazman14 - 09.11.2014

Quote:
Originally Posted by Dziugsas
Посмотреть сообщение
if your cmd is working why do you get SERVER: Command does not exist?
I have working commands around it. Such as /createcar. The script just hits problems when getting the vehicle sql id from the gameid. Even though its set up correctly. There must be a problem somwhere in my code to cause gathering the ID to fail causing the command to return Command Does not exist.


[GameID] is linked to that particular car on spawning from database. So i don't understand when it finds the game id by going through the For loop in GetVehicleSQLID it should return the SQL id as the result but instead doesn't function.