Hey leute ich hab ein Problem undzwar :
Wenn ich bei meinem Tempomat einmal C drücke
dann kommt zweimal die Nachricht : Speedometer turned on!
SCRIPT
Lua
function onPlayerJoin()
bindKey(source, "c", "down", cmd_tempomat)
end
addEventHandler("onPlayerJoin", root, onPlayerJoin)
function cmd_tempomat(player, command)
if(isPedInVehicle(player)) then
if(isTimer(tempomat)) then -- Tempomat wurde bereits eingestellt
killTimer(tempomat)
outputChatBox( "Speedometer turned off!", player)
else
if(getElementSpeed(getPedOccupiedVehicle(player)) > 15) then
local tempo = getElementSpeed(getPedOccupiedVehicle(player), "kmh")
tempo = math.round(tempo)
outputChatBox( "Speedometer turned on! ("..tostring(tempo).." km/h)", player)
tempomat = setTimer ( setSpeed, 250, 0, player, tonumber(tempo) )
else
outputChatBox( "You have to be at least 15 km/h fast!!", player)
end
end
else outputChatBox( "You are not in a Car!!", player) end
end
addCommandHandler("tempomat", cmd_tempomat)
function setElementSpeed(element, unit, speed)
if (unit == nil) then unit = 0 end
if (speed == nil) then speed = 0 end
speed = tonumber(speed)
local acSpeed = getElementSpeed(element, unit)
if (acSpeed~=false) then
local diff = speed/acSpeed
local x,y,z = getElementVelocity(element)
setElementVelocity(element,x*diff,y*diff,z*diff)
return true
end
return false
end
function getElementSpeed(element,unit)
if (unit == nil) then unit = 0 end
if (isElement(element)) then
local x,y,z = getElementVelocity(element)
if (unit=="mph" or unit==1 or unit =='1') then
return (x^2 + y^2 + z^2) ^ 0.5 * 100
else
return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100
end
else
outputDebugString("[getElementSpeed] No Element")
return false
end
end
function setSpeed(player, speed)
if(isPedInVehicle(player)) then
if((getElementSpeed(getPedOccupiedVehicle(player),"kmh") < tonumber(speed)-15) or (getElementSpeed(getPedOccupiedVehicle(player),"kmh") > tonumber(speed)+4)) then
killTimer(tempomat)
outputChatBox("Speedometer turned off!", player) -- Bei Crashes, Bremsen, Gas geben etc.
else
setElementSpeed(getPedOccupiedVehicle(player),"kmh", speed)
end
else
outputChatBox("Speedometer turned off!!" ,player)
killTimer(tempomat)
end
end
function math.round(number, decimals, method)
decimals = decimals or 0
local factor = 10 ^ decimals
if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
else return tonumber(("%."..decimals.."f"):format(number)) end
end
Alles anzeigen