Jump to content

Loan/Give Money System - HELP URGENT!?!


FlyingSpoon

Recommended Posts

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

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

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

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

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

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

Well I got somewhere :D

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

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