Jump to content

limit


Eshtiz

Recommended Posts

Hi, I'm trying to set a limit on 'wage' on guiCreateEdit

So I'm trying to set the limit to 0-1500 and nothing above but how?

-- RANKS/WAGES 
  
lRanks = { } 
tRanks = { } 
tRankWages = { } 
wRanks = nil 
bRanksSave, bRanksClose = nil 
  
function btEditRanks(button, state) 
    if (source==gButtonEditRanks) and (button=="left") and (state=="up") then 
        local factionType = tonumber(getElementData(theTeam, "type")) 
        lRanks = { } 
        tRanks = { } 
        tRankWages = { } 
         
        guiSetInputEnabled(true) 
         
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then -- factions w/ wages 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
             
            wRanks = guiCreateWindow(x, y, width, height, "Ranks & Wages", false) 
             
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title & Wage: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.4, y, 0.3, 0.04, arrFactionRanks[i], true, wRanks) 
                tRankWages[i] = guiCreateEdit(0.775, y, 0.2, 0.04, tostring(arrFactionWages[i]), true, wRanks) 
                y = y + 0.05 
            end 
        else 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
             
            wRanks = guiCreateWindow(x, y, width, height, "Ranks", false) 
             
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.3, y, 0.6, 0.04, arrFactionRanks[i], true, wRanks) 
                y = y + 0.05 
            end 
        end 
         
        bRanksSave = guiCreateButton(0.05, 0.850, 0.9, 0.075, "Save!", true, wRanks) 
        bRanksClose = guiCreateButton(0.05, 0.940, 0.9, 0.075, "Close", true, wRanks) 
         
        addEventHandler("onClientGUIClick", bRanksSave, saveRanks, false) 
        addEventHandler("onClientGUIClick", bRanksClose, closeRanks, false) 
    end 
end 
  
function saveRanks(button, state) 
    if (source==bRanksSave) and (button=="left") and (state=="up") then 
        local found = false 
        local isNumber = true 
        for key, value in ipairs(tRanks) do 
            if (string.find(guiGetText(tRanks[key]), ";")) or (string.find(guiGetText(tRanks[key]), "'")) then 
                found = true 
            end 
        end 
         
        local factionType = tonumber(getElementData(theTeam, "type")) 
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
            for key, value in ipairs(tRankWages) do 
                if not (tostring(type(tonumber(guiGetText(tRankWages[key])))) == "number") then 
                    isNumber = false 
                end 
            end 
        end 
         
        if (found) then 
            outputChatBox("Your ranks contain invalid characters, please ensure it does not contain characters such as '@.;", 255, 0, 0) 
        elseif not (isNumber) then 
            outputChatBox("Your wages are not numbers, please ensure you entered a number and no currency symbol.", 255, 0, 0) 
        else 
            local sendRanks = { } 
            local sendWages = { } 
             
            for key, value in ipairs(tRanks) do 
                sendRanks[key] = guiGetText(tRanks[key]) 
            end 
             
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                for key, value in ipairs(tRankWages) do 
                    sendWages[key] = guiGetText(tRankWages[key]) 
                end 
            end 
             
            hideFactionMenu() 
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks, sendWages) 
            else 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks) 
            end 
        end 
    end 
end 
  
function closeRanks(button, state) 
    if (source==bRanksClose) and (button=="left") and (state=="up") then 
        if (wRanks) then 
            destroyElement(wRanks) 
            lRanks, tRanks, tRankWages, wRanks, bRanksSave, bRanksClose = nil, nil, nil, nil, nil, nil 
            guiSetInputEnabled(false) 
        end 
    end 
end 
  

-- // CALL BACKS FROM CLIENT GUI 
function callbackUpdateRanks(ranks, wages) 
    local theTeam = getPlayerTeam(client) 
    local factionID = getElementData(theTeam, "id") 
     
    for key, value in ipairs(ranks) do 
        ranks[key] = mysql:escape_string(ranks[key]) 
    end 
     
    if (wages) then 
        for key, value in ipairs(wages) do 
            wages[key] = tonumber(wages[key]) or 0 
        end 
         
        mysql:query_free("UPDATE factions SET wage_1='" .. wages[1] .. "', wage_2='" .. wages[2] .. "', wage_3='" .. wages[3] .. "', wage_4='" .. wages[4] .. "', wage_5='" .. wages[5] .. "', wage_6='" .. wages[6] .. "', wage_7='" .. wages[7] .. "', wage_8='" .. wages[8] .. "', wage_9='" .. wages[9] .. "', wage_10='" .. wages[10] .. "', wage_11='" .. wages[11] .. "', wage_12='" .. wages[12] .. "', wage_13='" .. wages[13] .. "', wage_14='" .. wages[14] .. "', wage_15='" .. wages[15] .. "', wage_16='" .. wages[16] .. "' WHERE id='" .. factionID .. "'") 
        exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "wages", wages, false) 
    end 
     
    mysql:query_free("UPDATE factions SET rank_1='" .. ranks[1] .. "', rank_2='" .. ranks[2] .. "', rank_3='" .. ranks[3] .. "', rank_4='" .. ranks[4] .. "', rank_5='" .. ranks[5] .. "', rank_6='" .. ranks[6] .. "', rank_7='" .. ranks[7] .. "', rank_8='" .. ranks[8] .. "', rank_9='" .. ranks[9] .. "', rank_10='" .. ranks[10] .. "', rank_11='" .. ranks[11] .. "', rank_12='" .. ranks[12] .. "', rank_13='" .. ranks[13] .. "', rank_14='" .. ranks[14] .. "', rank_15='" .. ranks[15] .. "', rank_16='".. ranks[16] .."' WHERE id='" .. factionID .. "'") 
    exports['anticheat-system']:changeProtectedElementDataEx(theTeam, "ranks", ranks, false) 
     
    outputChatBox("Faction information updated successfully.", source, 0, 255, 0) 
    showFactionMenu(source) 
