SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 30/04/2016, 07:09 PM   #1
CloudLEL
Little Clucker
 
Join Date: Oct 2014
Posts: 14
Reputation: 0
Default Next available ID

Hi,

I need some insight on how I can do the following.

Say I have a command in-game which creates a vehicle. And each time it creates a vehicle it assigns an incremental ID to the vehicle (1, 2, 3, 4 etc..)

But if I delete the vehicle with the ID 3. The next vehicle I create needs to replace the ID that was deleted instead of continuing on the list.

Anyone know how I can do this?
CloudLEL is offline   Reply With Quote
Old 30/04/2016, 07:52 PM   #2
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default Re: Next available ID

Code:
stock GetFreeVehicleSlot()
{
	for(new i = 1; i < MAX_VEHICLES; i ++)
	{
	    if(!IsValidVehicle(i)) return i;
	}
	return 0;
}
This will get the next vehicleid that is unused.
__________________
[Tutorial] Custom Playerdamage system
Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
CalvinC is offline   Reply With Quote
Old 30/04/2016, 08:06 PM   #3
CloudLEL
Little Clucker
 
Join Date: Oct 2014
Posts: 14
Reputation: 0
Default Re: Next available ID

I fixed it anyhow, thanks.
CloudLEL 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



All times are GMT. The time now is 12:20 AM.


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