Jump to content

GUI and function problems


DRW

Recommended Posts

Hello, I'm making a upgrade system, it basically creates a script that creates a marker, when you hit it, a GUI window appears where you can buy a stat, but if you have a stat upgraded to max then it will cancel and say that you can't buy them, for now it works perfectly, but the problem is that when I start the script, if I have less money than needed I can't buy it, but even if I have a more money than needed, it still doesn't let me buy it, only when I restart the resource.

Also, when I click other part of the GUI window except the buttons, the GUI reacts like I clicked all of the buttons and gives me stats without even having clicked on it.

Server:

  
markerbuy = createMarker (-509,2632,52.5,"cylinder",1.0,0,150,255,255) 
  
addEventHandler("onMarkerHit",markerbuy,function(plr) 
if plr then 
triggerClientEvent (plr,"actventana",plr) 
end 
end) 
  
  
addEvent("addstat1",true) 
addEventHandler ("addstat1", root, 
function () 
    local weaponState = getPedStat (source,69) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 69, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Colt 45.",source,255,255,255) 
end) 
  
  
addEvent("addstat2",true) 
addEventHandler ("addstat2", root, 
function () 
    local weaponState = getPedStat (source,73) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 73, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Escopeta Recortada.",source,255,255,255) 
end) 
  
addEvent("addstat3",true) 
addEventHandler ("addstat3", root, 
function () 
    local weaponState = getPedStat (source,75) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 75, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Subfusiles.",source,255,255,255) 
end) 
  
  
addEvent("addstat4",true) 
addEventHandler ("addstat4", root, 
function () 
    local weaponState = getPedStat (source,79) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 79, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Francotirador.",source,255,255,255) 
end) 
  
  
addEvent("addstat5",true) 
addEventHandler ("addstat5", root, 
function () 
    local weaponState = getPedStat (source,78) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 78, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de M4.",source,255,255,255) 
end) 
  
  
addEvent("addstat6",true) 
addEventHandler ("addstat6", root, 
function () 
    local weaponState = getPedStat (source,71) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 71, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Desert Eagle.",source,255,255,255) 
end) 
  
  
addEvent("addstat7",true) 
addEventHandler ("addstat7", root, 
function () 
    local weaponState = getPedStat (source,72) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 72, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Escopeta.",source,255,255,255) 
end) 
  
addEvent("addstat8",true) 
addEventHandler ("addstat8", root, 
function () 
    local weaponState = getPedStat (source,74) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,0,0) 
        return 
    end 
    setPedStat (source, 74, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Arma Antigravedad.",source,255,255,255) 
end) 
  
addEvent("addstat9",true) 
addEventHandler ("addstat9", root, 
function () 
    local weaponState = getPedStat (source,76) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 76, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de MP5.",source,255,255,255) 
end) 
  
addEvent("addstat10",true) 
addEventHandler ("addstat10", root, 
function () 
    local weaponState = getPedStat (source,77) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 77, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de AK-47.",source,255,255,255) 
end) 
  
addEvent("addstat11",true) 
addEventHandler ("addstat11", root, 
function () 
    local weaponState = getPedStat (source,22) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 22, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Resistencia.",source,255,255,255) 
end) 
  
addEvent("addstat12",true) 
addEventHandler ("addstat12", root, 
function () 
    local weaponState = getPedStat (source,24) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source, 24, tonumber(weaponState)+20) 
    outputChatBox ("Has mejorado 2 puntos de Vida Máxima.",source,255,255,255) 
end) 
  
  

Client:

rRoot = getResourceRootElement(getThisResource()) 
local money = getPlayerMoney(thePlayer) 
  
