Jump to content

Flashlight bind


dewu

Recommended Posts

Posted (edited)

I don't mean command.

I mean when i click ex. "B" button on the keyboard, flashlight will be turn on/off.

In this res first i must type /flashlight command to enable.

Edited by Guest
Posted
I don't mean command.

I mean when i click ex. "B" button on the keyboard, flashlight will be turn on/off.

In this script first i must type /flashlight command to enable.

You type in the chat box

/bind b flashlight

After this, when you click "b" the flashlight will turn on and off

Posted

I create MTA: DayZ Server.

I don't want to use it in single, but on my server where players to turn on/off light just must use a key without earlier binding.

Posted
I create MTA: DayZ Server.

I don't want to use it in single, but on my server where players to turn on/off light just must use a key without earlier binding.

I do not know if you know, but this feature causes lag

Posted

What are you talking about ReX?

Hes probably talking about bindKey.

@dewu: just use the functiom bindKey ,

example :

bindKey("b", "down", function) 

Just put this under your flashlight function and change "function" in the bindKey Event above to your functionname.

Sent from my phone.

Posted

Yes! It is that what i mean ;)

but, don't know why it's not working.

I've changed:

  
-- start or stop using flashlight 
function toggleFlashLight() 
if flashLiTable.flModel[getLocalPlayer()] then  
    outputChatBox('You have disabled the flashlight',0,255,0) 
    triggerServerEvent("onSwitchLight",getLocalPlayer(),false) 
    triggerServerEvent("onSwitchEffect",getLocalPlayer(),false) 
    isLightOn = false 
    unbindKey(switch_key,"down",toggleLight) 
else 
    outputChatBox('You have enabled the flashlight',0,255,0) 
    triggerServerEvent("onSwitchLight",getLocalPlayer(),false) 
    triggerServerEvent("onSwitchEffect",getLocalPlayer(),true) 
    bindKey(switch_key,"down",toggleLight) 
    end 
end 
  
--------------------------------------------------------------------------------------------------- 
         
addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()), function() 
    local ver = getVersion ().sortable 
    local build = string.sub( ver, 9, 13 ) 
    if build<"04938" or ver < "1.3.1" then  
        outputChatBox('The resource is not compatible with this client version!',255,0,0) 
        return 
    end 
    local isEffectValid 
    if (vCardPSVer()~="3") then  
        outputChatBox('Flashlight: Shader Model 3 not supported',255,0,0) 
        isFullShader = false 
        isEffectValid = createWorldLightShader(0) 
    else 
        isFullShader = true 
        isEffectValid = createWorldLightShader(2) 
    end 
    if not isEffectValid then  
        outputChatBox('Flashlight effect failed to start!',255,0,0)  
        return  
    else 
        outputChatBox('Shader flashlight test ver 1.06 has started.',255,255,0) 
    end 
    engineImportTXD( engineLoadTXD( "objects/flashlight.txd" ), objID )  
    engineReplaceModel ( engineLoadDFF( "objects/flashlight.dff", 0 ), objID,true) 
    triggerServerEvent("onPlayerStartRes",getLocalPlayer()) 
    if autoEnableFL then  
        toggleFlashLight()  
    else 
        outputChatBox('Type /flashlight to enable the flashlight ',255,255,0) 
    end 
    outputChatBox('Hit '..switch_key..' to turn on/off the flashlight',255,255,0) 
    addCommandHandler("flashlight",toggleFlashLight) 
end 
) 

to

  
-- start or stop using flashlight 
function toggleFlashLight() 
if flashLiTable.flModel[getLocalPlayer()] then  
    outputChatBox('You have disabled the flashlight',0,255,0) 
    triggerServerEvent("onSwitchLight",getLocalPlayer(),false) 
    triggerServerEvent("onSwitchEffect",getLocalPlayer(),false) 
    isLightOn = false 
    unbindKey("b","down",toggleLight) 
else 
    outputChatBox('You have enabled the flashlight',0,255,0) 
    triggerServerEvent("onSwitchLight",getLocalPlayer(),false) 
    triggerServerEvent("onSwitchEffect",getLocalPlayer(),true) 
    bindKey("b","down",toggleLight) 
    end 
end 
  
--------------------------------------------------------------------------------------------------- 
         
addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()), function() 
    local ver = getVersion ().sortable 
    local build = string.sub( ver, 9, 13 ) 
    if build<"04938" or ver < "1.3.1" then  
        outputChatBox('The resource is not compatible with this client version!',255,0,0) 
        return 
    end 
    local isEffectValid 
    if (vCardPSVer()~="3") then  
        outputChatBox('Flashlight: Shader Model 3 not supported',255,0,0) 
        isFullShader = false 
        isEffectValid = createWorldLightShader(0) 
    else 
        isFullShader = true 
        isEffectValid = createWorldLightShader(2) 
    end 
    if not isEffectValid then  
        outputChatBox('Flashlight effect failed to start!',255,0,0)  
        return  
    else 
        outputChatBox('Shader flashlight test ver 1.06 has started.',255,255,0) 
    end 
    engineImportTXD( engineLoadTXD( "objects/flashlight.txd" ), objID )  
    engineReplaceModel ( engineLoadDFF( "objects/flashlight.dff", 0 ), objID,true) 
    triggerServerEvent("onPlayerStartRes",getLocalPlayer()) 
    if autoEnableFL then  
        toggleFlashLight()  
    else 
        outputChatBox('Type /flashlight to enable the flashlight ',255,255,0) 
    end 
    outputChatBox('Hit '..switch_key..' to turn on/off the flashlight',255,255,0) 
end 
) 

Also I deleted line with addCommandHandler

Posted

try this :

bindKey("b","down",  toggLight) 

i dont know if toggleLight is used to switch it off also , but if it is youll need an if i think . Ex : if switched == on then

---

if switched == off then

--

Greets,

Sent from my Phone.

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...