Author Topic: How to get a player's ID through a radius search? - SOLVED  (Read 3141 times)

I need straight forward replies. I don't really understand how the radius search crap works in the first place. I just need to know how to detect the type of object in the radius, and how to call different commands if that object is a certain type.

This topic is now solved. Thank you all so much!!

 :cookie:
« Last Edit: February 26, 2016, 03:34:35 PM by BloxersPost »

I need straight forward replies. I don't really understand how the radius search crap works in the first place. I just need to know how to detect the type of object in the radius, and how to call different commands if that object is a certain type.

Everyone was giving you a clear answer, don't create new topics, just ask if something is unclear.
As Jes said:
Code: [Select]
%mask = $Typemasks::PlayerObjectType;
initContainerRadiusSearch(%loc, %radius, %mask);

while(isObject(%player = containerSearchNext()))
{
%player.burn(1);
}
The value stored in %player is the players ID. You can perform operations on the player doing %player.client.getname(), getClassName(%player) etc. etc.

you also need to put in some effort on your hand to understand what we're telling you - we can't just feed you an answer that gives you exactly what you want. being angry and insensitive to the fact that we're trying to help you will only garner hate.

when you run a radius search, it checks a sphere around point %pos, with radius %radius, looking for objects of the typemask %mask (eg $TypeMasks::FxBrickObjectType | $TypeMasks::PlayerObjectType). Once starting the radius search, you run containerSearchNext(), which will return each object it finds sequentially.

for example, if the radius search finds objects %a, %b, %c, and you run the following code

while (isObject(%hit = containerSearchNext()))
     echo(%hit);

it will echo

%a
%b
%c

where %a, %b, %c are the objects, usually titled by their Object ID (the only exception I can think of is datablocks).

Thus if you run a container search for players, the results you get are the objects themselves, in the form of their object ID.
Read the code others are providing, and try to understand what is going on in them.
« Last Edit: February 26, 2016, 03:00:52 PM by Conan »

the two last posts in your other thread answered that question

you also need to put in some effort on your hand to understand what we're telling you - we can't just feed you an answer that gives you exactly what you want. being angry and insensitive to the fact that we're trying to help you will only garner hate.

when you run a radius search, it checks a sphere around point %pos, with radius %radius, looking for objects of the typemask %mask (eg $TypeMasks::FxBrickObjectType | $TypeMasks::PlayerObjectType). Once starting the radius search, you run containerSearchNext(), which will return each object it finds sequentially.

for example, if the radius search finds objects %a, %b, %c, and you run the following code

while (isObject(%hit = containerSearchNext()))
     echo(%hit);

it will echo

%a
%b
%c

where %a, %b, %c are the objects, usually titled by their Object ID (the only exception I can think of is datablocks).

Thus if you run a container search for players, the results you get are the objects themselves, in the form of their object ID.
Read the code others are providing, and try to understand what is going on in them.

Thanks for the clarification. I wasn't getting angry, I couldn't really understand what they meant. I didn't know there was another object type to possibly return. Again, thanks.  :cookie:

Everyone was giving you a clear answer, don't create new topics, just ask if something is unclear.
As Jes said:The value stored in %player is the players ID. You can perform operations on the player doing %player.client.getname(), getClassName(%player) etc. etc.

I got it checking for my player, but it doesn't find it... the console tells me that it's searching with my echo check, but it can't echo my player's ID. I don't really understand this at all.. it'll echo brick IDs and stuff

I got it checking for my player, but it doesn't find it... the console tells me that it's searching with my echo check, but it can't echo my player's ID. I don't really understand this at all.. it'll echo brick IDs and stuff
your %mask is looking at the wrong type. you probably have it set to find brick objects, not player objects

also whoops i guess i misread you - you were bolding a lot of posts and repeating the question over and over so i misinterpreted you as getting annoyed/angry.

also there was no point in splitting off to a new post - don't EVER "delete" old posts/remove significant amounts of text from them, or make a new topic because the old one was getting off topic. It just clogs up the topic list.
« Last Edit: February 26, 2016, 03:29:32 PM by Conan »

your %mask is looking at the wrong type. you probably have it set to find brick objects, not player objects

also whoops i guess i misread you - you were bolding a lot of posts and repeating the question over and over so i kinda misinterpreted you as getting annoyed/angry.

Actually I didn't.. I had the mask set right, but I somehow managed to workaround. I changed the code and found this works:

Code: [Select]
if(isObject(%BID))
{
echo("RADIUSSEARCHING");
%player = findClientByName("Bricktronic").player; //Find player
%position = %player.getPosition(); //Get his position
%radius = 10; //Specify a radius to search
%mask = $TypeMasks::PlayerObjectType; //Use a typemask
initContainerRadiusSearch(%position, %radius, %mask); //Start radius search
%object = containerSearchNext(); //search for the object
echo(%object.getID());
}

Actually I didn't.. I had the mask set right, but I somehow managed to workaround. I changed the code and found this works:

Code: [Select]
if(isObject(%BID))
{
echo("RADIUSSEARCHING");
%player = findClientByName("Bricktronic").player; //Find player
%position = %player.getPosition(); //Get his position
%radius = 10; //Specify a radius to search
%mask = $TypeMasks::PlayerObjectType; //Use a typemask
initContainerRadiusSearch(%position, %radius, %mask); //Start radius search
%object = containerSearchNext(); //search for the object
echo(%object.getID());
}
the objects its echoing ARE player object ID's...? Why do you think they are brick id's?
All objects are given a number ID, whether they are players, vehicles, projectiles, scriptobjects, etc etc. You can check the type of said object by calling [objectID].getType() (which is the equivalent of calling %object.getType() in your code)

didn't see that you said this works, oops.

If you are looking for the BLID of the client that the player object is associated with, you have to do %object.client, in this case. I don't see how this is a workaround in any way, but okay.
« Last Edit: February 26, 2016, 03:35:35 PM by Conan »

the objects its echoing ARE player object ID's...? Why do you think they are brick id's?
All objects are given a number ID, whether they are players, vehicles, projectiles, scriptobjects, etc etc. You can check the type of said object by calling [objectID].getType() (which is the equivalent of calling %object.getType() in your code)

If you are looking for the BLID of the client that the player object is associated with, you have to do %object.client, in this case. I don't see how this is a workaround in any way, but okay.

I meant that it would return brick IDs IF I had it set to the brick's mask type. I had to change the code to get it to finally somehow even detect the player, but it works and I'm happy with it lol.

You need to also include the while loop.

You need to also include the while loop.

Nope, I got a tick running with schedule

Nope, I got a tick running with schedule
every time the tick goes around you will only ever affect one player at most though. is that intentional?

Nope, I got a tick running with schedule
Okay, let's clarify something here if that's what I understand.

You're making a tick loop that's doing initContainerRadiusSearch everytime it does it, but it's only able to find 1 object.. That's pretty unstable. You'll get some random object but you won't get everyone that's inside, you'll only get an object. I'd recommend doing a while(isObject(%target = containerSearchNext()))

Make sure the loop doesn't go too fast and make sure you use a variable for setting the schedule so you don't get multiple schedules running.
Don't do 1 millisecond or less for the schedule unless you know what you're doing

Example of a schedule code on a variable that can be stopped
Code: [Select]
function someLoop()
{
cancel($someLoop);

echo("loop de loop!");

$someLoop = schedule(3000, 0, "someLoop");
}