Vehicle wont spawn
#1

I'm using a simple script to create a vehicle but it wont spawn. This is the code and only the textdraw spawns..

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

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).
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
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).
I get the following error.

Код:
sscanf warning: Strings without a length are deprecated, please add a destination size.
Reply
#4

Oh, I saw that while typing but forgot to mention it. It needs the size after the "s" specifier -> "s[size_here]".

pawn Код:
if(sscanf(params,"is[128]",CarPrice, CarModel))
Even though 128 is still much. You could reduce it to 32 (both in sscanf and CarModel's size).
Reply
#5

I did it. Now it has no problem with errors but it's not spawning the car again here is a screen from the MySQL

http://prikachi.com/images/537/8108537j.png
Reply
#6

See the "Model" in the database. It sets the modelid to 2 but the valid model IDs are between 400 and 611. I assume you returned the index only (from the loop) instead of adding 400 to it.

If you cannot fix it, then post GetCarIDFromName function here.
Reply
#7

Thanks very much AGAIN !! I didn't know that the car id's start from 400. Here is the script if someone needs it

Код:
GetCarIDFromName(vehicle_name[])
{
        for(new i = 0; i < 211; i++)
        {
                if ( strfind(VehicleNames[i], vehicle_name, true) != -1 )
                        return i + 400;
        }
        return -1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)