Check for closest player to you

was this tutorial useful to you?

  • Yes.

    Votes: 7 58.3%
  • No.

    Votes: 3 25.0%
  • Kinda.

    Votes: 2 16.7%

  • Total voters
    12

blackHat

Well-Known Member
Joined
Jul 28, 2013
Messages
931
Likes
0
Points
66
#1
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: [email protected] = read_memory 0xB74490 size 4 virtual_protect 0
000A: [email protected] += 0x4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
for [email protected] = 0 to 35584 step 0x100
    0A8D: [email protected] = read_memory [email protected] size 1 virtual_protect 0
    000A: [email protected] += 0x1
    if and
        0029:  [email protected] >= 0x00 
        001B:  0x80 > [email protected]
    then 
        005A: [email protected] += [email protected]
        // GOT THE PED. [email protected] = THE PLAYER (PED)
IF
056D:   actor [email protected] defined     //check if the actor defined
then
//-----THIS IS OUR CHECKING-----\\
actor.StorePos($PLAYER_ACTOR, [email protected] , [email protected] , [email protected]) //store your position
actor.StorePos([email protected], [email protected] , [email protected] , [email protected])                   //store the target position

IF 
[email protected] < 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 
[email protected] > 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: [email protected] = read_memory 0xB74490 size 4 virtual_protect 0
000A: [email protected] += 0x4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
for [email protected] = 0 to 35584 step 0x100
    0A8D: [email protected] = read_memory [email protected] size 1 virtual_protect 0
    000A: [email protected] += 0x1
    if and
        0029:  [email protected] >= 0x00 
        001B:  0x80 > [email protected]
    then 
        005A: [email protected] += [email protected]
        // GOT THE PED. [email protected] = THE PLAYER (PED)
if 
056D:   actor [email protected] defined     //check if the actor defined
then
actor.StorePos($PLAYER_ACTOR, [email protected] , [email protected] , [email protected]) //store your position
actor.StorePos([email protected], [email protected] , [email protected] , [email protected])                   //store the target position
0509: [email protected] = distance_between_XY [email protected] [email protected] and_XY [email protected] [email protected] //compare each position and store it in variable
if
[email protected] < 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 [email protected] = get_player_id_by_actor_handle [email protected]   //this will get the id of the player
0AD1: show_formatted_text_highpriority "ACTOR %d IS NEAR YOU" time 1000 [email protected]
else
if 
[email protected] > 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

Well-Known Member
Joined
Feb 18, 2014
Messages
45
Likes
0
Points
6
5
#2
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