Jump to content

Disable "F1" Key for Source Player


Zuher Laith

Recommended Posts

Set some data on the player using setElementData. As long as the player is in jail ( by checking the data ), add a "return" to your executing command.

Let's say we set some data on the player his butt;

setElementData ( thePlayer, "isJailed", true ); 

Now, we'll take a look at the f1 and f2 functions. Let's say that we take f1 and f1 is bound to function Support, all you have to do is add a return statement at the first line of the function;

if ( getElementData ( thePlayer, "isJailed" ) ) then return end 

This'll turn off the functions for him even when the player is using commands to avoid the bound button.

Link to comment

@tosfera

Hold on please ..

In the Second Part , You meant The Other Mod's Right ?

So i Tried it .. here is the Code:

xBindFunction_ = function () 
    if ( getElementData ( thePlayer, "isJailed" ) ) then return end 
    guiSetVisible(Project.Background ,not guiGetVisible(Project.Background)); 
    showCursor(guiGetVisible(Project.Background)); 
end 
bindKey(Key,"down",xBindFunction_); 

Doesn't work.

Link to comment
Use onClientKey and if the button is "F1" or "F2" then cancelEvent.

In that function you could check if the player is in jail aswell.

Here is what i tried (Server Side) ..:

addEventHandler( "onClientKey", root, function(button,press)  
        if button == "F1" then 
        cancelEvent () 
        outputChatBox("** You Can't Use The F1 ! ",root,255,0,0,true) 
            return true 
        end 
        return false 
        end ) 

Link to comment
Didn't you see the red text in the right up corner in wiki ? It is "Clientside event".

Also you need to check which resource sets that data (if the player is jailed or not) and then to use it.

I'am really Confused ..

Server Side:

setElementData(thePlayer,"isJailed",true) 

Client Side:

--------------------- 
--Key to open panel 
--------------------- 
  
open = false 
bindKey ( key, "down", 
function ( ) 
if ( getElementData ( thePlayer, "isJailed", "true" ) ) then  
addEventHandler( "onClientKey", root, function(button,press) 
    if button == "F1" then 
        cancelEvent () 
        outputChatBox("** You Can't Use The F1 ! ",root,255,0,0,true) 
        return true 
    end 
return false 
elseif ( getElementData ( thePlayer, "isJailed", "false" ) ) then 
    local vehicle = getPedOccupiedVehicle (getLocalPlayer()) 
if ( vehicle ) then 
    local allowedVehicles = { [ 490 ] = true, [ 597 ] = true, [ 596 ] = true, [ 598 ] = true, [ 470 ] = true, [ 523 ] = true, [ 528 ] = true, [ 427 ] = true}; 
    if ( allowedVehicles [ getElementModel ( vehicle ) ] ) then 
       if open == false then 
        add() 
    for k,v in ipairs(mywind) do 
     guiSetVisible(v,true) 
     guiSetAlpha(mywind[13],0.89999997615814) 
    end 
    showCursor(true) 
    open = true 
    else 
    close() 
    guiSetAlpha(mywind[13],0) 
        end 
        end 
    end 
        outputChatBox("** You Can Use The F1 ! ",root,255,0,0,true) 
end ) 
end 
  
  
end 
) 

Link to comment
I suggest start learning LUA from the start and not from a view of something you want to make.

Learn LUA stepwise, Datatypes, If, Else, For, Array's after studying this LUA becomes a whole easier.

I am a Pro at 3 Programming Languages , So LUA Would not be So Unrecognized to me.

I would not think that You Said that because my last Code make's a problem right ?

Link to comment

For every bind do an element data check so you can disable it whenever you want to for any player

e.g

bindKey(getRandomPlayer(),"F1","down", 
function(player) 
    if getElementData(player,"F1") ~= true then 
        -- 
    end 
end 
) 
  
