Check vehicles nearby
#6

Код:
1. If you store the vehicle data you are not only eating up unnecessary memory, you are going to need to continually update the data. This will be either by a timer, update procedure, or something else, requiring more code and used resources for the same effect.
No. I'd not update anything. I don't mind if server has to store some floats in memory. When starting the server vehicles will be created at those coords, the coords will get stored in the vehicle's enum after that, so you can use the same coords to check if you are near a vehicle of those without stocking around. Also you are forgetting that you will have the vehicle to respawn not only when it gets destroyed, but also when someone rams that car away. You would use another stock to respawn it, I'd use a "simple" for() and whenever the coords arent the same the car will get respawned. Keep it clean.

Код:
2. Your code shouldn't call IsPlayerInRangeOfPoint for all 1000 vehicles, regardless of if they are actually valid vehicles or not. That is most likely one of the slowest native functions so you will want to keep the calls to a minimum.
Am sorry, but you did something similar.

Код:
stock IsPlayerNearSpecifiedVehicle(playerid, model) {

	for(new v = 0; v < MAX_VEHICLES; v++) {
		if(IsValidVehicle(v) && GetVehicleModel(v) == model) {
			new Float: x, Float: y, Float: z;
			GetVehiclePos(v, x, y, z);

			if(IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z))
				return 1;
		}
	}
	return 0;
}
there could be many cars with the same id, or he could need to check all of them to make moved cars respawn. This will make script getvehiclepos n times, and check the range of point n times. What's wrong with that? That you need to get the position everytime creating new floats everytime, and then do the checking. This ain't memory cheap thing at all. I prefer having my enum so the checkings are less, used functions are less. Also, you check MAX_VEHICLES regardless if the server has only 50 cars around.

Код:
4. "No need for all these stocks." This is probably the 10th time I've read this over the past week. I would love someone to explain the logic behind this to me. Are they damaging in some way?
https://sampforum.blast.hk/showthread.php?tid=570635
Reply


Messages In This Thread
Check vehicles nearby - by Drak03 - 26.03.2018, 12:55
Re: Check vehicles nearby - by v1k1nG - 26.03.2018, 13:32
Re: Check vehicles nearby - by Grim_ - 26.03.2018, 13:48
Re: Check vehicles nearby - by v1k1nG - 26.03.2018, 14:55
Re: Check vehicles nearby - by Grim_ - 26.03.2018, 15:01
Re: Check vehicles nearby - by v1k1nG - 26.03.2018, 15:26
Re: Check vehicles nearby - by Grim_ - 26.03.2018, 15:41
Re: Check vehicles nearby - by v1k1nG - 26.03.2018, 16:05
Re: Check vehicles nearby - by Lokii - 26.03.2018, 16:27
Re: Check vehicles nearby - by Grim_ - 26.03.2018, 17:32

Forum Jump:


Users browsing this thread: 1 Guest(s)