SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 15/10/2019, 07:01 PM   #1
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Vehicle Spawning

How about, I'd like to fix a code that isn't working for me. My idea is to create vehicles that when a player takes one, recreates another in that position, but if there is a vehicle in that position, it does not create a new one.

Code:
#define MAX_RENTING_CAR         1

enum rentinf
{
	rModel,
	rColor1,
	rColor2,
	Float:rPosX,
	Float:rPosY,
	Float:rPosZ,
	Float:rAng
};

static const Rent[MAX_RENTING_CAR][rentinf] = 
{
	{492, 1228.0363, -1425.5000, 13.5000, 0.0000, 1, 1}
}

new Vehicle_Renta[MAX_RENTING_CAR];

task UpdateVehicles[5000]()
{
	foreach(new x : Player)
	{
		for(new i = 0; i < MAX_RENTING_CAR; i ++)
		{
			if(GetVehicleDistanceFromPoint(Vehicle_Rent[i], Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ]) >= 5.0 && GetPVarInt(x, "RentingCarID") != Vehicle_Rent[i])
				return SetVehicleToRespawn(Vehicle_Rent[i]);

			if(GetVehicleDistanceFromPoint(Vehicle_Rent[i], Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ]) <= 5.0) 
				return 1;

			if(IsPlayerInRangeOfPoint(x, 5.0, Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ]))
				return 1;

			Vehicle_Rent[i] = AddStaticVehicle(Rent[i][rModel], Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ], Rent[i][rAng], Rent[i][rColor1], Rent[i][rColor2]);
		}
	}
	return 1;
}
__________________
zZzTGTzZz is online now   Reply With Quote
Old 15/10/2019, 07:08 PM   #2
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,442
Reputation: 1620
Default Re: Vehicle Spawning

https://forum.sa-mp.com/showthread.php?t=669693

Someone asked something similar recently. You have to script it yourself but an explaination on how to do it should be somewhere in the replies
Kwarde is offline   Reply With Quote
Old 15/10/2019, 08:04 PM   #3
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

I had done that topic, but I had to do a code reconstruction etc etc and I couldn't find it xD.
I can't get the code, I don't understand.
__________________
zZzTGTzZz is online now   Reply With Quote
Old 15/10/2019, 08:33 PM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,442
Reputation: 1620
Default Re: Vehicle Spawning

> OnPlayerEnterVehicle
THEN
--> If player is not passenger
THEN
-->--> Save vehicle position and ID in either a variable or PVar
END
END

> OnPlayerUpdate
THEN
--> If player still in vehicle ID
THEN
-->--> If current position is (define range) away from saved position
THEN
-->-->--> Create the new vehicle at saved position (and model etc from GetVehicleModel)
END
END
END

This.
Kwarde is offline   Reply With Quote
Old 16/10/2019, 01:43 AM   #5
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

In fact, I simply put the player a variable and when the timer detects that it has that variable and is not in that position, it creates the vehicle.

Thanks for the help! + rep.
__________________
zZzTGTzZz is online now   Reply With Quote
Old 16/10/2019, 02:01 AM   #6
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,442
Reputation: 1620
Default Re: Vehicle Spawning

A timer doesn't detect anything.

Apart from that it seems you do get it when you're done with the script, let me know if it works --and show it to me. Me very slightly curious
Kwarde is offline   Reply With Quote
Old 16/10/2019, 02:09 AM   #7
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case D_RENTING:
		{
			if(!response) return RemovePlayerFromVehicle(playerid);

			SetPVarInt(playerid, "RentingCarID", GetPlayerVehicleID(playerid));
			SetPVarInt(playerid, "CreateCar", 1);
		}
	}
	return 1;
}

task UpdateVehicles[5000]()
{
	foreach(new x : Player)
	{
		for(new i = 0; i < MAX_RENTING_CAR; i ++)
		{
			if(GetVehicleDistanceFromPoint(Vehicle_Rent[i], Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ]) >= 5.0 && GetPVarInt(x, "RentingCarID") != Vehicle_Rent[i])
			{
				SetVehicleToRespawn(Vehicle_Rent[i]);
			}

			if(GetPVarInt(x, "CreateCar"))
			{
				if(GetVehicleDistanceFromPoint(GetPVarInt(x, "RentingCarID"), Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ]) >= 5.0 && Vehiculo_Renta[i] == GetPVarInt(x, "RentingCarID"))
				{
					DeletePVar(x, "CreateCar");
					Vehicle_Rent[i] = AddStaticVehicle(Rent[i][rModel], Rent[i][rPosX], Rent[i][rPosY], Rent[i][rPosZ], Rent[i][rAng], Rent[i][rColor1], Rent[i][rColor2]);
				}
			}
		}
	}
	return 1;
}
__________________
zZzTGTzZz is online now   Reply With Quote
Old 16/10/2019, 09:43 PM   #8
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,442
Reputation: 1620
Default Re: Vehicle Spawning

- To check if a PVar exists you could better use GetPVarType() and check if it's not PLAYER_VARTYPE_NONE
- You should break the loop once the vehicle is added.
Kwarde is offline   Reply With Quote
Old 17/10/2019, 09:52 PM   #9
zZzTGTzZz
Little Clucker
 
Join Date: Dec 2016
Posts: 49
Reputation: 14
Default Re: Vehicle Spawning

I have one more question, is this array well defined?

Code:
#define MAX_RENTING_CARS     12

enum renting_car
{
 // etc etc...
}

static const RentingCar[MAX_RENTING_CARS][renting_car] = 
{
     // etc etc...
}

new RentingCars[MAX_RENTING_CARS]; // Here.
Because the maximum is 12, but they can continue to generate vehicles, I don't know if I explain myself.
__________________
zZzTGTzZz is online now   Reply With Quote
Old 17/10/2019, 10:09 PM   #10
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,442
Reputation: 1620
Default Re: Vehicle Spawning

You can't extend an array during runtime.
If all 12 slots (0-11) are used and if you never reset it (or atleast change the indexes to a variable that tells the script it is unused) you won't be able to create more than twelve renting cars
Kwarde 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 04:37 AM.


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