SA-MP Forums Archive
Getting an ID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting an ID (/showthread.php?tid=560638)



Getting an ID - Luis- - 29.01.2015

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?


Re: Getting an ID - Sime30 - 29.01.2015

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;
}



Re: Getting an ID - Luis- - 29.01.2015

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


Re: Getting an ID - Vince - 29.01.2015

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.


Re: Getting an ID - Luis- - 29.01.2015

Ah brilliant, thanks Vince!