Annoyed - confused - Befuzzled -
Prokill911 - 05.02.2015
Okay, So I want it to search for a house thats within 2500..
But it just keeps giving the same house...... Literally 35 attempts it gives the same place.
Код:
getClosestPizzaDelivery(playerid) {
new Float:pDistance;
new index;
for(new i=0;i<sizeof(Houses);i++) {
pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]);
if(pDistance > random(2500)) {
continue;
}
index = i;
}
SetPVarFloat(playerid, "PizzaTravelDistance", pDistance);
return index;
}
Re: Annoyed - confused - Befuzzled -
Schneider - 05.02.2015
Try this:
pawn Код:
getClosestPizzaDelivery(playerid)
{
new Float:pDistance, Float:nDistance = 9999.9, index = -1;
for(new i=0;i<sizeof(Houses);i++)
{
pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]);
if(pDistance < nDistance)
{
nDistance = pDistance;
index = i;
}
}
SetPVarFloat(playerid, "PizzaTravelDistance", nDistance);
return index;
}
Re: Annoyed - confused - Befuzzled -
Prokill911 - 05.02.2015
Quote:
Originally Posted by Schneider
Try this:
pawn Код:
getClosestPizzaDelivery(playerid) { new Float:pDistance, Float:nDistance = 9999.9, index = -1; for(new i=0;i<sizeof(Houses);i++) { pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]); if(pDistance < nDistance) { nDistance = pDistance; index = i; } } SetPVarFloat(playerid, "PizzaTravelDistance", pDistance); return index; }
|
I'll give it a try an let you know

.
Edit:
Didn't work.. still keeps going to the same place: Distance == 2764.433349
Re: Annoyed - confused - Befuzzled -
Schneider - 05.02.2015
I made one little error: In the SetPVarFloat-function, change: pDistance to nDistance.
Re: Annoyed - confused - Befuzzled -
Prokill911 - 05.02.2015
Quote:
Originally Posted by Schneider
I made one little error: In the SetPVarFloat-function, change: pDistance to nDistance.
|
trying it now

