SA-MP Forums Archive
Vehicle Spawning - 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: Vehicle Spawning (/showthread.php?tid=602946)



Vehicle Spawning - Markus_Whiteus - 15.03.2016

I am new to pawn here I am trying to create a simple command to spawn a player vehicle. It is the stored vehicle however it is not spawning it i'm not sure where my issue is I feel it may be with my use of createvehicle hopefully someone can shed a light on my issue and any pointers would also be appreciated

Код:
enum pVehicleEnum {
	CarID,
	OwnerID,
	Slot,
	ModelID,
	Float: Position[4],
	Col[2],
};
new pVehicle[MAX_PLAYERS][pVehicleEnum];
Код:
stock SpawnPlayersCar(playerid, slot)
{
	new query[256], string[256];
	
	format(query, sizeof(query), "SELECT * FROM pVehicles WHERE owner = %d && slot = %d", Player[playerid][pID], slot) ;
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows() == 1)
	{
		new VehiclesSpawned;
		while(mysql_retrieve_row())
		{
			if(VehiclesSpawned < 1)
			{
				mysql_get_field("id", query);
				pVehicle[playerid][ID] = strval(query);
				
				mysql_get_field("model", query);
				pVehicle[playerid][ModelID] = strval(query);
				
				mysql_get_field("position", query);
				sscanf(query, "ffff", pVehicle[playerid][Position][0], pVehicle[playerid][Position][1], pVehicle[playerid][Position][2], pVehicle[playerid][Position][3]);
				
				mysql_get_field("col", query);
				sscanf(query, "dd", pVehicle[playerid][Col][0], pVehicle[playerid][Col][1]);
				new playerscar = CreateVehicle(pVehicle[playerid][ModelID], pVehicle[playerid][Position][0], pVehicle[playerid][Position][1], pVehicle[playerid][Position][2], pVehicle[playerid][Position][3], pVehicle[playerid][Col][0], pVehicle[playerid][Col][1], -1, 0);
				LinkVehicleToInterior(playerscar, GetPlayerInterior(playerid));
				format(string, sizeof(string), "Vehicle spawned from slot %d", slot);
				SendClientMessage(playerid, -1, string);
				VehiclesSpawned = 1;
				break;
			}
		}
		
	}
	else
		{
			
			format(string, sizeof(string), "No car found in slot %d", slot);
			SendClientMessage(playerid, -1, string);
	
		}
}
Код:
CMD:v(playerid,params[])
{
	new slot;
	if(sscanf(params, "i", slot))
		return SendClientMessage(playerid, -1, "Syntax: /v [slot]");
	SpawnPlayersCar(playerid, slot);
	return 1;

}
Many thanks in advance!
Markus


Re: Vehicle Spawning - saffierr - 15.03.2016

I mean... Do you really have to use your database for this simple cmd? This is like the most difficultest way, when you can create it with just one CMD...
Plus, you dont need an enum at all.


Re: Vehicle Spawning - Markus_Whiteus - 16.03.2016

Quote:
Originally Posted by saffierr
Посмотреть сообщение
I mean... Do you really have to use your database for this simple cmd? This is like the most difficultest way, when you can create it with just one CMD...
Plus, you dont need an enum at all.
Well the players personal vehicle details are to be stored within the database, so I assumed this is how it would be done but as I said I'm new to pawn would you be able to advise me at all on a better way to do this?

Thanks
Markus


Re: Vehicle Spawning - Beckett - 16.03.2016

First of all, the enum index should belong to the vehicle ID, not the player's.

Because you will be working with the vehicle, not the player.

Also try printing the vehicle's coordinates, see if it matches.


Re: Vehicle Spawning - Markus_Whiteus - 16.03.2016

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
First of all, the enum index should belong to the vehicle ID, not the player's.

Because you will be working with the vehicle, not the player.

Also try printing the vehicle's coordinates, see if it matches.
Thanks for the advice will give it a go once I am home.