Jump to content

GUI problem


Recommended Posts

So I scripted a ammunation resource resterday, today I decided to make a very simple pizza guy job and when I start to test the markers I see that when I enter to any kind of marker it opens the ammunation gui. So how can i fix this bug? Every markers is opening ammunation GUI...

  
WeAN = {} 
M4 = {} 
Eagle = {} 
WeANclose = {} 
SPAZ12 = {} 
AK47 = {} 
MP5 = {} 
Pistol = {} 
WeAN.window = guiCreateWindow(471, 218, 367, 511, "WeAmmu Nation   v1.0", false) 
guiWindowSetMovable(WeAN.window, false) 
guiWindowSetSizable(WeAN.window, false) 
  
M4.button = guiCreateButton(9, 50, 105, 41, "M4 \n2000$", false, WeAN.window) 
guiSetProperty(M4.button, "NormalTextColour", "FFAAAAAA") 
Eagle.button = guiCreateButton(124, 50, 105, 41, "Desert Eagle \n500$", false, WeAN.window) 
guiSetProperty(Eagle.button, "NormalTextColour", "FFAAAAAA") 
MP5.button = guiCreateButton(239, 50, 105, 41, "MP5\n1000$", false, WeAN.window) 
guiSetProperty(MP5.button, "NormalTextColour", "FFAAAAAA") 
Pistol.button = guiCreateButton(9, 101, 105, 41, "Pistol\n100$", false, WeAN.window) 
guiSetProperty(Pistol.button, "NormalTextColour", "FFAAAAAA") 
SPAZ12.button = guiCreateButton(124, 101, 105, 41, "SPAZ-12\n1500$", false, WeAN.window) 
guiSetProperty(SPAZ12.button, "NormalTextColour", "FFAAAAAA") 
AK47.button = guiCreateButton(239, 101, 105, 41, "AK-47\n1200$", false, WeAN.window) 
guiSetProperty(AK47.button, "NormalTextColour", "FFAAAAAA") 
WeANclose.button = guiCreateButton(329, 19, 28, 27, "X", false, WeAN.window) 
guiSetProperty(WeANclose.button, "NormalTextColour", "FFAAAAAA") 
  
local WeANmarker = createMarker ( 777, -2070, 11.5, "cylinder", 2, 0, 128, 0, 170 ) 
guiSetVisible(WeAN.window,false) 
-- 
-- 
-- 
function WeANmarkerEnter () 
guiSetVisible(WeAN.window,true) 
showCursor ( true ) 
end 
addEventHandler ( "onClientMarkerHit", getRootElement(), WeANmarkerEnter ) 
  
function WeANguiClose () 
guiSetVisible(WeAN.window,false) 
showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", WeANclose.button, WeANguiClose, false ) 
  
function buym4 () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"M4","2000","31","100") 
end 
addEventHandler ( "onClientGUIClick", M4.button, buym4, false ) 
  
function buyEagle () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"Desert Eagle","500","24","50") 
end 
addEventHandler ( "onClientGUIClick", Eagle.button, buyEagle, false ) 
  
function buyMP5 () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"MP5","1000","29","100") 
end 
addEventHandler ( "onClientGUIClick", MP5.button, buyMP5, false ) 
  
function buyPistol () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"Pistol","100","22","50") 
end 
addEventHandler ( "onClientGUIClick", Pistol.button, buyPistol, false ) 
  
function buySPAZ12 () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"SPAZ-12","1500","27","90") 
end 
addEventHandler ( "onClientGUIClick", SPAZ12.button, buySPAZ12, false ) 
  
function buyAK47 () 
triggerServerEvent("buyWeapon",getLocalPlayer(),"AK-47","1200","30","100") 
end 
addEventHandler ( "onClientGUIClick", AK47.button, buyAK47, false ) 
  
  

Link to comment
  
local weapons = { }  -- lets use 1 table 
  
  
weapons.window = guiCreateWindow(471, 218, 367, 511, "WeAmmu Nation   v1.0", false) 
guiWindowSetMovable(weapons.window, false) 
guiWindowSetSizable(weapons.window, false) 
guiSetVisible(weapons.WeAN,false) -- lets put this here, just to make it easy for you  
  
