Jump to content

Gui issue at keypad


icarus

Recommended Posts

At GUI tutorial 2, i edited it so it could say higher/lower , but doesnt work, dont know what is wrong, can someone help me.

de Debug script 3 output is this : ERROR:server.lua:13: attempt to compare nil with string

  
local keypadCodes = { 
    ["a51MainGateKeypadCode"] = math.random (0, 50000) 
} 
addEvent("verifyKeypadCode",true) 
addEventHandler("verifyKeypadCode",root,function(code,keypadID) 
    if code then 
  
        if code == keypadCodes[keypadID] then 
  
            triggerClientEvent(client,"onKeypadVerificationSuccessful",client,keypadID) 
        elseif code >= keypadCodes[keypadID] then  
  
            triggerClientEvent(client,"oncodeishigher",client,keypadID) 
                elseif code <= keypadCodes[keypadID] then  
                         
                        triggerClientEvent(client,"oncodeislower",client,keypadID) 
        end 
    end 
end) 

Link to comment

you mean, like this ?

  
local keypadCodes = { 
    ["a51MainGateKeypadCode"] = math.random (0, 50000) 
} 
addEvent("verifyKeypadCode",true) 
addEventHandler("verifyKeypadCode",root,function(code,keypadID) 
    if code then 
  
        if code == tonumber(code) then 
  
            triggerClientEvent(client,"onKeypadVerificationSuccessful",client,keypadID) 
        elseif code >= tonumber(code) then  
  
            triggerClientEvent(client,"oncodeishigher",client,keypadID) 
                elseif code <= tonumber(code) then  
                         
                        triggerClientEvent(client,"oncodeislower",client,keypadID) 
        end 
    end 
end) 

Link to comment
 local keypadCodes = { 
    ["a51MainGateKeypadCode"] = math.random(0, 50000) 
} 
addEvent("verifyKeypadCode",true) 
addEventHandler("verifyKeypadCode",root,function(code,keypadID) 
     if tonumber(code) then 
          if tonumber(code) == keypadCodes[keypadID] then 
               triggerClientEvent(client,"onKeypadVerificationSuccessful",client,keypadID) 
          elseif tonumber(code) >= keypadCodes[keypadID] then 
               triggerClientEvent(client,"oncodeishigher",client,keypadID) 
          elseif tonumber(code) <= keypadCodes[keypadID] then 
               triggerClientEvent(client,"oncodeislower",client,keypadID) 
          end 
     end 
end) 

Link to comment

kk, client side is this, the problem is probably there, im new at scripting,so thats probably it.

local bankrob = createMarker ( 2655, 2706, 411, "arrow", 1, 100, 20, 20 ) 
function createKeypad() 
  
    local sWidth, sHeight = guiGetScreenSize() 
  
  
    local Width,Height = 142,276 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
    keypadWindow = guiCreateWindow(X,Y,Width,Height,"Keypad",false) 
  
    addEventHandler("onClientGUIClick",keypadWindow,processKeypadClicks,true) 
  
  
    guiWindowSetSizable(keypadWindow,false) 
  
  
    keypadButton1 = guiCreateButton(13,68,37,36,"1",false,keypadWindow) 
    keypadButton2 = guiCreateButton(53,68,37,36,"2",false,keypadWindow) 
    keypadButton3 = guiCreateButton(93,68,37,36,"3",false,keypadWindow) 
    keypadButton4 = guiCreateButton(13,108,37,36,"4",false,keypadWindow) 
    keypadButton5 = guiCreateButton(53,108,37,36,"5",false,keypadWindow) 
    keypadButton6 = guiCreateButton(93,108,37,36,"6",false,keypadWindow) 
    keypadButton7 = guiCreateButton(13,148,37,36,"7",false,keypadWindow) 
    keypadButton8 = guiCreateButton(53,148,37,36,"8",false,keypadWindow) 
    keypadButton9 = guiCreateButton(93,148,37,36,"9",false,keypadWindow) 
    keypadButtonAsterix = guiCreateButton(13,188,37,36,"*",false,keypadWindow) 
    keypadButton0 = guiCreateButton(53,188,37,36,"0",false,keypadWindow) 
    keypadButtonHash = guiCreateButton(93,188,37,36,"#",false,keypadWindow) 
    keypadButtonExit = guiCreateButton(13,228,37,36,"Exit",false,keypadWindow) 
    keypadButtonEnter = guiCreateButton(53,228,37,36,"Enter",false,keypadWindow) 
    keypadButtonClear = guiCreateButton(93,228,37,36,"Clear",false,keypadWindow) 
  
  
    keypadGridlistDisplay = guiCreateGridList(13,25,117,33,false,keypadWindow) 
    guiGridListSetSelectionMode(keypadGridlistDisplay,2) 
    guiSetAlpha(keypadGridlistDisplay,0.6) 
  
    keypadLabelDisplay = guiCreateLabel(14,26,115,30,"Enter Keycode.",false,keypadWindow) 
    guiLabelSetColor(keypadLabelDisplay,255,000,000) 
    guiLabelSetVerticalAlign(keypadLabelDisplay,"center") 
    guiLabelSetHorizontalAlign(keypadLabelDisplay,"center",false) 
  
    guiSetVisible(keypadWindow,false) 
