chat_range = 100 -- Distancia
function engineSwitch ( )
if ( isPedInVehicle ( source ) ) then
local veh = getPedOccupiedVehicle ( source )
if ( getVehicleEngineState ( veh ) == true ) then
setVehicleEngineState ( veh, false )
local px, py, pz = getElementPosition ( source )
for _, v in ipairs ( getElementsByType ( "player" ) ) do
if isPlayerInRangeOfPoint ( v, px, py, pz, chat_range ) then
outputChatBox ( "*".. getPlayerName ( source ) .." ah apagado el Vehiculo.", v, 255, 40, 80 )
end
end
else
setVehicleEngineState ( veh, true )
local px, py, pz = getElementPosition ( source )
for _, v in ipairs ( getElementsByType ( "player" ) ) do
if isPlayerInRangeOfPoint ( v, px, py, pz, chat_range ) then
outputChatBox ( "*".. getPlayerName ( source ) .." ah encendido el Vehiculo.", v, 255, 40, 80 )
end
end
end
else
outputChatBox ("You aren't in a vehicle!", source, 255, 0, 0)
end
end
addEvent ( "engenieSwitch",true )
addEventHandler ( "engenieSwitch", getRootElement(), engineSwitch )
function isPlayerInRangeOfPoint(player,x,y,z,range)
local px,py,pz=getElementPosition(player)
return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5 <= range
end