SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/10/2019, 10:46 PM   #11
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

you have an example for how to create cars in array with enum?
__________________
zZzTGTzZz is offline   Reply With Quote
Old 17/10/2019, 11:39 PM   #12
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,441
Reputation: 1620
Default Re: Vehicle Spawning

Currently on phone and not near my PC, typing code is a pain in the ess.
Check my signature. It leads you to the PAWN guide, I'm quite certain you'll find what you need in there.
On top of that, you might want to read all of it.
Kwarde is online now   Reply With Quote
Old 18/10/2019, 12:40 AM   #13
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

i think i already did it, i'm not sure.

Code:
enum renting_Data
{
	Model,
	Float:rentX,
	Float:rentY,
	Float:rentZ,
	Float:rentAngle,
	rentColor1,
	rentColor2
};

#define MAX_RENTING_VEHICLES 		5
#define MAX_VEHICLES_FOR_RENT 		MAX_PLAYERS

static const VehicleRent[MAX_RENTING_VEHICLES][renting_Data] = 
{
	// etc etc...
};

new Vehicle_for_Rent[MAX_VEHICLES_FOR_RENT];

public OnGameModeInit()
{
	for(new i = 0; i < MAX_RENTING_VEHICLES; i ++)
	{
		Vehicle_for_Rent[i] = AddStaticVehicle(VehicleRent[i][Model], // etc etc...);
	}
	return 1;
}
__________________
zZzTGTzZz is offline   Reply With Quote
Old 19/10/2019, 02:16 AM   #14
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

bump, it doesn't work.
__________________
zZzTGTzZz is offline   Reply With Quote
Old 20/10/2019, 01:05 AM   #15
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

bump
__________________
zZzTGTzZz is offline   Reply With Quote
Old 26/10/2019, 10:52 PM   #16
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

bump... i can't resolve this. :/
__________________
zZzTGTzZz is offline   Reply With Quote
Old 27/10/2019, 09:18 AM   #17
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,441
Reputation: 1620
Default Re: Vehicle Spawning

Quote:
Originally Posted by zZzTGTzZz View Post
i think i already did it, i'm not sure.

Code:
enum renting_Data
{
	Model,
	Float:rentX,
	Float:rentY,
	Float:rentZ,
	Float:rentAngle,
	rentColor1,
	rentColor2
};

#define MAX_RENTING_VEHICLES 		5
#define MAX_VEHICLES_FOR_RENT 		MAX_PLAYERS

static const VehicleRent[MAX_RENTING_VEHICLES][renting_Data] = 
{
	// etc etc...
};

new Vehicle_for_Rent[MAX_VEHICLES_FOR_RENT];

public OnGameModeInit()
{
	for(new i = 0; i < MAX_RENTING_VEHICLES; i ++)
	{
		Vehicle_for_Rent[i] = AddStaticVehicle(VehicleRent[i][Model], // etc etc...);
	}
	return 1;
}
- Vehicle_for_Rent has an array size of MAX_PLAYERS (assuming you didn't re-define MAX_PLAYERS that is (500)). You are looping through MAX_RENTING_VEHICLES (5) while i < 5. So what is happening;
Code:
Vehicle_for_Rent[0] = AddStaticVehicle(VehicleRent[0][renting_Data:0],...);
Vehicle_for_Rent[1] = AddStaticVehicle(VehicleRent[1][renting_Data:0],...);
Vehicle_for_Rent[2] = AddStaticVehicle(VehicleRent[2][renting_Data:0],...);
Vehicle_for_Rent[3] = AddStaticVehicle(VehicleRent[3][renting_Data:0],...);
Vehicle_for_Rent[4] = AddStaticVehicle(VehicleRent[4][renting_Data:0],...);
That is rather odd.

Also you create a static constant array (VehicleRent) with the size of MAX_RENTING_VEHICLES which has per array the size of renting_Data (7).
You also have initial data for this array. Assuming you set all the data for all 5 vehicles it is not requires to use MAX_RENTING_VEHICLES; Assigning initial data automatically sets the array size. However that's not really important futher; If you'd increase MAX_RENTING_VEHICLES but not modify VehicleRent, the server will try to create vehicles with model 0. So Vehicle_for_Rent[>4]'s value would then be INVALID_VEHICLE_ID (65535).

Since VehicleRent[] has the array size of MAX_PLAYERS, you might want to create the vehicle when a player asks for/rents a rent vehicle (however you did do that in your script), and not in OnGameModeInit().

What is it precisely that doesn't work btw? Compile errors? Vehicles don't get created at all? Please let me know
Kwarde is online now   Reply With Quote
Old 27/10/2019, 11:25 PM   #18
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

To be more specific, the problem is when creating the vehicle, to assign the data where it should be created and with what model.
__________________
zZzTGTzZz is offline   Reply With Quote
Old 31/10/2019, 12:03 AM   #19
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

bump
__________________
zZzTGTzZz is offline   Reply With Quote
Old 31/10/2019, 01:27 PM   #20
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,112
Reputation: 67
Default Re: Vehicle Spawning

array and vehicleid might be different, make sure it's not.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Spawning the Vehicle MouizGhouri Scripting Help 12 29/05/2015 05:52 PM
Vehicle won't destroy after spawning another vehicle /image kbalor Scripting Help 19 12/07/2012 01:44 PM
Vehicle spawning Aleksalaz Scripting Help 2 02/06/2012 12:14 PM
Vehicle spawning Tanush123 Scripting Help 4 09/02/2012 09:44 PM


All times are GMT. The time now is 02:02 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.