stock GetNextMissionCheckpoint(playerid) { new msg[50]; new Float:distance = 1000000.0, nearestID = -1; for(new p = 0; p < sizeof(mInfo); p++) { if(mInfo[p][mID] != 0) { distance = GetPlayerDistanceFromPoint(playerid, mInfo[p][mX], mInfo[p][mY], mInfo[p][mY]); if(distance > 500) { suitedmission[p] = mInfo[p][mID]; } } } // problem down here new i = random( format(msg,sizeof(msg), "Mission ID %i, X: %f, Y: %f, Z: %f", mInfo[i][mID], mInfo[i][mX], mInfo[i][mY], mInfo[i][mZ]); SendClientMessage(playerid, COLOR_WHITE, msg); nearestID = i; return nearestID; // problem up here }
stock GetNextMissionCheckpoint(playerid) {
#define SIZE 64
#if sizeof mInfo > SIZE
#undef SIZE
#define SIZE sizeof mInfo
#endif
new
count,
p = -1,
tmp[SIZE]
;
while(++p < sizeof mInfo) {
if(mInfo[p][mID] != 0) { // \/ changed second mY to mZ
if(500.0 < GetPlayerDistanceFromPoint(playerid, mInfo[p][mX], mInfo[p][mY], mInfo[p][mZ])) {
tmp[count++] = mInfo[p][mID];
}
}
}
p = tmp[random(count)];
format(tmp, sizeof tmp, "Mission ID %i, X: %f, Y: %f, Z: %f", mInfo[p][mID], mInfo[p][mX], mInfo[p][mY], mInfo[p][mZ]);
SendClientMessage(playerid, COLOR_WHITE, tmp);
return p;
}
For some reason that code always ends up with mission ID 0, which doesn't exist, so it's point is at 0.0 0.0 0.0
But once i remove the mission ID checker so it can be mission id 0, then it's always comes up with mission ID 1 |
stock GetNextMissionCheckpoint(playerid) {
#define SIZE 64
#if sizeof mInfo > SIZE
#undef SIZE
#define SIZE sizeof mInfo
#endif
new
count,
p = -1,
tmp[SIZE]
;
while(++p < sizeof mInfo) {
if(mInfo[p][mID] != 0) { // \/ changed second mY to mZ
if(500.0 < GetPlayerDistanceFromPoint(playerid, mInfo[p][mX], mInfo[p][mY], mInfo[p][mZ])) {
tmp[count++] = mInfo[p][mID];
}
}
}
if(count == 0) {
return printf("No mission found!");
}
printf("count %d", count); // add some debug prints
for(new i; i < count; ++i) printf("%d - %d", i, tmp[i]);
p = tmp[random(count)];
format(tmp, sizeof tmp, "Mission ID %i, X: %f, Y: %f, Z: %f", mInfo[p][mID], mInfo[p][mX], mInfo[p][mY], mInfo[p][mZ]);
SendClientMessage(playerid, COLOR_WHITE, tmp);
return p;
}
mInfo
enum missioninfo { mID, Float:mX, Float:mY, Float:mZ, bool:loaded }; new mInfo[MAX_Missions][missioninfo];
The code works, but the problem with mission ID 0 still occures, in the console it shows for example:
0 - 3 1 - 4 and it still sends mission ID 0, which i really can't explain. But that only happens rarely |
p = tmp[random(count)];
p = tmp[random(count-1)];