FlyingSpoon Posted February 17, 2015 Share Posted February 17, 2015 Well, before I do anything else, I want the person to enter an amount between, $50,000 - $500,000 So if they enter an amount over it it will output a message saying, please enter an amount between them to numbers and the same if they enter an amount less then it. function loanSys() loanMenu = guiCreateWindow(349, 240, 354, 310, "Loan-System v0.1", false) guiWindowSetSizable(loanMenu, false) loanLabel = guiCreateLabel(9, 26, 81, 21, "Loan Amount: ", false, loanMenu) guiSetFont(loanLabel, "default-small") loanEd = guiCreateEdit(71, 21, 164, 27, "Enter 50000-500000", false, loanMenu) loanInfo = guiCreateLabel(9, 52, 325, 37, "Enter the loan amount you wish to receive,\nMinimum: $50,000\nMaximum: $500,000\n", false, loanMenu) guiSetFont(loanInfo, "default-small") loanClose = guiCreateButton(304, 279, 41, 22, "Close", false, loanMenu) guiSetFont(loanClose, "default-small") bSumbit = guiCreateButton(240, 22, 99, 32, "Submit", false, loanMenu) showCursor(true) end addCommandHandler("loanv1", loanSys) function closeIt() if loanClose then guiSetVisible(loanSys, false) showCursor(false) end end So, basically when they enter the amount in the guiEdit and hit the Submit button if it is between 50-50000 then they get that amount and a message gets output's like the example below, e.g. 15000, so they get $15,000 and this message gets outputted, outputChatBox("You have received $15,000!") Anyone help me please! Link to comment
AMARANT Posted February 17, 2015 Share Posted February 17, 2015 You need some kind of this if I got right what you asked: local amt = tonumber(guiGetText(loanEd)) if amt then if amt>=50000 and amt<=500000 then --You actions else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end Link to comment
FlyingSpoon Posted February 17, 2015 Author Share Posted February 17, 2015 Your script has a slight bug, When I start/restart it, it output's - Enter something. local amt = tonumber(guiGetText(loanEd)) if amt and bSumbit then if amt>=50000 and amt<=500000 then givePlayerMoney ( source, amt ) else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end I tried doing this but no luck Link to comment
AMARANT Posted February 17, 2015 Share Posted February 17, 2015 Man, it's just a piece of code. I showed you an example how to check the data you enter into edit boxes. The rest you must do on your own. Link to comment
FlyingSpoon Posted February 17, 2015 Author Share Posted February 17, 2015 Well, I need help haha, by help I meant someone fixing my code so I can learn from it for future references.. Sorry if you mis-understood me. Link to comment
AMARANT Posted February 17, 2015 Share Posted February 17, 2015 You just needed to attach GUI click event to check your button pressed and info from the edit box. But OK here is the code: function pressMyButton() if source==bSubmit then local amt = tonumber(guiGetText(loanEd)) if amt then if amt>=50000 and amt<=500000 then --You actions else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end end end addEventHandler("onClientGUIClick",root,pressMyButton) Link to comment
FlyingSpoon Posted February 17, 2015 Author Share Posted February 17, 2015 loanMenu = guiCreateWindow(349, 240, 354, 310, "Loan-System v0.1", false) guiWindowSetSizable(loanMenu, false) loanLabel = guiCreateLabel(9, 26, 81, 21, "Loan Amount: ", false, loanMenu) guiSetFont(loanLabel, "default-small") loanEd = guiCreateEdit(71, 21, 164, 27, "Enter 50000-500000", false, loanMenu) loanInfo = guiCreateLabel(9, 52, 325, 37, "Enter the loan amount you wish to receive,\nMinimum: $50,000\nMaximum: $500,000\n", false, loanMenu) guiSetFont(loanInfo, "default-small") loanClose = guiCreateButton(304, 279, 41, 22, "Close", false, loanMenu) guiSetFont(loanClose, "default-small") bSumbit = guiCreateButton(240, 22, 99, 32, "Submit", false, loanMenu) guiSetVisible(loanMenu,false) function openIt() guiSetVisible(loanMenu,true) showCursor(true) end addCommandHandler("loanv1", openIt) function closeIt() if loanClose then guiSetVisible(loanSys, false) showCursor(false) end end function pressMyButton() if source==bSubmit then local amt = tonumber(guiGetText(loanEd)) if amt then if amt>=50000 and amt<=500000 then givePlayerMoney ( source, amt ) else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end end end addEventHandler("onClientGUIClick",root,pressMyButton) I did this but it didn't work still, I also attempt to press 'Close' and it still doesn't work! Help please Link to comment
Dealman Posted February 17, 2015 Share Posted February 17, 2015 You called your button variable bSumbit, not bSubmit. Link to comment
AMARANT Posted February 17, 2015 Share Posted February 17, 2015 You called your button variable bSumbit, not bSubmit. Exactly. Just tested. It's very hard to detect it without checking in-game btw. Link to comment
FlyingSpoon Posted February 18, 2015 Author Share Posted February 18, 2015 It works great, Now it the 'givePlayerMoney' part which is not being detected, When I hit submit nothing happens, But the rest happens if I type it below, or above that number a text is outputted This happens when I hit submit with a value between them 2 numbers. WARNING: loanv1\client.lua:33: Bad argument @ 'givePlayerMoney' [Expected number at argument 1, got gui-button] loanMenu = guiCreateWindow(349, 240, 354, 310, "Loan-System v0.1", false) guiWindowSetSizable(loanMenu, false) loanLabel = guiCreateLabel(9, 26, 81, 21, "Loan Amount: ", false, loanMenu) guiSetFont(loanLabel, "default-small") loanEd = guiCreateEdit(71, 21, 164, 27, "Enter 50000-500000", false, loanMenu) loanInfo = guiCreateLabel(9, 52, 325, 37, "Enter the loan amount you wish to receive,\nMinimum: $50,000\nMaximum: $500,000\n", false, loanMenu) guiSetFont(loanInfo, "default-small") loanClose = guiCreateButton(304, 279, 41, 22, "Close", false, loanMenu) guiSetFont(loanClose, "default-small") bSubmit = guiCreateButton(240, 22, 99, 32, "Submit", false, loanMenu) guiSetVisible(loanMenu,false) function openIt() guiSetVisible(loanMenu,true) showCursor(true) end addCommandHandler("loanv1", openIt) function closeIt() if loanClose then guiSetVisible(loanSys, false) showCursor(false) end end function pressMyButton() if source==bSubmit then local amt = tonumber(guiGetText(loanEd)) if amt then if amt>=50000 and amt<=500000 then givePlayerMoney ( source, amt ) else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end end end addEventHandler("onClientGUIClick",root,pressMyButton) Link to comment
AMARANT Posted February 18, 2015 Share Posted February 18, 2015 Because you set the first argument to 'source' which is your GUI button pressed. You need to delete your first argument at all because client-side givePlayerMoney needs only the integer parameter. But! I strongly recommend you to use this function ONLY server-side! And please check MTA wiki to see function arguments. Link to comment
FlyingSpoon Posted February 18, 2015 Author Share Posted February 18, 2015 Well I got somewhere Ty for your help guys +1 !! So now the new problem is, I want to move the givePlayerMoney server-side any ideas how I can do it? Please someone help. loanMenu = guiCreateWindow(349, 240, 354, 310, "Loan-System v0.1", false) guiWindowSetSizable(loanMenu, false) loanLabel = guiCreateLabel(9, 26, 81, 21, "Loan Amount: ", false, loanMenu) guiSetFont(loanLabel, "default-small") loanEd = guiCreateEdit(71, 21, 164, 27, "Enter 50000-500000", false, loanMenu) loanInfo = guiCreateLabel(9, 52, 325, 37, "Enter the loan amount you wish to receive,\nMinimum: $50,000\nMaximum: $500,000\n", false, loanMenu) guiSetFont(loanInfo, "default-small") loanClose = guiCreateButton(304, 279, 41, 22, "Close", false, loanMenu) guiSetFont(loanClose, "default-small") bSubmit = guiCreateButton(240, 22, 99, 32, "Submit", false, loanMenu) guiSetVisible(loanMenu,false) function openIt() guiSetVisible(loanMenu,true) showCursor(true) end addCommandHandler("loanv1", openIt) function closeIt() if loanClose then guiSetVisible(loanSys, false) showCursor(false) end end addEventHandler("onClientGUIClick", resourceRoot, closeIt) function pressMyButton() if source==bSubmit then local amt = tonumber(guiGetText(loanEd)) if amt then if amt>=50000 and amt<=500000 then givePlayerMoney ( amt ) else outputChatBox("Enter amount between 50000 and 500000.") end else outputChatBox("Enter something.") end end end addEventHandler("onClientGUIClick",root,pressMyButton) Link to comment
AMARANT Posted February 18, 2015 Share Posted February 18, 2015 https://wiki.multitheftauto.com/wiki/TriggerServerEvent Link to comment
FlyingSpoon Posted February 18, 2015 Author Share Posted February 18, 2015 Well I tried that, but I was worried about the guiGetText, how will I do, givePlayerMoney( source, amt ) ? amt == Client Side Link to comment
AMARANT Posted February 18, 2015 Share Posted February 18, 2015 You can pass these variables to the server with that function I provided. Link to comment
FlyingSpoon Posted February 18, 2015 Author Share Posted February 18, 2015 Can you show me how it's done :~( I am really confused. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now