Jump to content

[Help Night Vision]


iPanda

Recommended Posts

-

I want to create a resource that allows you to activate Night Vision by pressing the "n", provided that the player has Night vision goggles.

Here is my script, but it does not work for some reason. Throws an error that getPedWeapon - bad argument.

-- Night Vision Googles 
local nightvision = false 
  
local googleVision = function ( key, player ) 
  local googles = getPedWeapon ( player ) 
  if key == "n" then 
    if not ( googles == 44 ) then 
      nightvision = false 
      setCameraGoggleEffect("normal") 
    else 
      nightvision = true 
      setCameraGoggleEffect("nightvision") 
      setFarClipDistance(1000) 
    end 
  end 
end 
  
--  Resource start and key 
addEventHandler ( "onPlayerJoin",root, 
  function ( ) 
    bindKey ( source, "n", "down", googleVision ) 
  end 
) 
  
addEventHandler ( "onResourceStart", resourceRoot, 
  function ( ) 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
      bindKey ( player, "n", "down", googleVision ) 
    end 
  end 
) 

Link to comment

you are mixing client-side code with server-side code erroneusly.

client-side only!

  
   local nightvision = false; 
   addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), 
          function ()  
                   bindKey ("n", "down", 
                            function ()  
                                     if not ( googles == 44 ) then 
                                            nightvision = false 
                                            setCameraGoggleEffect("normal") 
                                     else 
                                            nightvision = true 
                                            setCameraGoggleEffect("nightvision") 
                                            setFarClipDistance(1000) 
                                     end; 
                            end);  
          end);  
  

Link to comment

-- Client Side --

bindKey("n", "down", 
function () 
    if getPedWeapon(localPlayer) == 44 then 
        if getCameraGoggleEffect() == "normal" then 
            setCameraGoggleEffect("nightvision") 
            setFarClipDistance(1000) 
        else 
            setCameraGoggleEffect("normal") 
        end 
    end 
end) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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