Is player in range of object?
#1

I'm trying to make it to where if they player is in range of any one of these fishing poles I've made, it will allow them to fish, but I just keep getting the message:
"You're not at the pier!"

pawn Код:
public OnGameModeInit()
{
    CreateObject(18632,-2997.06,460,5.16,180,45,0);
    CreateObject(18632,-2997.06,465,5.16,180,45,0);
    CreateObject(18632,-2997.06,470,5.16,180,45,0);
    CreateObject(18632,-2997.06,475,5.16,180,45,0);
    CreateObject(18632,-2997.06,480,5.16,180,45,0);
    return 1;
}

CMD:fish(playerid,params[])
{
   if(pInfo[playerid][Job]==2)
   {
       new Float:x,Float:y,Float:z;
       GetObjectPos(18632,x,y,z);
       if(IsPlayerInRangeOfPoint(playerid,2,x,y,z))
       {
           if(fish[playerid]<2000)
           {
               if(worms[playerid]>1)
               {
                   new str[128];
                   format(str,sizeof(str),"* * %s cast out their fishing line.",GetName(playerid));
                   ProxDetector(30,playerid,str,COLOR_PURPLE);
                   TogglePlayerControllable(playerid,0);
                   worms[playerid]--;
                   defer fWait(playerid);
               }
               else SendClientMessage(playerid,COLOR_RED,"You have no worms!");
           }
           else SendClientMessage(playerid,COLOR_RED,"You've reached the limit!");
       }
       else SendClientMessage(playerid,COLOR_RED,"You're not at the pier!");
   }
   return 1;
}
Reply
#2

Try this:
pawn Код:
new fObjects[5];
public OnGameModeInit()
{
    fObjects[0] = CreateObject(18632, -2997.06, 460, 5.16, 180, 45, 0);
    fObjects[1] = CreateObject(18632, -2997.06, 465, 5.16, 180, 45, 0);
    fObjects[2] = CreateObject(18632, -2997.06, 470, 5.16, 180, 45, 0);
    fObjects[3] = CreateObject(18632, -2997.06, 475, 5.16, 180, 45, 0);
    fObjects[4] = CreateObject(18632, -2997.06, 480, 5.16, 180, 45, 0);
    return 1;
}

CMD:fish(playerid)
{
    if(pInfo[playerid][Job] == 2)
    {
        new Float:x[5], Float:y[5], Float:z[5];
        for(new i; i < 5; i ++)
        {
            GetObjectPos(fObjects[i], x[i], y[i], z[i]);
            if(IsPlayerInRangeOfPoint(playerid, 2, x[i], y[i], z[i]))
            {
                if(fish[playerid] < 2000)
                {
                    if(worms[playerid] > 1)
                    {
                        new str[128];
                        format(str, sizeof(str), "* * %s cast out their fishing line.", GetName(playerid));
                        ProxDetector(30, playerid, str, COLOR_PURPLE);
                        TogglePlayerControllable(playerid, 0);
                        worms[playerid] --;
                        defer fWait(playerid);
                    }
                    else SendClientMessage(playerid, COLOR_RED, "You have no worms!");
                }
                else SendClientMessage(playerid, COLOR_RED, "You've reached the limit!");
            }
            else SendClientMessage(playerid, COLOR_RED, "You're not at the pier!");
        }
    }
    return 1;
}
Reply
#3

your doing it wrong
pawn Код:
//make a new Array becosue u need to store the objectids
new ObjPos[4];

//Creat the objects
public OnGameModeInit()
{
    ObjPos[0] = CreateObject(18632,-2997.06,460,5.16,180,45,0);
    ObjPos[1] = CreateObject(18632,-2997.06,465,5.16,180,45,0);
    ObjPos[2] = CreateObject(18632,-2997.06,470,5.16,180,45,0);
    ObjPos[3] = CreateObject(18632,-2997.06,475,5.16,180,45,0);
    ObjPos[4] = CreateObject(18632,-2997.06,480,5.16,180,45,0);
    return 1;
}

CMD:fish(playerid,params[])
{
   if(pInfo[playerid][Job]==2)
   {
       new Float:x,Float:y,Float:z;
       new Counter=0;
       for(new i=0; i < sizeof(ObjPos); i++)
          {
             GetObjectPos(ObjPos[i],x,y,z);
             if(!IsPlayerInRangeOfPoint(playerid,2,x,y,z))
                {
                    Counter++;
                    if(Counter>= sizeof(ObjPos))
                       {
                           SendClientMessage(playerid,COLOR_RED,"You're not at the pier!");
                           return 0;
                       }
                }else continue;
         }
       if(fish[playerid]<2000)
          {
             if(worms[playerid]>1)
                {
                    new str[128];
                    format(str,sizeof(str),"* * %s cast out their fishing line.",GetName(playerid));
                    ProxDetector(30,playerid,str,COLOR_PURPLE);
                    TogglePlayerControllable(playerid,0);
                    worms[playerid]--;
                    defer fWait(playerid);
                }else SendClientMessage(playerid,COLOR_RED,"You have no worms!");
           }else SendClientMessage(playerid,COLOR_RED,"You've reached the limit!");
   }
   return 1;
}
There are other ways ofc, but i tried to keep it your way.

EDITED
Reply
#4

The one you posted before doesn't work and this edit doesn't work either.
Reply
#5

Tell me what the problem is, don't just say it doesn't work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)