function onPlayerJoin()
bindKey (source, "o", "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( "Tempomat abgestellt!", player)
else
if(getElementSpeed(getPedOccupiedVehicle(player)) > 15) then
local tempo = getElementSpeed(getPedOccupiedVehicle(player), "kmh")
tempo = math.round(tempo)
outputChatBox( "Tempomat eingestellt! ("..tostring(tempo).." km/h)", player)
tempomat = setTimer ( setSpeed, 250, 0, player, tonumber(tempo) )
else
outputChatBox( "Du musst mind. 15 km/h schnell fahren!", player)
end
end
else outputChatBox( "Du bist in keinem Fahrzeug!", 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] Ungueltiges 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("Tempomat ausgestellt!", player) -- Bei Crashes, Bremsen, Gas geben etc.
else
setElementSpeed(getPedOccupiedVehicle(player),"kmh", speed)
end
else
outputChatBox("Tempomat ausgeschaltet!" ,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
Nein, keine langeweile. Ich habs nur selber gebraucht und wenn ich es schon mache dann kann ich es ja auch posten