possible?
#1

Hey guys. I'm making a FS but I need your help.
I'm now at this command.

pawn Код:
if (strcmp("/takedrugs", cmdtext, true, 10) == 0)
    {

  if(IsPlayerInRageOfObject(3.0,308);
  {
  SendClientMessage(playerid,0xFFFF00AA,"You are not near a drugs plant");
  return 1;
  }
  drugs[playerid] +=1;
 
    return 1;
    }
But yea the if(IsPlayerInRageOfObject(3.0,30; doesn't works ofcourse.
How to make something like that? SO it will work?
And how to delete that object directly?

Thanks in advance
Reply
#2

I would suggest you to take a closer look on this function.

https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

It's IsPlayerInRangeOfPoint(playerid, range, x,y,z))


This one to destroy objects.

https://sampwiki.blast.hk/wiki/DestroyObject
Reply
#3

Well. I know that function. Both of them :P
But i don't know how to check if the player is in range of object model 801
Reply
#4

To check the coords of the object.

https://sampwiki.blast.hk/wiki/GetObjectPos

Then put the coords into the IsPlayerInRangeOfPoint.
Reply
#5

Ooooow. NO I seeee. Thaankyaaa
Reply
#6

If you want to find the closest object to a player, and destroy it, you would have to loop around all created objects, which is very resource unfriendly, the more objects you have.

An example:

pawn Код:
stock IsPlayerInRangeOfObject(playerid, objectid)
{
    new
        Float:ox, Float:oy, Float:oz;
       
    GetObjectPos(objectid, ox, oy, oz);
    if(IsPlayerInRangeOfPoint(playerid, YOUR_RANGE, ox, oy, oz)) return 1;
    return 0;
}

stock IsPlayerInRangeOfAnyObject(playerid)
{
    new
        Float:ox, Float:oy, Float:oz, closest = -1;
       
    for(new a = 0; a < MAX_OBJECTS; a++)
    {
        GetObjectPos(a, ox, oy, oz);
        if(IsPlayerInRangeOfPoint(playerid, YOUR_RANGE, ox, oy, oz))
        {
            closest = a;
        }
    }
   
    if(closest != -1) return closest;
    return -1;
}
There's two example functions.

Now, I'd use the 2nd example, with a varible instead of 'MAX_OBJECTS', The reason being, MAX_OBJECTS would probably be made quite high, and in most cases, thousands more than how many objects you have.

When you load a object, you should increase a varible, for example 'ObjectCount' by one, then loop around ObjectCount, so that you only loop around created objects.

In the long run, this is more efficient than using a constant, due to it being more dynamic (eg, the value of ObjectCount will change when a object is deleted/created, and a constant like MAX_OBJECTS will have to be changed manualy or redefined)

pawn Код:
stock CreateObjectEx(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    new
        Objectid = CreateObject(modelid, x, y, z, rx, ry, rz);
       
    ObjectCount++;
    return Objectid;
}
The above example should only be used in one file (for example a gamemode, due to varibles not being able to go across scripts)

The below example, which is untested, and in logic, probably pretty slow, due to varibles being faster than functions, and it sounds like you're making an object streamer, if that's the case, speed is needed.

pawn Код:
stock CreateObjectEx(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    new
        Objectid = CreateObject(modelid, x, y, z, rx, ry, rz);

    SetGVarInt("ObjectCount", GetGVarInt("ObjectCount") + 1, Objectid);
    return Objectid;
}
GVar is a plugin by Icognito, it works like the PVar system, but is not bound to players, It's like a varible, but with an ID, you could say it's like an Array(?).

pawn Код:
new
    Arr[100];
pawn Код:
SetGVarInt("Arr", 0, 0);
SetGVarInt("Arr", 1, 1);
SetGVarInt("Arr", 2, 2);
If you look at that, it looks like it works like an array, but I don't know, anyway, hope this helped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)