SCamera: Difference between revisions
(Created page with "== sCamera == '''The function creates a speed camera in-game, fines speeding vehicles, and notifies the driver and take money from player based on vehicle speed. ''' == Syntax == <syntaxhighlight lang="lua"> function sCamera(modelId, x, y, z, speed, between) </syntaxhighlight> == Parameters == * modelId: The model ID of the camera object to be created. * x, y, z: The coordinates where the camera object will be placed in the game world. * speed: The speed limit tha...") |
mNo edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Useful Function}} | |||
<lowercasetitle/> | |||
__NOTOC__ | |||
This function creates a speed camera in-game, fines speeding vehicles, and notifies the driver and take money from player based on vehicle speed. | |||
== Syntax == | == Syntax == | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 48: | Line 51: | ||
fine = 2250 | fine = 2250 | ||
end | end | ||
takePlayerMoney(driver, fine) | takePlayerMoney(driver, fine) | ||
fadeCamera(driver, false, 0.4 , 255,255,255) | fadeCamera(driver, false, 0.4 , 255,255,255) | ||
Line 54: | Line 56: | ||
outputChatBox("You were caught speeding by a traffic enforcement camera! You've been fined $" .. fine .. ".", driver, 255, 0, 0) | outputChatBox("You were caught speeding by a traffic enforcement camera! You've been fined $" .. fine .. ".", driver, 255, 0, 0) | ||
end | end | ||
end | end | ||
end | end | ||
Line 74: | Line 75: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
By : [https://forum.multitheftauto.com/profile/52553-khaledx/ KhaledX] |
Latest revision as of 21:54, 26 November 2023
This function creates a speed camera in-game, fines speeding vehicles, and notifies the driver and take money from player based on vehicle speed.
Syntax
function sCamera(modelId, x, y, z, speed, between)
Parameters
- modelId: The model ID of the camera object to be created.
- x, y, z: The coordinates where the camera object will be placed in the game world.
- speed: The speed limit that vehicles should not exceed.
- between: The maximum distance from the camera at which a vehicle can be detected.
Description
The sCamera function creates a camera object at a specified location in the game world. It then sets up a timer to check the speed of all vehicles in the game every second. If a vehicle is found to be exceeding the defined speed limit and is within a certain distance from the camera, the driver of the vehicle is fined. The fine is calculated based on the vehicle’s speed, and a message is displayed to the driver informing them of the fine.
Code
The function creates a speed camera in-game, fines speeding vehicles, and notifies the driver and take money from player based on vehicle speed.
function sCamera(modelId, x, y, z, speed, between) local camera = createObject(modelId, x, y, z) local speedLimit = speed local speedCheckTimer = setTimer( function() local vehicles = getElementsByType("vehicle") for i, vehicle in ipairs(vehicles) do local vx, vy, vz = getElementVelocity(vehicle) local vehicleSpeed = (vx^2 + vy^2 + vz^2)^(0.5) * 180 local x1, y1, z1 = getElementPosition(vehicle) local x2, y2, z2 = getElementPosition(camera) local distance = getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) if vehicleSpeed > speedLimit and distance < between then local driver = getVehicleOccupant(vehicle, 0) if driver then local fine = 0 if vehicleSpeed <= 10 then fine = 150 elseif vehicleSpeed <= 20 then fine = 350 elseif vehicleSpeed <= 50 then fine = 1250 else fine = 2250 end takePlayerMoney(driver, fine) fadeCamera(driver, false, 0.4 , 255,255,255) setTimer(fadeCamera, 250, 1, driver, true, 1.0) outputChatBox("You were caught speeding by a traffic enforcement camera! You've been fined $" .. fine .. ".", driver, 255, 0, 0) end end end end, 1000, 0 ) end
Example Code
The function creates a speed camera in-game, fines speeding vehicles, and notifies the driver and take money from player based on vehicle speed.
-- Create a speed camera at coordinates (-710.23791503906, 688.37194824219, 17.034782409668) with a speed limit of 70 and a detection range of 15 units sCamera(1286, -710.23791503906, 688.37194824219, 17.034782409668, 70, 15)
By : KhaledX