end 
addEvent("cguiUpdateRanks", true ) 
addEventHandler("cguiUpdateRanks", getRootElement(), callbackUpdateRanks) 

Link to comment
I don't understand what do you mean exactly, where do you want the check?

I mean here,

  tRankWages[i] = guiCreateEdit(0.775, y, 0.2, 0.04, tostring(arrFactionWages[i]), true, wRanks) 

( line 30-31 on first post )

I'm trying to add a limit to it, 0-1500 so people can't put more than 1500 in it.

Link to comment
-- RANKS/WAGES 
  
lRanks = { } 
tRanks = { } 
tRankWages = { } 
wRanks = nil 
bRanksSave, bRanksClose = nil 
  
function btEditRanks(button, state) 
    if (source==gButtonEditRanks) and (button=="left") and (state=="up") then 
        local factionType = tonumber(getElementData(theTeam, "type")) 
        lRanks = { } 
        tRanks = { } 
        tRankWages = { } 
        
        guiSetInputEnabled(true) 
        
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then -- factions w/ wages 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
            
            wRanks = guiCreateWindow(x, y, width, height, "Ranks & Wages", false) 
            
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title & Wage: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.4, y, 0.3, 0.04, arrFactionRanks[i], true, wRanks) 
                tRankWages[i] = guiCreateEdit(0.775, y, 0.2, 0.04, tostring(arrFactionWages[i]), true, wRanks) 
                addEventHandler("onClientGUIChanged", tRankWages[i],  
                function(element) 
                    local number = tonumber(guiGetText(element)) 
                    if (number and number > 1500) then -- If the number in the EDIT is higher to 1500 .. 
                            guiSetText(element, 1500) -- We set it to 1500, so this way it'll never go higher. 
                        end 
                    end 
                ,false) 
                y = y + 0.05 
            end 
        else 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
            
            wRanks = guiCreateWindow(x, y, width, height, "Ranks", false) 
            
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.3, y, 0.6, 0.04, arrFactionRanks[i], true, wRanks) 
                y = y + 0.05 
            end 
        end 
        
        bRanksSave = guiCreateButton(0.05, 0.850, 0.9, 0.075, "Save!", true, wRanks) 
        bRanksClose = guiCreateButton(0.05, 0.940, 0.9, 0.075, "Close", true, wRanks) 
        
        addEventHandler("onClientGUIClick", bRanksSave, saveRanks, false) 
        addEventHandler("onClientGUIClick", bRanksClose, closeRanks, false) 
    end 
end 
  
function saveRanks(button, state) 
    if (source==bRanksSave) and (button=="left") and (state=="up") then 
        local found = false 
        local isNumber = true 
        for key, value in ipairs(tRanks) do 
            if (string.find(guiGetText(tRanks[key]), ";")) or (string.find(guiGetText(tRanks[key]), "'")) then 
                found = true 
            end 
        end 
        
        local factionType = tonumber(getElementData(theTeam, "type")) 
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
            for key, value in ipairs(tRankWages) do 
                if not (tostring(type(tonumber(guiGetText(tRankWages[key])))) == "number") then 
                    isNumber = false 
                end 
            end 
        end 
        
        if (found) then 
            outputChatBox("Your ranks contain invalid characters, please ensure it does not contain characters such as '@.;", 255, 0, 0) 
        elseif not (isNumber) then 
            outputChatBox("Your wages are not numbers, please ensure you entered a number and no currency symbol.", 255, 0, 0) 
        else 
            local sendRanks = { } 
            local sendWages = { } 
            
            for key, value in ipairs(tRanks) do 
                sendRanks[key] = guiGetText(tRanks[key]) 
            end 
            
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                for key, value in ipairs(tRankWages) do 
                    sendWages[key] = guiGetText(tRankWages[key]) 
                end 
            end 
            
            hideFactionMenu() 
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks, sendWages) 
            else 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks) 
            end 
        end 
    end 
end 
  
