Jump to content

Uberschall Script PLEASE HELP :-(


Einheit-101

Recommended Posts

Hello Community, i am new in this Forum and i hope that you will help me better then the German Community :cry:

I have made this script with help from Wiki and codeparts from other resources. But it does not work. The script should check if a player is in a Hydra and play the sound "knall.mp3" if the Hydra is faster than 230 mph. Hope for help.

  
local vehSpeed = getVehicleSpeed() 
  
function planeEnter ( theVehicle, seat, jacked ) 
id = getElementModel ( theVehicle ) 
if id == 520 then 
    if (speed >= 230) then 
    local sound = playSound(files/knall.mp3) 
    setSoundVolume(sound, 1)  
    end 
end 
end 
addEventHandler ( "onClientVehicleEnter", getRootElement(), planeEnter ) 
  
  
  
function getVehicleSpeed() 
    if isPedInVehicle(source) then 
        local vx, vy, vz = getElementVelocity(getPedOccupiedVehicle(source)) 
        return math.sqrt(vx^2 + vy^2 + vz^2) * 161 
    end 
    return 0 
end 
addEventHandler ( "onClientVehicleEnter", getRootElement(), getVehicleSpeed )  
  

mfg Einheit

Link to comment
  
local localPlayer = getLocalPlayer ( ) 
local isSoundPlayed = false 
  
addEventHandler ( "onClientRender", getRootElement ( ), 
    function ( ) 
        if isPedInVehicle ( localPlayer ) and getVehicleType ( getPedOccupiedVehicle ( localPlayer ) ) == "Plane" then 
            if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then 
                local sound = playSound ( "files/knall.mp3" ) 
                isSoundPlayed = true 
                --You can add here some more stuff if you reached 230 KM/H. 
            else 
                if isSoundPlayed == true then isSoundPlayed = false end 
            end 
        end 
    end 
) 
  
function getVehicleSpeed ( vehicle ) 
    local vx, vy, vz = getElementVelocity ( vehicle ) 
    return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 
end 
  

I didnt test that, but it should work. Besides that, you script was totally wrong :P Too much to explain so early in the morning :P

Edited by Guest
Link to comment

!!!WOW!!! :shock:

RESPECT!! :!:

You have answered me! So you have done something the German Community has never done!

Thanks! I will test it now and try to learn from you, Remi-x.

@ varez

Maybe its not the best way, but i am lucky if it works anyway and i dont like so much "gefuschels" because it doesnt work if i make it :-D

Edit1:

What will happen if I delete the"IsSoundPlayed == true" or add a Timer which sets it to false again because i want the sound to play again when your plane is faster than 230 mph again.

Link to comment

if plane will slow down isSoundPlayed will be changed back to false - so if plane accelerate again to 230km/h - the sound will be played again. its all ok.

or maybe you mean to make sound loopped while speed > 230?

then do it in this way:

  
            if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then 
                sound = playSound ( "files/knall.mp3", true ) 
                isSoundPlayed=true 
            else 
                if isElement(sound) then 
                    stopSound(sound) 
                    isSoundPlayed = false 
                end 
            end 
  

Link to comment
!!!WOW!!! :shock:

RESPECT!! :!:

You have answered me! So you have done something the German Community has never done!

Thanks! I will test it now and try to learn from you, Remi-x.

:oops:

Edit1:

What will happen if I delete the"IsSoundPlayed == true" or add a Timer which sets it to false again because i want the sound to play again when your plane is faster than 230 mph again.

You don't need to do that, because that's already what I've made.

Explanation:

On the top of the script we got isSoundPlayer = false, this will mean when a player joins, he doesn't have to hear the sound.

After flying and get a speed higher than 230 units (Which we check here: getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 ), we are looking to that boolean again if it's still false: if (...) isSoundPlayed == false then

If it's still false, the script will be passed. There will the sound be played, and the boolean will be set to true, which means we played the sound. isSoundPlayed = true

If the player is flying less than 230 units, we would pass the "else" statement, and that will check if the boolean we used is set to true. If so, we set it to false.

And since this event is triggered everytime your game renders ( Amount of renders in 1 second = FPS, that may sound familiar ), we are checking your speed also enough times.

EDIT2: It plays the sound strange. If i am faster than 230 mph it make bööööööööööööö[...]öm until i am slower than 230 mph.

You should do what varez said, stopping the sound. I never worked with sounds, so that's the reason why I forgot that to place in the script I've made :P

And I'm bored at the moment, so here it is all ready:

  
local localPlayer = getLocalPlayer ( ) 
local isSoundPlayed = false 
local knallSound = nil --nil means literally "nothing", or "empty".  
  
addEventHandler ( "onClientRender", getRootElement ( ), 
    function ( ) 
        if isPedInVehicle ( localPlayer ) and getVehicleType ( getPedOccupiedVehicle ( localPlayer ) ) == "Plane" then 
            if getVehicleSpeed ( getPedOccupiedVehicle ( localPlayer ) ) >= 230 and isSoundPlayed == false then 
                knallSound = playSound ( "files/knall.mp3" ) 
                isSoundPlayed = true 
                --You can add here some more stuff if you reached 230 KM/H. 
            else 
                if isSoundPlayed == true and isElement ( knallSound ) then  
                    isSoundPlayed = false 
                    stopSound ( knallSound ) 
                end 
            end 
        end 
    end 
) 
  
function getVehicleSpeed ( vehicle ) 
    local vx, vy, vz = getElementVelocity ( vehicle ) 
    return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 
end 
  

Should really give no problems.

@ varez below: solved.

Edited by Guest
Link to comment

tested, working.. hydra is a bit noisy vehicle so its hard to hear that sound, but script is working ;p

  
  
local pl = getLocalPlayer() 
  
local mycar = nil 
local t = nil 
  
addEventHandler("onClientPlayerVehicleEnter",pl, 
function(veh) 
  if getElementModel(veh) == 520 then 
    mycar = veh 
    if (not isTimer(t)) then 
      t = setTimer(check, 100, 0) 
    end 
  end 
end) 
addEventHandler("onClientPlayerVehicleExit",pl, 
function() 
  mycar = nil 
  if (isTimer(t)) then 
    killTimer(t) 
  end 
end) 
  
  
local above = false 
  
function check() 
  local speed = getVehicleSpeed(mycar) 
  if (not above and speed>225) then 
    --outputChatBox("b") 
    above = true 
    playSound ("file/knall.mp3") 
  elseif (above and speed<225) then 
    above = false 
  end 
end 
  
function getVehicleSpeed ( vehicle ) 
    local vx, vy, vz = getElementVelocity ( vehicle ) 
    return math.sqrt ( vx^2 + vy^2 + vz^2 ) * 161 
end 
  
  

Link to comment
  • 2 weeks later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...