weapons.M4 = guiCreateButton(9, 50, 105, 41, "M4 \n2000$", false, weapons.window) 
guiSetProperty(weapons.M4, "NormalTextColour", "FFAAAAAA") 
  
weapons.Eagle = guiCreateButton(124, 50, 105, 41, "Desert Eagle \n500$", false, weapons.window) 
guiSetProperty(weapons.Eagle, "NormalTextColour", "FFAAAAAA") 
  
weapons.MP5 = guiCreateButton(239, 50, 105, 41, "MP5\n1000$", false, weapons.window) 
guiSetProperty(weapons.MP5, "NormalTextColour", "FFAAAAAA") 
  
weapons.Pistol = guiCreateButton(9, 101, 105, 41, "Pistol\n100$", false, weapons.window) 
guiSetProperty(weapons.Pistol, "NormalTextColour", "FFAAAAAA") 
  
weapons.SPAZ12 = guiCreateButton(124, 101, 105, 41, "SPAZ-12\n1500$", false, weapons.window) 
guiSetProperty(weapons.SPAZ12, "NormalTextColour", "FFAAAAAA") 
  
weapons.AK47 = guiCreateButton(239, 101, 105, 41, "AK-47\n1200$", false, weapons.window) 
guiSetProperty(weapons.AK47, "NormalTextColour", "FFAAAAAA") 
  
weapons.close = guiCreateButton(329, 19, 28, 27, "X", false, weapons.window) 
guiSetProperty(weapons.close, "NormalTextColour", "FFAAAAAA") 
  
local WeANmarker = createMarker ( 777, -2070, 11.5, "cylinder", 2, 0, 128, 0, 170 ) 
  
-- 
-- 
-- 
function WeANmarkerEnter () 
if source == WeANmarker then  
guiSetVisible(weapons.WeAN,true) 
showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", getRootElement(), WeANmarkerEnter ) 
  
function buttonsz () 
if source == weapons.close then  
guiSetVisible(weapons.window,false) 
showCursor ( false )   
------- If you want to make your code a little more better then use 1 triggerServerEvent. You can use variables for that 
elseif source ==  weapons.M4  then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"M4","2000","31","100") 
elseif source == weapons.Eagle then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"Desert Eagle","500","24","50") 
elseif source == weapons.MP5 then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"MP5","1000","29","100") 
elseif source == weapons.Pistol then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"Pistol","100","22","50") 
elseif source ==  weapons.SPAZ12  then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"SPAZ-12","1500","27","90") 
elseif source == weapons.AK47 then  
triggerServerEvent("buyWeapon",getLocalPlayer(),"AK-47","1200","30","100") 
   end  
end 
addEventHandler ( "onClientGUIClick", root, buttonsz, false ) 
  
  
  
  

Link to comment

thanks for the help again but the buttons arent working atm and no errors at debugscript. I dont think it has got anything to do about server side because the gui close button doesnt working too. It seems like I should work with more smaller resources for learning lua :D . Resources like ammu nations are kind a hard for me. I am trying to do this resource for 2 days and I started lua 5 days ago so I am really noob for these kind of resources :cry:

Link to comment
thanks for the help again but the buttons arent working atm and no errors at debugscript. I dont think it has got anything to do about server side because the gui close button doesnt working too. It seems like I should work with more smaller resources for learning lua :D . Resources like ammu nations are kind a hard for me. I am trying to do this resource for 2 days and I started lua 5 days ago so I am really noob for these kind of resources :cry:

I did another small fix after testing it in my local server and its working now.

  
local weapons = { }  -- lets use 1 table 
  
  
weapons.window = guiCreateWindow(471, 218, 367, 511, "WeAmmu Nation   v1.0", false) 
guiWindowSetMovable(weapons.window, false) 
guiWindowSetSizable(weapons.window, false) 
guiSetVisible(weapons.window,true) -- lets put this here, just to make it easy for you 
  
weapons.M4 = guiCreateButton(9, 50, 105, 41, "M4 \n2000$", false, weapons.window) 
guiSetProperty(weapons.M4, "NormalTextColour", "FFAAAAAA") 
  