setElementData(getRandomPlayer(),"F1",true) -- To disable F1 
setElementData(getRandomPlayer(),"F1",nil) -- To enable F1 (even false gonna work but it's better to delete it using nil) 

Link to comment
I suggest start learning LUA from the start and not from a view of something you want to make.

Learn LUA stepwise, Datatypes, If, Else, For, Array's after studying this LUA becomes a whole easier.

I am a Pro at 3 Programming Languages , So LUA Would not be So Unrecognized to me.

I would not think that You Said that because my last Code make's a problem right ?

Okay nevermind then, it just looked like you really were starting from scratch. Just out of interest, which languages?

Link to comment

Maybe something like this?

addEventHandler( "onClientKey", root, 
    function(button,press) 
        if button == "F1" and getElementData ( thePlayer, "isJailed" ) then 
            cancelEvent () 
            outputChatBox("** You Can't Use The F1 ! ",root,255,0,0,true) 
        end 
    end 
) 

Link to comment

Cancelling a custom event isn't going to do any good. The only thing that has been cancelled with your script @Army@1 is the button's function. But if you bound the button yourself, it'll most likely still bug out and work.

@ALw7sH's script is the way to go, sorry that I've been so slow in sending you a reply but his script is going to work. Since you've used custom events, you can't just cancel them without going into the custom made things. You said you're pro at 3 programming languages, I don't believe that. The way you're writing your code lacks all the hints towards a real programmer.

For example; Coding styles, lack of common sense, getting stuck at simple things, messing up some copy paste things. Every language is the same as in logic, you just need to learn the syntax.

Link to comment
For every bind do an element data check so you can disable it whenever you want to for any player

e.g

bindKey(getRandomPlayer(),"F1","down", 
function(player) 
    if getElementData(player,"F1") ~= true then 
        -- 
    end 
end 
) 
  
setElementData(getRandomPlayer(),"F1",true) -- To disable F1 
setElementData(getRandomPlayer(),"F1",nil) -- To enable F1 (even false gonna work but it's better to delete it using nil) 

Here is My Edit's :

xBindFunction_ = function () 
--function(player) 
    if getElementData("F10") ~= true then 
        outputChatBox("** You Can't Use The F10 ! ", root, 255, 0, 0, true) 
    else 
        guiSetVisible(GiveAdmin.Background ,not guiGetVisible(GiveAdmin.Background)); 
        showCursor(guiGetVisible(GiveAdmin.Background)); 
    end 
end 
bindKey(Key,"down",xBindFunction_); 

And On Player Is in Prison , then i Set:

setElementData(getRandomPlayer(),"F10",true) 

Same for unJail Func:

setElementData(getRandomPlayer(),"F10",nil) 

I'am shore that the Error is in "xBindFunction_" Function ..

am i missing something there ?

Edited by Guest
Link to comment
Maybe something like this?
addEventHandler( "onClientKey", root, 
    function(button,press) 
        if button == "F1" and getElementData ( thePlayer, "isJailed" ) then 
            cancelEvent () 
            outputChatBox("** You Can't Use The F1 ! ",root,255,0,0,true) 
        end 
    end 
) 

Might be not what i'am talking about My friend.

What i meant that If Player IsJailed, Then On Bindkey Function, Will Check if The Player is Jailed Using "SetElementData" & Will outputChatBox Message Say's "You Can't Use F1" , & Else will show the GUI Normally.

Link to comment

What i tried Currently ..:

xBindFunction_ = function () 
--function(player) 
    if getElementData("F10") ~= true then 
        --canelEvent() 
    elseif getElementData("F10") ~= false then 
        guiSetVisible(GiveAdmin.Background ,not guiGetVisible(GiveAdmin.Background)); 
        showCursor(guiGetVisible(GiveAdmin.Background)); 
    end 
         
     
end 
bindKey(Key,"down",xBindFunction_); 

Doesn't Work .. What's the problem ?

any help please ? ..

Link to comment
What i tried Currently ..:
xBindFunction_ = function () 
--function(player) 
    if getElementData("F10") ~= true then 
        --canelEvent() 
    elseif getElementData("F10") ~= false then 
        guiSetVisible(GiveAdmin.Background ,not guiGetVisible(GiveAdmin.Background)); 
        showCursor(guiGetVisible(GiveAdmin.Background)); 
    end 
         
     
end 
bindKey(Key,"down",xBindFunction_); 

Doesn't Work .. What's the problem ?

any help please ? ..

Check the wiki for every function you'll use it and you haven't used it before

because you're missing some arguments

to know the errors write in F8 "debugscript 3"

xBindFunction_ = function () 
--function(player) 
    if getElementData(localPlayer,"F10") ~= true then 
        guiSetVisible(GiveAdmin.Background ,not guiGetVisible(GiveAdmin.Background)); 
        showCursor(guiGetVisible(GiveAdmin.Background)); 
    else 
       -- if F10 blocked  
    end 
         
     
end 
bindKey(Key,"down",xBindFunction_); 

Link to comment

@ALw7sH

Thanks for the Idea ..

After Some editing .. it Seem's this is the Right Solution:

in unJail Func:

setElementData(thePlayer,"F10",false) 

in Jail Func:

setElementData(thePlayer,"F10",true) 

in Bind The Window Func:

xBindFunction_ = function () 
    if getElementData(localPlayer,"F10") ~= false then 
        -- If F10 Was Blocked 
        outputChatBox("لا يمكنك استخدام اللوحة", source, 251, 100, 0) 
    elseif getElementData(localPlayer,"F10") ~= true then 
        -- If F10 Wasn't Blocked 
        guiSetVisible(GiveAdmin.Background ,not guiGetVisible(GiveAdmin.Background)); 
        showCursor(guiGetVisible(GiveAdmin.Background)); 
    end 
        
    
end 
bindKey(Key,"down",xBindFunction_); 

Problem Solved.

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