Check for closest player to you

hello, since there is many asking how , here is how


this will check if players is away from you around 100 meter or less , you can change it



Code:
{$CLEO}

0000: NOP


:START
wait 0 
IF AND
056D:   actor $PLAYER_ACTOR defined 
0AB0:   key_pressed 49 //key 1 to start the loop
then   
REPEAT
wait 0 
// GET ALL STREAMED PEDS     
0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
000A: 29@ += 0x4
0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
for 30@ = 0 to 35584 step 0x100
    0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
    000A: 29@ += 0x1
    if and
        0029:  31@ >= 0x00 
        001B:  0x80 > 31@
    then 
        005A: 31@ += 30@
        // GOT THE PED. 31@ = THE PLAYER (PED)
IF
056D:   actor 31@ defined     //check if the actor defined
then
//-----THIS IS OUR CHECKING-----\\
actor.StorePos($PLAYER_ACTOR, 1@ , 2@ , 3@) //store your position
actor.StorePos(31@, 4@ , 5@ , 6@)                   //store the target position

IF 
7@ < 100.0   // this will check if the target is less than 100 meter away from you ,float is better to use (.0)
then
//HERE YOU CAN ADD THINGS YOU WANT TO HAPPEN OR IF YOU HAVE MORE CONDITIONS



ELSE
IF 
7@ > 100.0  //this will check if the target is more than 100 meter away 
then 
// here put things that will run if the target is away more than 100 meter 



//----ends----\\
end
end
end
end
end
//----ends----\\
until key_down 48 // key 0  will stop the loop 
END
jump @START



for example:
Code:
{$CLEO}

0000: NOP


:START
wait 0 
if and
056D:   actor $PLAYER_ACTOR defined 
0AB0:   key_pressed 49 //key 1 to start the loop
then
REPEAT
wait 0 
// GET ALL STREAMED PEDS     
0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
000A: 29@ += 0x4
0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
for 30@ = 0 to 35584 step 0x100
    0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
    000A: 29@ += 0x1
    if and
        0029:  31@ >= 0x00 
        001B:  0x80 > 31@
    then 
        005A: 31@ += 30@
        // GOT THE PED. 31@ = THE PLAYER (PED)
if 
056D:   actor 31@ defined     //check if the actor defined
then
actor.StorePos($PLAYER_ACTOR, 1@ , 2@ , 3@) //store your position
actor.StorePos(31@, 4@ , 5@ , 6@)                   //store the target position
0509: 7@ = distance_between_XY 1@ 2@ and_XY 3@ 4@ //compare each position and store it in variable
if
7@ < 100.0   // this will check if the target is less than 100 meter away from you ,float is better to use (.0)
then
//HERE YOU CAN ADD THINGS YOU WANT TO HAPPEN OR IF YOU HAVE MORE CONDITIONS
0B2B: samp 0@ = get_player_id_by_actor_handle 31@   //this will get the id of the player
0AD1: show_formatted_text_highpriority "ACTOR %d IS NEAR YOU" time 1000 2@
else
if 
7@ > 100.0  //this will check if the target is more than 100 meter away 
then 
0AD1: show_formatted_text_highpriority "NO ACTOR IS NEAR YOU" time 1000 
end
end
end
end
end
until key_down 48 // key 0  will stop the loop 
END
jump @START
you may check http://ugbase.eu/snippets/for-all-peds/ to know how to get all streamed peds
 

wavelengthzero

Active member
Joined
Feb 18, 2014
Messages
45
Reaction score
0
It's not working for me. I tried SAMPFUNCS 5.2.1 to the new 5.3 and I get the same result:
Distance of 100: "No actor is near you"
Distance of 1000+: "Actor D is near you"

No number, just the letter D. I don't want the D tho, I want the ID, ffs. Halp?
 
Top