function closeRanks(button, state) 
    if (source==bRanksClose) and (button=="left") and (state=="up") then 
        if (wRanks) then 
            destroyElement(wRanks) 
            lRanks, tRanks, tRankWages, wRanks, bRanksSave, bRanksClose = nil, nil, nil, nil, nil, nil 
            guiSetInputEnabled(false) 
        end 
    end 
end 

@Kenix: The Length is no the problem as far as I know, because he could just put $2000 if you restrict the Length to 4 digits.

Link to comment
-- RANKS/WAGES 
  
lRanks = { } 
tRanks = { } 
tRankWages = { } 
wRanks = nil 
bRanksSave, bRanksClose = nil 
  
function btEditRanks(button, state) 
    if (source==gButtonEditRanks) and (button=="left") and (state=="up") then 
        local factionType = tonumber(getElementData(theTeam, "type")) 
        lRanks = { } 
        tRanks = { } 
        tRankWages = { } 
        
        guiSetInputEnabled(true) 
        
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then -- factions w/ wages 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
            
            wRanks = guiCreateWindow(x, y, width, height, "Ranks & Wages", false) 
            
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title & Wage: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.4, y, 0.3, 0.04, arrFactionRanks[i], true, wRanks) 
                addEventHandler("onClientGUIChanged", tRanks[i],  
                function(element) 
                    local number = tonumber(guiGetText(element)) 
                    if (number and number > 1500) then -- If the number in the EDIT is higher to 1500 .. 
                            guiSetText(element, 1500) -- We set it to 1500, so this way it'll never go higher. 
                        end 
                    end 
                ,false) 
                tRankWages[i] = guiCreateEdit(0.775, y, 0.2, 0.04, tostring(arrFactionWages[i]), true, wRanks) 
                y = y + 0.05 
            end 
        else 
            local width, height = 400, 620 
            local scrWidth, scrHeight = guiGetScreenSize() 
            local x = scrWidth/2 - (width/2) 
            local y = scrHeight/2 - (height/2) 
            
            wRanks = guiCreateWindow(x, y, width, height, "Ranks", false) 
            
            local y = 0.0525 
            for i=1, 16 do 
                lRanks[i] = guiCreateLabel(0.05, y+0.0025, 0.4, 0.1, "Rank #" .. i .. " Title: ", true, wRanks) 
                guiSetFont(lRanks[i], "default-bold-small") 
                tRanks[i] = guiCreateEdit(0.3, y, 0.6, 0.04, arrFactionRanks[i], true, wRanks) 
                y = y + 0.05 
            end 
        end 
        
        bRanksSave = guiCreateButton(0.05, 0.850, 0.9, 0.075, "Save!", true, wRanks) 
        bRanksClose = guiCreateButton(0.05, 0.940, 0.9, 0.075, "Close", true, wRanks) 
        
        addEventHandler("onClientGUIClick", bRanksSave, saveRanks, false) 
        addEventHandler("onClientGUIClick", bRanksClose, closeRanks, false) 
    end 
end 
  
function saveRanks(button, state) 
    if (source==bRanksSave) and (button=="left") and (state=="up") then 
        local found = false 
        local isNumber = true 
        for key, value in ipairs(tRanks) do 
            if (string.find(guiGetText(tRanks[key]), ";")) or (string.find(guiGetText(tRanks[key]), "'")) then 
                found = true 
            end 
        end 
        
        local factionType = tonumber(getElementData(theTeam, "type")) 
        if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
            for key, value in ipairs(tRankWages) do 
                if not (tostring(type(tonumber(guiGetText(tRankWages[key])))) == "number") then 
                    isNumber = false 
                end 
            end 
        end 
        
        if (found) then 
            outputChatBox("Your ranks contain invalid characters, please ensure it does not contain characters such as '@.;", 255, 0, 0) 
        elseif not (isNumber) then 
            outputChatBox("Your wages are not numbers, please ensure you entered a number and no currency symbol.", 255, 0, 0) 
        else 
            local sendRanks = { } 
            local sendWages = { } 
            
            for key, value in ipairs(tRanks) do 
                sendRanks[key] = guiGetText(tRanks[key]) 
            end 
            
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                for key, value in ipairs(tRankWages) do 
                    sendWages[key] = guiGetText(tRankWages[key]) 
                end 
            end 
            
            hideFactionMenu() 
            if (factionType==2) or (factionType==3) or (factionType==4) or (factionType==5) or (factionType==6) then 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks, sendWages) 
            else 
                triggerServerEvent("cguiUpdateRanks", getLocalPlayer(), sendRanks) 
            end 
        end 
    end 
end 
  
function closeRanks(button, state) 
    if (source==bRanksClose) and (button=="left") and (state=="up") then 
        if (wRanks) then 
            destroyElement(wRanks) 
            lRanks, tRanks, tRankWages, wRanks, bRanksSave, bRanksClose = nil, nil, nil, nil, nil, nil 
            guiSetInputEnabled(false) 
        end 
    end 
end 

@Kenix: The Length is no the problem as far as I know, because he could just put $2000 if you restrict the Length to 4 digits.

I like what you did there, very clever, but sadly it doesn't work :cry:

it still lets people set above 1500

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