How to detect if a player is in range of a object?
#1

I know how to assign a object to a specific playerid and detect if their near it. But how do I make the object for everyone? Say someone types /object and a object appears on the ground. I want anyone who goes near it to have something happen to them. How could I make this possible?

ANY help would be much appreciated. Thank you.
Reply
#2

Does this help at all?

http://pastebin.com/JBnGqTmk

(Code obviously not written by me)
Reply
#3

Not really, as it's assigning that object a "ID" when I need the ID to be global, I suppose. I'm not too sure how to put it, honestly. Would this work? I want more than 1 object to be able to be placed. So if another player placed a object, would the ID's shift to the newest object?

pawn Код:
foreach(Player, i)
{
    if(IsPlayerNearObject(i, objectid, 3.0)
    {
        //would this detect if ANYONE is near it?
    }
}
Reply
#4

The streamer plugin's dynamic areas are probably the easiest way to tackle this problem. It has callbacks for entering and leaving an area as well.
Reply
#5

Incognito's? I've never even bothered using the available functions/callbacks honestly. I'll check them out and get back to you.

EDIT: There's a bazillion functions on there! I went to the "Areas" and searched for a few. Would I need to create a area in order to detect this? It would be great if you could show me a example of this. And I noticed the "playerid = -1" param in the function. Would the -1 create the area for ALL players?

pawn Код:
native CreateDynamicCircle(Float:x, Float:y, Float:size, worldid = -1, interiorid = -1, playerid = -1);
EDIT2: Still experimenting with the functions.
Reply
#6

Any shape might work, but a circle or sphere is probably the most fitting. And yes, -1 means all. It works just like pickups, honestly;
pawn Код:
new gMyArea;

gMyArea = CreateDynamicSphere(...);

public OnPlayerEnterDynamicArea(playerid, areaid)
{
    if(areaid == gMyArea)
    {
        // stuff
    }
    return 1;
}
Reply
#7

Yup. I'm just messing with them, and will hopefully create something cool out of experimentation. Thanks for the responses.

And just out of curiosity. I've been thinking about it a lot. My code is quite messy, and I was wondering how you organize your code properly? Do you include stocks/forwards/callbacks all under a different category separated by comments?
Reply
#8

Rather than complicating it with dynamic areas, Why don't you use IsValidDynamicObject + GetDynamicObjectPos (if you use dynamic objects, you can guess what the normal function is) + IsPlayerInRangeOfPoint? That's really the easiest way.

Also don't use stocks if it's a full gamemode. Use normal functions.
Reply
#9

Quote:
Originally Posted by CuervO
Посмотреть сообщение
Rather than complicating it with dynamic areas, Why don't you use IsValidDynamicObject + GetDynamicObjectPos (if you use dynamic objects, you can guess what the normal function is) + IsPlayerInRangeOfPoint? That's really the easiest way.
.
I'm not really understanding your above post. Could you elaborate with a example?
Reply
#10

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
I'm not really understanding your above post. Could you elaborate with a example?
You can use GetObjectPos (i'll use the native functions) to get the exact object position for the desired id. Then you can proceed to check if the player is near that position with IsPlayerInRangeOfPoint or even GetPlayerDistanceFromPoint (not recommended)

The resources taken on this would be WAY less than having the streamer check constantly if the player is in an area, as you see, you would be checking this once - when the player types the command.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)