2 stock help
#1

Everytime i use this stock (i made a test debug command) appears always ID 0

how to make it not return id 0

pawn Код:
stock nearestwanted(playerid)
{
    new Float:x, Float:y, Float:z;
    new ii;
    GetPlayerPos(playerid, x, y, z);
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z) && GetPlayerWantedLevel(i) >= 3)
        {
            printf("Player %d is The Nearest Wanted Level", i);
            ii = i;
            return ii;
        }
        else
        {
            print("No Wanted Level Near");
            ii = 0;
            return ii;
        }
    }
    return -1;
}

stock nearestrobbable(playerid)
{
    new Float:x, Float:y, Float:z;
    new ii;
    GetPlayerPos(playerid, x, y, z);
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
        {
            printf("Player %d is The Nearest Robbable Player", i);
            if(i = playerid) return 1;
            else
            {
                ii = i;
                return ii;
            }
        }
        else
        {
            print("No Robbable player near");
            ii = 0;
            return ii;
        }
    }
    return -1;
}
Reply
#2

It wont show you nearest player as you return from loop before the loop is completed

Use this UNTESTED
pawn Код:
stock Float:GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2) //By Gabriel "Larcius" Cordes
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(x1,x2),2)),floatsqroot(floatpower(floatsub(y1,y2),2))),floatsqroot(floatpower(floatsub(z1,z2),2)));
}

stock nearestwanted(playerid)
{
    new Float:x, Float:y, Float:z;
    new Float:x1, Float:y1, Float:z1;//To store position of player i (in loop)
    new ii;
    GetPlayerPos(playerid, x, y, z);
    new Float:d=9999;//Assuming d is distance b/w playerid and i and it is 9999 (much)
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if(!IsPlayerConnected(i) || i == playerid) continue;//If player is not connected or playerid is equal to  i
        GetPlayerPos(i, x1, y1, z1);//Store Player Pos (i)  in x1,y1,z1
        if (GetDistance(x, y, z,x1,y1,z1)<d && GetPlayerWantedLevel(i) >= 3)//If distance is lesser than smallest distance
//We assumed smallest distance to be 9999.
        {
            //printf("Player %d is The Nearest Wanted Level", i); We dont need this.
            ii = i;//Store value of i in ii
            d=GetDistance(x, y, z,x1,y1,z1);//Store the new smallest distance in d.
            //return ii;We wont return until loop has gone through all players
        }
    }
    if(d<=5) return ii;//If smallest distance loop could find was less than or equal to 5 then return nearest playerid.
    print("No Wanted Level Near");//Else no player was i range of 5
    return -1;
}
//Similarly for this.
stock nearestrobbable(playerid)
{
    new Float:x, Float:y, Float:z;
    new Float:x1, Float:y1, Float:z1;
    new ii;
    new Float:d = 9999;
    GetPlayerPos(playerid, x, y, z);
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if(!IsPlayerConnected(i) || i == playerid) continue;
        GetPlayerPos(i, x1, y1, z1);
        if (GetDistance(x, y, z,x1,y1,z1)<d)
        {
            //printf("Player %d is The Nearest Robbable Player", i);
            ii = i;
            d=GetDistance(x, y, z,x1,y1,z1);
        }
    }
    id( d<=5)   return ii;
    print("No Robbable player near");
    return -1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)