local screenW, screenH = guiGetScreenSize() 
        ventanamejoras = guiCreateWindow((screenW - 669) / 2, (screenH - 412) / 2, 669, 412, "ZNEXT: Sistema de habilidades", false) 
        guiWindowSetSizable(ventanamejoras, false) 
  
        mejora1 = guiCreateButton(13, 115, 288, 45, "+2 Puntos de mejora: Colt 45", false, ventanamejoras) 
        guiSetProperty(mejora1, "NormalTextColour", "FF05F7F9") 
        mejora2 = guiCreateButton(13, 160, 288, 45, "+2 Puntos de mejora: Escopeta recortada", false, ventanamejoras) 
        guiSetProperty(mejora2, "NormalTextColour", "FF00EFFE") 
        mejora3 = guiCreateButton(13, 205, 288, 45, "+2 Puntos de mejora: Subfusiles", false, ventanamejoras) 
        guiSetProperty(mejora3, "NormalTextColour", "FF00EFFE") 
        mejora4 = guiCreateButton(13, 250, 288, 45, "+2 Puntos de mejora: Francotirador", false, ventanamejoras) 
        guiSetProperty(mejora4, "NormalTextColour", "FF00EFFE") 
        mejora5 = guiCreateButton(13, 295, 288, 45, "+2 Puntos de mejora: M4", false, ventanamejoras) 
        guiSetProperty(mejora5, "NormalTextColour", "FF00EFFE") 
        mejora6 = guiCreateButton(13, 340, 288, 45, "+2 Puntos de mejora: Desert Eagle", false, ventanamejoras) 
        guiSetProperty(mejora6, "NormalTextColour", "FF00EFFE") 
        mejora7 = guiCreateButton(371, 115, 288, 45, "+2 Puntos de mejora: Escopeta", false, ventanamejoras) 
        guiSetProperty(mejora7, "NormalTextColour", "FF00EFFE") 
        mejora8 = guiCreateButton(371, 160, 288, 45, "+2 Puntos de mejora: Arma Antigravedad", false,ventanamejoras) 
        guiSetProperty(mejora8, "NormalTextColour", "FFFB9A02") 
        mejora9 = guiCreateButton(371, 205, 288, 45, "+2 Puntos de mejora: MP5", false, ventanamejoras) 
        guiSetProperty(mejora9, "NormalTextColour", "FFAAAAAA") 
        mejora10 = guiCreateButton(371, 250, 288, 45, "+2 Puntos de mejora: AK-47", false, ventanamejoras) 
        guiSetProperty(mejora10, "NormalTextColour", "FF00EFFE") 
        mejora11 = guiCreateButton(371, 295, 288, 45, "+2 Puntos de mejora: Resistencia", false, ventanamejoras) 
        guiSetProperty(mejora11, "NormalTextColour", "FF53FC00") 
        mejora12 = guiCreateButton(371, 340, 288, 45, "+2 Puntos de mejora: Vida máxima", false, ventanamejoras) 
        guiSetProperty(mejora12, "NormalTextColour", "FF53FC00") 
        labelmejora = guiCreateLabel(197, 31, 268, 48, "Comprar mejoras", false, ventanamejoras) 
        guiSetFont(labelmejora, "sa-gothic")     
        cerrarmejoras = guiCreateButton(629, 21, 20, 19, "x", false, ventanamejoras) 
guiSetProperty(cerrarmejoras, "NormalTextColour", "FFFF0000") 
         
addEventHandler ("onClientResourceStart", rRoot, function () 
    guiSetVisible(ventanamejoras, false) 
    end) 
     
addEvent ("actventana",true) 
addEventHandler ("actventana",root, function () 
guiSetVisible (ventanamejoras,true) 
showCursor(true) 
guiBringToFront(ventanamejoras) 
end 
) 
     
addEventHandler ("onClientGUIClick", cerrarmejoras, function() 
showCursor (false) 
guiSetVisible (ventanamejoras, false) 
end) 
  
addEventHandler ("onClientGUIClick", mejora1, function() 
if (money < 1000)  --HERE IS THE MAIN PROBLEM 
then return 
else 
triggerServerEvent ("addstat1", localPlayer) 
end 
end) 
  