, I'll edit this after
Didn't work Q_Q...
Still sending to the exact same spot over an over.
IF there any way I can make it so If It's !< (100.0) !> (2000)
Re: Annoyed - confused - Befuzzled -
Keyhead - 05.02.2015
Anyone know how to fix this?
Re: Annoyed - confused - Befuzzled -
Schneider - 05.02.2015
I just tested it with some random generated coordinates.and the function works good as it should...
Are you sure the house-coordinates are stored correctly and are you using the function correctly? Can you show us the command where you use this function?
Edit: This is the code I used to test it:
//Top of script:
pawn Код:
enum hinfo
{
Float:EHouseX,
Float:EHouseY,
Float:EHouseZ
};
new Houses[90][hinfo];
//@ OnGameModeInit
pawn Код:
for(new i; i<90; i++)
{
Houses[i][EHouseX] = (random(6000)-3000);
Houses[i][EHouseY] = (random(6000)-3000);
Houses[i][EHouseZ] = (random(30));
}
//@ OnPlayerConnect:
pawn Код:
for(new i; i<90; i++)
{
SetPlayerMapIcon(playerid, i, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ], 31, 0, MAPICON_GLOBAL);
}
//Command:
pawn Код:
COMMAND:getnearesthouse(playerid, params[])
{
new house = getClosestPizzaDelivery(playerid);
if(house != -1)
{
SetPlayerCheckpoint(playerid, Houses[house][EHouseX], Houses[house][EHouseY], Houses[house][EHouseZ], 6.0);
}
return 1;
}
It works as it should, It shows a checkpoint at the nearest 'house'.
Re: Annoyed - confused - Befuzzled -
Prokill911 - 05.02.2015
Quote:
Originally Posted by Schneider
I just tested it with some random generated coordinates.and the function works good as it should...
Are you sure the house-coordinates are stored correctly and are you using the function correctly? Can you show us the command where you use this function?
Edit: This is the code I used to test it:
//Top of script:
pawn Код:
enum hinfo { Float:EHouseX, Float:EHouseY, Float:EHouseZ }; new Houses[90][hinfo];
//@ OnGameModeInit
pawn Код:
for(new i; i<90; i++) { Houses[i][EHouseX] = (random(6000)-3000); Houses[i][EHouseY] = (random(6000)-3000); Houses[i][EHouseZ] = (random(30)); }
//@ OnPlayerConnect:
pawn Код:
for(new i; i<90; i++) { SetPlayerMapIcon(playerid, i, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ], 31, 0, MAPICON_GLOBAL); }
//Command:
pawn Код:
COMMAND:getnearesthouse(playerid, params[]) { new house = getClosestPizzaDelivery(playerid); if(house != -1) { SetPlayerCheckpoint(playerid, Houses[house][EHouseX], Houses[house][EHouseY], Houses[house][EHouseZ], 6.0); } return 1; }
It works as it should, It shows a checkpoint at the nearest 'house'.
|
That's just selecting the closest house to your current location...
Also, My information saves via SQL, An selects all houses on loading an saves the info.;
How I need it = IT selects a random house >> GREATER than 500 distance an then returns it..
Re: Annoyed - confused - Befuzzled -
Prokill911 - 05.02.2015
Quote:
Originally Posted by Schneider
Try this:
pawn Код:
getClosestPizzaDelivery(playerid) { new Float:pDistance, Float:nDistance = 9999.9, index = -1; for(new i=0;i<sizeof(Houses);i++) { pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]); if(pDistance < nDistance) { nDistance = pDistance; index = i; } } SetPVarFloat(playerid, "PizzaTravelDistance", nDistance); return index; }
|
THIS is the code which I'm using.
I've tried multiple things... But it wont select a house OVER 500 meters away...
Код:
getMaxPizzaDeliveryTime(playerid, index) {
new Float: pDistance = GetPlayerDistanceFromPoint(playerid, Houses[index][EHouseX], Houses[index][EHouseY], Houses[index][EHouseZ]);
return floatround(pDistance/10, floatround_round);
}
initiatePizzaDelivery(playerid) {
new job = GetPVarInt(playerid, "Job");
if(job != EJobType_PizzaMan) {
return 1;
}
new string[128];
new houseid = getClosestPizzaDelivery(playerid);
new deliverytime = getMaxPizzaDeliveryTime(playerid, houseid);
SetPlayerCheckpoint(playerid, Houses[houseid][EHouseX],Houses[houseid][EHouseY],Houses[houseid][EHouseZ],5.0);
SetPVarInt(playerid, "IsOnPizzaRoute", 1);
SetPVarFloat(playerid, "PizzaDeliveryTime", deliverytime);
format(string, sizeof(string), "You have %d seconds to deliver the pizza to the destination.", deliverytime);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
return 1;
}
getClosestPizzaDelivery(playerid) {
new Float:pDistance;
new index;
for(new i=0;i<sizeof(Houses);i++) {
pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]);
if(pDistance > random(1000)) {
continue;
}
index = i;
}
SetPVarFloat(playerid, "PizzaTravelDistance", pDistance);
return index;
}
Re: Annoyed - confused - Befuzzled -
Schneider - 05.02.2015
Well, you didn't mention it had to be at least 500 units away and since you called your function
getClosestPizzaDelivery I assumed you wanted to get the
closest location...
Anyway, try this one. This should select a random house between 500 and 2500 units away:
Make sure, when you use this function, it doesn't return '-1'. (No house found). I added this to prevent the server from getting in an infinite loop.
pawn Код:
getClosestPizzaDelivery(playerid)
{
new Float:pDistance, i, index = -1, loop;
while(index == -1)
{
loop++;
i = random(sizeof(Houses));
pDistance = GetPlayerDistanceFromPoint(playerid, Houses[i][EHouseX], Houses[i][EHouseY], Houses[i][EHouseZ]);
if(500.0 < pDistance < 2500.0)
{
index = i;
}
if(loop == 500) return -1;
}
SetPVarFloat(playerid, "PizzaTravelDistance", pDistance );
return index;
}
Re: Annoyed - confused - Befuzzled -
Keyhead - 07.02.2015
It seems to only be selecting two houses, always the same two. Any ideas?