26.03.2018, 15:01
So, a few notes...
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.
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.
3. You don't need a stock for each vehicle. He asked for one use case so he got it. Otherwise, he could do something like so...
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?
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.
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.
3. You don't need a stock for each vehicle. He asked for one use case so he got it. Otherwise, he could do something like so...
pawn Код:
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;
}