end 
  
  
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),createKeypad) 
  
function updateDisplay(text) 
  
    if text then 
  
        if tonumber(text) or text == "*" or text == "#" then 
            guiSetText(keypadLabelDisplay,guiGetText(keypadLabelDisplay) .. text) 
  
        else 
            guiSetText(keypadLabelDisplay,text) 
        end  
  
    else 
        guiSetText(keypadLabelDisplay,"") 
    end 
end 
  
function processKeypadClicks(button,state) 
    if button == "left" and state == "up" then 
  
        if getElementType(source) == "gui-button" then 
  
            triggerEvent("onKeypadButtonClicked",source,getElementData(keypadWindow,"keypadID")) 
        end 
    end 
end 
  
addEvent("onKeypadButtonClicked",false) 
addEventHandler("onKeypadButtonClicked",root, 
    function(keypadID) 
  
        if guiGetText(keypadLabelDisplay) == "Enter Keycode." or guiGetText(keypadLabelDisplay) == "Lower" or guiGetText(keypadLabelDisplay) == "Higher" then 
            updateDisplay() 
        end 
  
  
  
        if guiGetText(source) == "Clear" then 
  
            updateDisplay() 
  
  
        elseif guiGetText(source) == "Enter" then 
  
            local code = guiGetText(keypadLabelDisplay) 
  
  
            if code then 
  
                triggerServerEvent("verifyKeypadCode",getLocalPlayer(),code,keypadID) 
            end 
  
  
        elseif guiGetText(source) == "Exit" then 
  
            guiSetVisible(keypadWindow,false) 
            updateDisplay("Enter Keycode.") 
            showCursor(false,false) 
  
  
        else 
            updateDisplay(guiGetText(source))    
        end 
    end 
) 
  
addEvent("onKeypadVerificationSuccessful",true) 
addEventHandler("onKeypadVerificationSuccessful",root, 
    function() 
  
        guiSetVisible(keypadWindow,false) 
        updateDisplay("Enter Keycode.") 
        showCursor(false,false) 
    end 
) 
  
addEvent("oncodeishigher",true) 
addEventHandler("oncodeishigher",root, 
    function() 
  
        updateDisplay("Higher") 
    end 
) 
  
addEvent("oncodeislower",true) 
addEventHandler("oncodeislower",root, 
    function() 
  
        updateDisplay("Lower") 
    end 
) 
  

Link to comment

i don't see where you set the element data here

triggerEvent("onKeypadButtonClicked",source,getElementData(keypadWindow,"keypadID")) 

the element data must be "a51MainGateKeypadCode"

and i still don't understand why you need the table here

local keypadCodes = { 
    ["a51MainGateKeypadCode"] = math.random(0, 50000) 
} 

you can just do

addEvent("verifyKeypadCode",true) 
addEventHandler("verifyKeypadCode",root,function(code) 
     local keypadCodes = math.random(0, 50000) 
     if tonumber(code) then 
          if tonumber(code) == keypadCodes then 
               triggerClientEvent(client,"onKeypadVerificationSuccessful",client) 
          elseif tonumber(code) >= keypadCodes then 
               triggerClientEvent(client,"oncodeishigher",client) 
          elseif tonumber(code) <= keypadCodes then 
               triggerClientEvent(client,"oncodeislower",client) 
          end 
     end 
end) 

Link to comment

Sorry to bother again.

What i wanna do is make is add a new gui that is almost equal to the other , but the difference is that i want to change they keypad window name to other that opens when i hit another marker, and updates other trigger vent, and the code is different.

I tried doing it , but the results are almost everytime the same, like the display of the first gui shows in the second, the code is the same at the 2 guis. The Guis confuse themselves.

can you help me, what do i need to add to the version i uploaded here client/server side , in order to make it work and simple.

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