Getting an ID
#1

Right, I've made a stock, which will loop through the array of each dealership;
pawn Код:
stock GetNearestDealership(playerid) {
    for(new i = 0; i != sizeof Dealerships; i++) {
        if(IsPlayerInRangeOfPoint(playerid, 5.0, Dealerships[i][0], Dealerships[i][1], Dealerships[i][2])) {
            return i;
        }
    }
    return 1;
}
As you can see i'm "returning i" but that's not working so, how would I actually get what dealership the player is near?
Reply
#2

I am using these codes for my gas station

pawn Код:
NearestGasStation(playerid)
{
    new gasid, Float:distance = 99999.0, Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i <MAX_BIZ; i++)
    {
       
            new Float:tempdist;
            tempdist = GetDistance(x, y, z, BizInfo[i][EXTX], BizInfo[i][EXTY], BizInfo[i][EXTZ]);
            if(tempdist < distance)
            {
                distance = tempdist;
                gasid= i;
            }
    }
    return gasid;
}
Reply
#3

Is there anyway of making my code work, I prefer keeping a smaller code.
Reply
#4

Well, you're returning 1 if nothing is found and I reckon 1 is a valid value. You will need to change that to something invalid, like -1, cellmin, cellmax or 0xFFFF.
Reply
#5

Ah brilliant, thanks Vince!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)