addEventHandler ("onClientGUIClick", mejora2, function() 
triggerServerEvent ("addstat2", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora3, function() 
triggerServerEvent ("addstat3", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora4, function() 
triggerServerEvent ("addstat4", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora5, function() 
triggerServerEvent ("addstat5", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora6, function() 
triggerServerEvent ("addstat6", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora7, function() 
triggerServerEvent ("addstat7", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora8, function() 
triggerServerEvent ("addstat8", localPlayer) 
end)  
addEventHandler ("onClientGUIClick", mejora9, function() 
triggerServerEvent ("addstat9", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora10, function() 
triggerServerEvent ("addstat10", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora11, function() 
triggerServerEvent ("addstat11", localPlayer) 
end)  
  
addEventHandler ("onClientGUIClick", mejora12, function() 
triggerServerEvent ("addstat12", localPlayer) 
end) 
  
     
  
     
  
  

Link to comment

your script in 90 lines.

* Client side:

  
 addEventHandler("onClientResourceStart",resourceRoot, 
 function() 
        local screenW, screenH = guiGetScreenSize() 
        ventanamejoras = guiCreateWindow((screenW - 669) / 2, (screenH - 412) / 2, 669, 412, "ZNEXT: Sistema de habilidades", false) 
        guiWindowSetSizable(ventanamejoras, false) 
        guiSetVisible(ventanamejoras, false) 
        mejora1 = guiCreateButton(13, 115, 288, 45, "+2 Puntos de mejora: Colt 45", false, ventanamejoras) 
        mejora2 = guiCreateButton(13, 160, 288, 45, "+2 Puntos de mejora: Escopeta recortada", false, ventanamejoras) 
        mejora3 = guiCreateButton(13, 205, 288, 45, "+2 Puntos de mejora: Subfusiles", false, ventanamejoras) 
        mejora4 = guiCreateButton(13, 250, 288, 45, "+2 Puntos de mejora: Francotirador", false, ventanamejoras) 
        mejora5 = guiCreateButton(13, 295, 288, 45, "+2 Puntos de mejora: M4", false, ventanamejoras) 
        mejora6 = guiCreateButton(13, 340, 288, 45, "+2 Puntos de mejora: Desert Eagle", false, ventanamejoras) 
        mejora7 = guiCreateButton(371, 115, 288, 45, "+2 Puntos de mejora: Escopeta", false, ventanamejoras) 
        mejora8 = guiCreateButton(371, 160, 288, 45, "+2 Puntos de mejora: Arma Antigravedad", false,ventanamejoras) 
        mejora9 = guiCreateButton(371, 205, 288, 45, "+2 Puntos de mejora: MP5", false, ventanamejoras) 
        mejora10 = guiCreateButton(371, 250, 288, 45, "+2 Puntos de mejora: AK-47", false, ventanamejoras) 
        mejora11 = guiCreateButton(371, 295, 288, 45, "+2 Puntos de mejora: Resistencia", false, ventanamejoras) 
        mejora12 = guiCreateButton(371, 340, 288, 45, "+2 Puntos de mejora: Vida máxima", false, ventanamejoras) 
        labelmejora = guiCreateLabel(197, 31, 268, 48, "Comprar mejoras", false, ventanamejoras) 
        guiSetFont(labelmejora, "sa-gothic")     
        cerrarmejoras = guiCreateButton(629, 21, 20, 19, "x", false, ventanamejoras) 
        guiSetProperty(cerrarmejoras, "NormalTextColour", "FFFF0000") 
         
        -- Buttons 
        buttons = {mejora1,mejora2,mejora3,mejora4,mejora5,mejora6,mejora7,mejora8,mejora9,mejora10,mejora11,mejora12} 
        for i , v in pairs(buttons) do 
        guiSetProperty(v, "NormalTextColour", "FF05F7F9") 
        end  
         
        -- Events 
        addEventHandler ("onClientGUIClick", cerrarmejoras, closeGui,false) 
         
end 
) 
    
addEvent ("actventana",true) 
addEventHandler ("actventana",root,  
function () 
    guiSetVisible (ventanamejoras,true) 
    showCursor(true) 
    guiBringToFront(ventanamejoras) 
end 
) 
    
function closeGui() 
showCursor (false) 
guiSetVisible (ventanamejoras, false) 
end 
  
addEventHandler ("onClientGUIClick", guiRoot,  
function() 
local money = getPlayerMoney() 
    if (money < 1000) then outputChatBox ("Sorry you don't have engouh money!",255,0,0) return end  
        if source == mejora1 then 
        triggerServerEvent ("addstate", localPlayer,69) 
        elseif source == mejora2 then 
        triggerServerEvent ("addstate", localPlayer,73) 
        elseif source == mejora3 then 
        triggerServerEvent ("addstate", localPlayer,75) 
        elseif source == mejora4 then 
        triggerServerEvent ("addstate", localPlayer,79) 
        elseif source == mejora5 then 
        triggerServerEvent ("addstate", localPlayer,78) 
        elseif source == mejora6 then 
        triggerServerEvent ("addstate", localPlayer,71) 
        elseif source == mejora7 then 
        triggerServerEvent ("addstate", localPlayer,72) 
        elseif source == mejora8 then 
        triggerServerEvent ("addstate", localPlayer,74) 
        elseif source == mejora9 then 
        triggerServerEvent ("addstate", localPlayer,76) 
        elseif source == mejora10 then 
        triggerServerEvent ("addstate", localPlayer,77) 
        elseif source == mejora11 then 
        triggerServerEvent ("addstate", localPlayer,22) 
        elseif source == mejora12 then 
        triggerServerEvent ("addstate", localPlayer,24) 
    end 
end) 

* Server side

markerbuy = createMarker (-509,2632,52.5,"cylinder",1.0,0,150,255,255) 
  
addEventHandler("onMarkerHit",markerbuy, 
function(plr,matchDim) 
    if matchDim and isElement(plr) and getElementType(plr) == "player" then 
    triggerClientEvent (plr,"actventana",plr) 
    end 
end) 
  
  
addEvent("addstate",true) 
addEventHandler ("addstate", root, 
function (state,gunName) 
    local weaponState = getPedStat (source,tonumber(state)) 
    if  tonumber (weaponState) >= 1000 then 
            outputChatBox ("NO PUEDES MEJORAR.",source,255,255,255) 
        return 
    end 
    setPedStat (source,tonumber(state),tonumber(weaponState)+20) 
    outputChatBox ("Done!",source,255,255,255) 
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...