weapons.Eagle = guiCreateButton(124, 50, 105, 41, "Desert Eagle \n500$", false, weapons.window) 
guiSetProperty(weapons.Eagle, "NormalTextColour", "FFAAAAAA") 
  
weapons.MP5 = guiCreateButton(239, 50, 105, 41, "MP5\n1000$", false, weapons.window) 
guiSetProperty(weapons.MP5, "NormalTextColour", "FFAAAAAA") 
  
weapons.Pistol = guiCreateButton(9, 101, 105, 41, "Pistol\n100$", false, weapons.window) 
guiSetProperty(weapons.Pistol, "NormalTextColour", "FFAAAAAA") 
  
weapons.SPAZ12 = guiCreateButton(124, 101, 105, 41, "SPAZ-12\n1500$", false, weapons.window) 
guiSetProperty(weapons.SPAZ12, "NormalTextColour", "FFAAAAAA") 
  
weapons.AK47 = guiCreateButton(239, 101, 105, 41, "AK-47\n1200$", false, weapons.window) 
guiSetProperty(weapons.AK47, "NormalTextColour", "FFAAAAAA") 
  
weapons.close = guiCreateButton(329, 19, 28, 27, "X", false, weapons.window) 
guiSetProperty(weapons.close, "NormalTextColour", "FFAAAAAA") 
  
local WeANmarker = createMarker ( 777, -2070, 11.5, "cylinder", 2, 0, 128, 0, 170 ) 
  
-- 
-- 
-- 
function WeANmarkerEnter () 
if source == WeANmarker then 
guiSetVisible(weapons.window,true) 
showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", getRootElement(), WeANmarkerEnter ) 
  
function buttonsz () 
if source == weapons.close then 
guiSetVisible(weapons.window,false) 
showCursor ( false )   
------- If you want to make your code a little more better then use 1 triggerServerEvent. You can use variables for that 
elseif source ==  weapons.M4  then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"M4","2000","31","100") 
elseif source == weapons.Eagle then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"Desert Eagle","500","24","50") 
elseif source == weapons.MP5 then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"MP5","1000","29","100") 
elseif source == weapons.Pistol then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"Pistol","100","22","50") 
elseif source ==  weapons.SPAZ12  then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"SPAZ-12","1500","27","90") 
elseif source == weapons.AK47 then 
triggerServerEvent("buyWeapon",getLocalPlayer(),"AK-47","1200","30","100") 
   end 
end 
addEventHandler ( "onClientGUIClick", root, buttonsz ) 

Link to comment

You're welcome but I don't have your server side code so I didn't notice that when a player clicks a button then it will be triggered twice means player will lose money two times so just use this:

  
function buttonsz (button,state) 
if buttton == "left" and state == "down" then --if down does not work then place it with "up" 
  
if source == weapons.close then 
  
guiSetVisible(weapons.window,false) 
  
showCursor ( false )   
  
------- If you want to make your code a little more better then use 1 triggerServerEvent. You can use variables for that 
  
elseif source ==  weapons.M4  then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"M4","2000","31","100") 
  
elseif source == weapons.Eagle then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"Desert Eagle","500","24","50") 
  
elseif source == weapons.MP5 then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"MP5","1000","29","100") 
  
elseif source == weapons.Pistol then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"Pistol","100","22","50") 
  
elseif source ==  weapons.SPAZ12  then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"SPAZ-12","1500","27","90") 
  
elseif source == weapons.AK47 then 
  
triggerServerEvent("buyWeapon",getLocalPlayer(),"AK-47","1200","30","100") 
  
       end 
     end 
end 
  
addEventHandler ( "onClientGUIClick", root, buttonsz ) 

Link to comment
  
  
  
function buyWeapon (weaponName, weaponPrice, weaponID, weaponAmmo) 
local money = getPlayerMoney(source) 
    if ( tonumber(money) >= tonumber(weaponPrice) ) then 
    giveWeapon ( source, tonumber(weaponID), tonumber(weaponAmmo), true) 
    takePlayerMoney ( source, tonumber(weaponPrice) ) 
    else 
    outputChatBox ("You havent got enough money to buy this!", source) 
    end 
end 
addEvent("buyWeapon",true) 
addEventHandler("buyWeapon",getRootElement(),buyWeapon) 
  
  

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