The online racing simulator
[Request] Can someone make me a speed radar plugin and only for cops
I've tried some tries and couldn't make it, can someone help?
Start by showing what you have made and what issues you ran into.
Alright
I made a speed radar with AI for a cruise server, tho it does not work, no errors in chat. Sending code
<?php
# LFSLapper Script for Speed Radar (Only for Cops)

# List of usernames that should work for the radar
$CopUsernames = array("CopUser1", "CopUser2", "CopUser3");

Event OnInterval(1000) # Check every second
$Players = GetListOfPlayers();
foreach($Players as $Player) {
$UserName = GetCurrentPlayerVar("UserName", $Player);
$Speed = GetCurrentPlayerVar("Speed", $Player);
$Heading = GetCurrentPlayerVar("Heading", $Player);
$Distance = GetCurrentPlayerVar("Distance", $Player);

# Check if the player is a cop
$IsCop = in_array($UserName, $CopUsernames);

if($IsCop) {
# Check if there's a car in front within a certain distance (e.g., 50 meters)
$CarInFront = false;
foreach($Players as $OtherPlayer) {
if($Player != $OtherPlayer) {
$OtherDistance = GetCurrentPlayerVar("Distance", $OtherPlayer);
$OtherHeading = GetCurrentPlayerVar("Heading", $OtherPlayer);

if($OtherDistance < 50 && abs($Heading - $OtherHeading) < 10) { # Adjust distance and heading tolerance as needed
$CarInFront = true;
$OtherSpeed = GetCurrentPlayerVar("Speed", $OtherPlayer);
break;
}
}
}

if($CarInFront) {
if($OtherSpeed > 100) { # Speed limit (adjust as needed)
btnCreate("^1Speed Radar", 5, 5, 50, 10, 1, "^1Speeding car detected at " . $OtherSpeed . " km/h!");
} else {
btnCreate("^1Speed Radar", 5, 5, 50, 10, 1, "^2Car in front is within speed limit.");
}
} else {
btnCreate("^1Speed Radar", 5, 5, 50, 10, 1, "^2No car in front.");
}
}
}
EndEvent
?>

No errors in chat doesn't say much.
What is the Lapper error log showing you?
Sorry for late reply, I'm not sure where to find Lapper error log
Logfile can be found in: [your path to Lapper]\bin\default\logs
Then you need to look at this file: [an IP address]-[port nbr]-ERR.log
In Logfile
8/23/2024 9:36:25 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:37:44 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:38:56 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:40:04 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:40:54 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:41:09 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:43:56 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:45:05 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174
8/23/2024 9:50:44 PM -> Var not defined on file: ".\default\LFSLapper.lpr" at line #174

In LFSLapper.lpr at line 174
$StoreOfflineData = 0; #storedvalue.dbs Store Offline data , even when the player doesnt exist in the database.

Quote from buntidondo :Can you see the image? because i cant

Why on earth would you link an image from Discord, while you can upload files here?
Made a screenshot of the image and have uploaded it here, so this whole thread will still make sense in the future.

Logfile is very clear and says there is an undefined variable in line 174 of file 'LFSLapper.lpr' so you might want to start looking at that particular line to see what is going on.
Attached images
Screenshot 2024-08-29 235716.png
buntidondo didnt take any effort to look into any LFSLapper scripts, on how the scripts are build.

I dont think LFSLapper will spit any errors or maybe one error.
and it stops the script at Event OnInterval(1000) # Check every second

@buntidondo
It seems you took some insim.net code and trying to convert it into a LFSLapper script, And this goes very wrong.
I suggest to open some LFSLapper and look how the syntaxes looks likes.

For 1 sec loops : https://www.lfs.net/forum/post/1927015#post1927015
  • -Wrong Array Syntax
  • -In_Array does not exist in LFSLapper, use InArray() instead.
  • -LFSLapper Scripts do not use brackets '{' '}'
  • -Event OnInterval(1000) # Check every second Does not exist in LFSLapper.

  • -foreach($Players as $Player) wrong syntax:
    foreach($Player IN $Players)
    #your code
    EndForEach
  • https://www.lfs.net/forum/post/1305874#post1305874 Scroll down to splittoarray()
  • -GetCurrentPlayerVar() wrong order of parameters
  • -btnCreate() does not exist in LFSLapper. Full explaination here, thanks to Sinanju for creating this nice tutorial: https://www.lfs.net/forum/thre ... --includes-odd-shaped-but
  • Probably missed more.

Please come back when you read into some lfslapper scripts.

Topic Closed.
This thread is closed

FGED GREDG RDFGDR GSFDG