The online racing simulator
[Solved] Get NickName of Player close to me
Hi There,

Can you guys help me with by code below.

I'm trying to get NickName/username of player close to me,I dont know what I am doing wrong.
When l do this :


CatchEvent OnLapperStart()
OnLapperStart_Ctrack();
EndCatchEvent


CatchEvent OnMSO( $userName, $text ) # Player event

$idxOfFirtsSpace = indexOf( $text, " ");
IF( $idxOfFirtsSpace == -1 ) THEN
$command = $text;
$argv = "";
ELSE
$command = subStr( $text,0,$idxOfFirtsSpace );
$argv = trim( subStr( $text,$idxOfFirtsSpace ) );
ENDIF

SWITCH( $command )

CASE "!t":
$players = GetListOfPlayers("U");

FOREACH($play IN $players)
$distance = trackuserdistance($play,$userName);

IF ($distance <=5)
THEN
globalMsg("^6Twin ".GetCurrentPlayerVar("NickName")."^6 and ".GetPlayerVar($play,"NickName"));
ELSE
privMsg("No nearby Cars");
ENDIF
ENDFOREACH

BREAK;
ENDSWITCH
EndCatchEvent

I get Current user/player nickname but not the other player and even if the distance between the players is not less than 5 the code in globalMsg still execute.

Thank you.
** Best answer **
Hello, I copied your code and tried to load it, but it threw several errors in the Lapper logfile.

After making some adjustments, this is working as far as I can tell.
I left my debug code in the script,


<?php 
/*
CatchEvent OnLapperStart()
    OnLapperStart_Ctrack();
EndCatchEvent
*/

CatchEvent OnMSO$userName$text # Player event
     
$idxOfFirtsSpace indexOf$text" ");
    IF( 
$idxOfFirtsSpace == -THEN
      $command 
$text;
      
$argv "";
    ELSE
      
$command subStr$text,0,$idxOfFirtsSpace );
      
$argv trimsubStr$text,$idxOfFirtsSpace ) );
    ENDIF

    SWITCH( 
$command )

        CASE 
"!dist":
            
check_player_distance();
            BREAK;
    ENDSWITCH
EndCatchEvent

Sub check_player_distance
()
    
$players GetListOfPlayers("U");
    
dumpvar($players); #DEBUG
    
    
FOREACH( $var IN $players )
        
$distance trackuserdistanceGetCurrentPlayerVar "UserName" ),$var["value" ] );
        
writeline "DEBUG: "$distance );

        IF ( 
$distance <=)
        
THEN
          globalMsg 
"^6Twin " GetCurrentPlayerVar "NickName" ) . "^6 and " GetPlayerVar $var["value"],"NickName") );
        ELSE
          
privMsg "No nearby Cars" );
        ENDIF
    ENDFOREACH
EndSub
?>


Hi There,

Thank you very much for your help,its working.

Your code was getting distance between me and me not other player so l added "$players != $userName;" and now its working perfect.

Thank you again Smile
This thread is closed

FGED GREDG RDFGDR GSFDG