Best-Killer Posted January 14, 2016 Share Posted January 14, 2016 attempt to compare number with nill function depoistMoney() local text = guiGetText(GUIEditor.label[2]) local text2 = guiGetText(GUIEditor.edit[2]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney(localPlayer) >= tonumber(text) and tonumber(text) >= 0 then guiSetText(cashLabel,"Transferring...") setTimer(guiSetText,2000,1,cashLabel,""..tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney(localPlayer) < tonumber(text) then outputChatBox("You don't have enough money.") elseif tonumber(text) < 0 then outputChatBox("You can't deposit negative numbers.") end end end Line 10 Link to comment
Platin Posted January 14, 2016 Share Posted January 14, 2016 function depoistMoney() local text = guiGetText(GUIEditor.label[2]) local text2 = guiGetText(GUIEditor.edit[2]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney(localPlayer) >= tonumber(text) and tonumber(text) >= 0 then guiSetText(cashLabel,"Transferring...") setTimer(guiSetText,2000,1,cashLabel,tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney() < tonumber(text) then -- getPlayerMoney in client-side dont need arguments outputChatBox("You don't have enough money.") elseif tonumber(text) < 0 then outputChatBox("You can't deposit negative numbers.") end end end Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 thanks bro function depoistMoney() local text = guiGetText(GUIEditor.label[2]) local text2 = guiGetText(GUIEditor.edit[2]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney(localPlayer) >= tonumber(text) and tonumber(text) >= 0 then guiSetText(cashLabel,"Transferring...") setTimer(guiSetText,2000,1,cashLabel,tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney() then -- outputChatBox("You don't have enough money.") elseif tonumber(text) < 0 then outputChatBox("You can't deposit negative numbers.") end end end now work but when click deposit it's says You don't have enough money and i have money what is the problem Link to comment
Enargy, Posted January 14, 2016 Share Posted January 14, 2016 elseif tonumber( getPlayerMoney() < text ) then Link to comment
Army@1 Posted January 14, 2016 Share Posted January 14, 2016 function depoistMoney() local text = guiGetText(GUIEditor.label[2]) local text2 = guiGetText(GUIEditor.edit[2]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(cashLabel,"Transferring...") setTimer(guiSetText,2000,1,cashLabel,tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney() == 0 then -- outputChatBox("You don't have enough money.") elseif getPlayerMoney() < 0 then outputChatBox("You can't deposit negative numbers.") end end end Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 elseif tonumber( getPlayerMoney() < text ) then nothing shoing function depoistMoney() local text = guiGetText(GUIEditor.label[2]) local text2 = guiGetText(GUIEditor.edit[2]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(cashLabel,"Transferring...") setTimer(guiSetText,2000,1,cashLabel,tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney() == 0 then -- outputChatBox("You don't have enough money.") elseif getPlayerMoney() < 0 then outputChatBox("You can't deposit negative numbers.") end end end nothing shoing same problem 0 errors 0 warnings Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 server side : function onPlayerLogin(per,cur) name = getAccountName(cur) money = getAccountData(account,"bank.money") setElementData(source,"bank.money",money) setElementData(source,"account",cur) setElementData(source,"accountName",name) end addEventHandler("onPlayerLogin",root,onPlayerLogin) function onPlayerLogout() account = getPlayerAccount(source) money = getElementData(source,"bank.money") setAccountData(account,"bank.money",money) end addEventHandler("onPlayerQuit",root,onPlayerLogout) function giveMoneyOnLog() local bankmoney = getElementData(source,"bank.money") local playermoney = getPlayerMoney(source) if bankmoney == "0" and playermoney == 0 then setElementData(source,"bank.money","5000") outputChatBox("Your current bank balance: $"..getElementData(source,"bank.money"),source) end end addEventHandler("onPlayerLogin",root,giveMoneyOnLog) Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 function depoistMoney() local text = guiGetText(GUIEditor.edit[2]) local text2 = guiGetText(GUIEditor.edit[1]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],tostring(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bank.money",tonumber(text + text2)) elseif getPlayerMoney() == 0 then -- outputChatBox("You don't have enough money.") elseif getPlayerMoney() < 0 then outputChatBox("You can't deposit negative numbers.") end end end line 7 ( attempt to perform arithmetic on local 'text2' ( a string value) Link to comment
AMARANT Posted January 14, 2016 Share Posted January 14, 2016 Man, isn't it obvious? You're trying to do maths with 'strings'. Can you add "ABC"+"ABC"? What will you get then? Convert your strings 'text' and 'text2' to numbers with this: tonumber Link to comment
Addlibs Posted January 14, 2016 Share Posted January 14, 2016 local text2 = tonumber(guiGetText(GUIEditor.edit[1])) Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 function depoistMoney() local text = tonumber (guiGetText(GUIEditor.edit[2])) local text2 = tonumber(guiGetText(GUIEditor.edit[1])) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],tonumber(text + text2)) setTimer(takePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bankmoney",tonumber(text + text2)) elseif getPlayerMoney() == 0 then -- outputChatBox("You don't have enough money.") elseif getPlayerMoney() < 0 then outputChatBox("You can't deposit negative numbers.") end end end same problem please guys explain to me easy i'm learning attempt to perform arithmetic on local 'text2' ( a nill value) Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 GUIEditor.edit[1] = guiCreateEdit(11, 45, 444, 31,tostring(getElementData(localPlayer,"bankmoney")), false, GUIEditor.window[1]) function setZero() if guiGetText(GUIEditor.edit[1]) == "false" then guiSetText(GUIEditor.edit[1],"0$") end end addEventHandler("onClientRender",root,setZero) Link to comment
AMARANT Posted January 14, 2016 Share Posted January 14, 2016 You need to understand that you CAN'T add string values like "0$". It MUST be a number like 0. Your GUI labels contain data as strings so when you try to retrieve data from them it will be in a string format, not number. After that you add string to another string, but it's impossible. So convert your string to number with: tonumber(myString) Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 You need to understand that you CAN'T add string values like "0$". It MUST be a number like 0. Your GUI labels contain data as strings so when you try to retrieve data from them it will be in a string format, not number. After that you add string to another string, but it's impossible. So convert your string to number with: tonumber(myString) ye ye thanks u really u helped me alot <3 Thanks All Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 Guys There is way to add $ after the numbers ? Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 function withdrawMoney() local text = tonumber guiGetText(GUIEditor.edit[2]) local text2 = tonumber guiGetText(GUIEditor.edit[1]) if (guiRadioButtonGetSelected(GUIEditor.radiobutton[2])) then if tonumber(text2) >= tonumber(text) and tonumber(text) > 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],tonumber(text + text2)) setTimer(givePlayerMoney,2000,1,tonumber(text)) setElementData(localPlayer,"bankmoney",tonumber(text2 - text)) elseif tonumber(text2) < tonumber(text) then outputChatBox("You don't have enough money at bank.") elseif tonumber(text) < 0 then outputChatBox("You can't withdraw negative numbers.") end end end line 5 attempt to compare two nill values Link to comment
Best-Killer Posted January 14, 2016 Author Share Posted January 14, 2016 Sloved But there is way to add $ after the numbers ? Link to comment
Dealman Posted January 15, 2016 Share Posted January 15, 2016 What you're looking for is concatenation. In Lua you concatenate strings using .. "1000".."$" -- 1000$ Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 function depoistMoney() local text = tonumber (guiGetText(GUIEditor.edit[2])) local text2 = tonumber(guiGetText(GUIEditor.edit[1])) mb = text + text2 if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],mb) triggerServerEvent ("depoist", getLocalPlayer(), text) setAccountData(localPlayer,"bankmoney",mb) end end end now code but same problem Link to comment
1LoL1 Posted January 21, 2016 Share Posted January 21, 2016 function depoistMoney() local text = tonumber (guiGetText(GUIEditor.edit[2])) local text2 = tonumber(guiGetText(GUIEditor.edit[1])) mb = text + text2 if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],mb) triggerServerEvent ("depoist", getLocalPlayer(), text) setAccountData(localPlayer,"bankmoney",mb) end end end now code but same problem setAccountData is server-side function. Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 function depoistMoney() local text = tonumber (guiGetText(GUIEditor.edit[2])) local text2 = tonumber(guiGetText(GUIEditor.edit[1])) mb = text + text2 if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then guiSetText(GUIEditor.edit[1],"Transferring...") setTimer(guiSetText,2000,1,GUIEditor.edit[1],mb) triggerServerEvent ("depoist", getLocalPlayer(), text) setAccountData(localPlayer,"bankmoney",mb) end end end now code but same problem setAccountData is server-side function. already i did check this : https://forum.multitheftauto.com/viewtopic.php?f=91&t=95922 Link to comment
Recommended Posts