Imposter Posted July 25, 2012 Share Posted July 25, 2012 i want it to check if the player has a value for bankMoney, if not then it sets it as 0 but i cant get it to work cause im a noob. serverside function checkBalance() playerName = getPlayerName(thePlayer) account = getPlayerAccount ( source ) bankMoney = getAccountData ( account, "bankcash" ) if ( bankMoney==nil ) then setAccountData ( account, "bankCash", 0 ) bankMoney=0 else outputChatBox ( "EagleBot: " .. playerName .. " has $" .. bankMoney .. " in his bank!" ) end end addCommandHandler ( "bank" , checkBalance ) Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 function checkBalance(thePlayer) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) if ( bankMoney==false ) then -- getAccountData returns false not nil, so check if false setAccountData ( account, "bankCash", 0 ) bankMoney=0 else outputChatBox ( "EagleBot: " .. getPlayerName(thePlayer) .. " has $" .. bankMoney .. " in his bank!" ) end end addCommandHandler ( "bank" , checkBalance ) Link to comment
Castillo Posted July 25, 2012 Share Posted July 25, 2012 You don't have "thePlayer" defined anywhere. Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 function checkBalance(thePlayer) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) if ( bankMoney==false ) then -- getAccountData returns false not nil, so check if false setAccountData ( account, "bankCash", 0 ) bankMoney=0 else outputChatBox ( "EagleBot: " .. getPlayerName(thePlayer) .. " has $" .. bankMoney .. " in his bank!" ) end end addCommandHandler ( "bank" , checkBalance ) What the hell...?? this is a retarded error..im using npp [2012-07-25 14:05:02] WARNING: Loading script failed: [roleplay]\bank\server.lua:2: unexpected symbol near 'Â' Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 I don't know try to write this line on your own. Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 I don't know try to write this line on your own. yea, i figured that is what happened, its all good now, thanks again AMARANT and SolidSnake14 Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 function checkBalance(thePlayer) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) if ( bankMoney==false ) then setAccountData ( account, "bankCash", 0 ) bankMoney=0 outputChatBox ("hi") else outputChatBox ("EagleBot: " .. getPlayerName(thePlayer) .. " has $" .. bankMoney .. " in his bank!" ) end end addCommandHandler ( "bank" , checkBalance ) function saveBalance() end addEventHandler ( "onPlayerQuit", getRootElement(), saveBalance ) function withdrawBalance() end function storeMoney( thePlayer, command, cash) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) local store = bankMoney+cash takePlayerMoney ( cash ) setAccountData ( account, "bankCash", store ) outputChatBox ( "You stored $" .. cash .. "in your bank!", thePlayer) end addCommandHandler ( "store" , storeMoney ) [2012-07-25 14:44:21] ERROR: [roleplay]\bank\server.lua:26: attempt to perform arithmetic on local 'bankMoney' (a boolean value) why am i getting an error? Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 You might have had an empty account data "bankMoney". Check if it saved correctly in your internal.db or by debug messages: function storeMoney( thePlayer, command, cash) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) local store = bankMoney+tonumber(cash) -- Convert string to number here. It might cause an error too. outputChatBox("DEBUG: bankMoney is: "..tostring(bankMoney)) takePlayerMoney ( cash ) setAccountData ( account, "bankCash", store ) outputChatBox ( "You stored $" .. cash .. "in your bank!", thePlayer) end addCommandHandler ( "store" , storeMoney ) Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 You might have had an empty account data "bankMoney". Check if it saved correctly in your internal.db or by debug messages: function storeMoney( thePlayer, command, cash) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) local store = bankMoney+tonumber(cash) -- Convert string to number here. It might cause an error too. outputChatBox("DEBUG: bankMoney is: "..tostring(bankMoney)) takePlayerMoney ( cash ) setAccountData ( account, "bankCash", store ) outputChatBox ( "You stored $" .. cash .. "in your bank!", thePlayer) end addCommandHandler ( "store" , storeMoney ) still not working, i tried it just now. [2012-07-25 15:59:01] ERROR: [roleplay]\bank\server.lua:26: attempt to perform arithmetic on local 'bankMoney' (a boolean value) Link to comment
Callum Posted July 25, 2012 Share Posted July 25, 2012 (edited) function checkBalance(thePlayer) local account = getPlayerAccount ( thePlayer ) local bankMoney = getAccountData ( account, "bankcash" ) if ( bankMoney==false ) then setAccountData ( account, "bankCash", 0 ) bankMoney=0 outputChatBox ("hi") else outputChatBox ("EagleBot: " .. getPlayerName(thePlayer) .. " has $" .. bankMoney .. " in his bank!" ) end end addCommandHandler ( "bank" , checkBalance ) function saveBalance() end addEventHandler ( "onPlayerQuit", getRootElement(), saveBalance ) function withdrawBalance() end function storeMoney( thePlayer, command, cash) local account = getPlayerAccount ( thePlayer ) if isGuestAccount ( account ) then return not outputChatBox ( "* Invalid account.", thePlayer, 255, 0, 0 ) end local bankMoney = getAccountData ( account, "bankcash" ) or 0 local store = bankMoney+cash takePlayerMoney ( cash ) setAccountData ( account, "bankCash", store ) outputChatBox ( "You stored $" .. cash .. "in your bank!", thePlayer) end addCommandHandler ( "store" , storeMoney ) Edited July 25, 2012 by Guest Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 Obviously your account data 'bankMoney" returns false. It means that there's no any data saved in your internal database. You should check that there's something in it or any script makes it set correctly. Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 Ok, i fixed that using serverside function storeMoney( thePlayer, command, cash) local account = getPlayerAccount ( thePlayer ) if isGuestAccount ( account ) then return not outputChatBox ( "* Invalid account.", thePlayer, 255, 0, 0 ) end if getPlayerMoney(thePlayer) >= tonumber(cash) then local bankMoney = getAccountData ( account, "bankCash" ) or 0 local store = bankMoney+cash takePlayerMoney ( thePlayer, cash ) setAccountData ( account, "bankCash", store ) outputChatBox ( "DEBUG: " .. store ) outputChatBox ( "You stored $" .. cash .. " in your bank!", thePlayer) else outputChatBox ( "You do not have $" .. cash ..", you have $" .. getPlayerMoney(thePlayer) .. " and are short by $" .. cash-getPlayerMoney(thePlayer), thePlayer) end end addCommandHandler ( "store" , storeMoney ) and I want to know how i can pass arguements to the serverside from clientside clientside local screenX, screenY = guiGetScreenSize() local width, height = 331,140 local x = (screenX/2) - (width/2) local y = (screenY/2) - (height/2) local lp = getLocalPlayer() bankwindow = guiCreateWindow(x,y,331,140,"Bank System",false) balancelbl = guiCreateLabel(18,31,170,20,"Your Balance :",false,bankwindow) cashlbl = guiCreateLabel(18,61,170,20,"Your Cash :",false,bankwindow) worktxt = guiCreateEdit(22,95,158,27,"",false,bankwindow) storebtn = guiCreateButton(186,93,52,31,"Deposit",false,bankwindow) withdrawbtn = guiCreateButton(248,93,70,31,"Withdraw",false,bankwindow) guiWindowSetSizable(bankwindow,false) guiSetVisible (bankwindow, false) function resourceStart () bindKey ("j", "down", menuShow) end addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart) function menuShow () visableornot = guiGetVisible (bankwindow) if (visableornot == true) then guiSetVisible (bankwindow, false) showCursor (false) end if (visableornot == false) then guiSetVisible (bankwindow, true) showCursor (true) end end function guiClick (button, state, absoluteX, absoluteY) if (source == storebtn) then triggerServerEvent ("withdraw", lp) elseif (source == withdrawbtn) then triggerServerEvent ("deposit", lp) end end addEventHandler("onClientRender",root, function() dxDrawText("$01234567",1080.0,159.0,1281.0,214.0,tocolor(37,110,37,255),1.8,"pricedown","left","top",false,false,false) end ) so when i click store, it sends the amount of cash entered in the editbox to the server so i can use my function that i made, how do I do this? Link to comment
Callum Posted July 25, 2012 Share Posted July 25, 2012 Look into using events to transfer data between the server and client. Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 You have to create a function server-side which receives arguments from client-side. In client-side function you have to pass required arguments. Something like this: triggerServerEvent ("withdraw", lp, cash) -- All needed arguments can be passed after lp (local player which will be 'source' of the server function. 'cash' might be your argument representing your money to be received from client.) Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 would this work if i wanted to send the bankmoney to the clientside??? server side triggerClientEvent( "menuShow", getRootElement(), cash ) clientside addEvent("menuShow", true ) function menuShow ( thePlayer, cash ) visableornot = guiGetVisible (bankwindow) if (visableornot == true) then guiSetVisible (bankwindow, false) showCursor (false) end if (visableornot == false) then guiSetText ( balancelbl, "Your Balance : $" .. cash ) guiSetVisible (bankwindow, true) showCursor (true) end end addEventHandler("menuShow", getRootElement(), menuShow) Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 I'll explain it via comments: Server side: triggerClientEvent( "menuShow", getRootElement(), cash ) -- Instead of getRootElement() you should define your specific player if you want to show it to him. Root element will show you window to everyone. 'cash' is your money argument. It can be whatever you want. Client side: addEvent("menuShow", true ) function menuShow ( thePlayer, cash ) -- 'thePlayer' is unnecessary variable here. It should be just menuShow ( cash ). 2nd argument from server-side will be 'source' of your client-side function so it's not required here. Leave here just 'cash'. visableornot = guiGetVisible (bankwindow) if (visableornot == true) then guiSetVisible (bankwindow, false) showCursor (false) end if (visableornot == false) then guiSetText ( balancelbl, "Your Balance : $" .. cash ) guiSetVisible (bankwindow, true) showCursor (true) end end addEventHandler("menuShow", getRootElement(), menuShow) -- I use here getLocalPlayer() as a rule. Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 OK i got it all working, but i dont understand why this isnt working, the buttons arent even outputting the text function guiClick (button, state, absoluteX, absoluteY) local cash = guiGetText (worktxt) if (source == storebtn) then outputChatBox("should work...") triggerServerEvent ("withdraw", lp, cash) elseif (source == withdrawbtn) then outputChatBox("should work...") triggerServerEvent ("deposit", lp, cash) end end Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 There's no event for your function. It should be like this: addEventHandler("onClientGUIClick",getRootElement(), function () local cash = guiGetText (worktxt) if (source == storebtn) then outputChatBox("should work...") triggerServerEvent ("withdraw", lp, cash) end if (source == withdrawbtn) then outputChatBox("should work...") triggerServerEvent ("deposit", lp, cash) end end) Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 There's no event for your function. It should be like this: addEventHandler("onClientGUIClick",getRootElement(), function () local cash = guiGetText (worktxt) if (source == storebtn) then outputChatBox("should work...") triggerServerEvent ("withdraw", lp, cash) end if (source == withdrawbtn) then outputChatBox("should work...") triggerServerEvent ("deposit", lp, cash) end end) thanks to you i successfully made it, you are like a brother but just one more thing, you know how when you add a handler as onResourceStart, why does it do it when other resources start, can it do it only when the same resource starts? Link to comment
AMARANT Posted July 25, 2012 Share Posted July 25, 2012 You mean this? addEventHandler( "onClientResourceStart", getRootElement( ), function ( startedRes ) if startedRes==getThisResource() then -- Some stuff... end end ) Link to comment
Imposter Posted July 25, 2012 Author Share Posted July 25, 2012 You mean this? addEventHandler( "onClientResourceStart", getRootElement( ), function ( startedRes ) if startedRes==getThisResource() then -- Some stuff... end end ) this can be used for server side too? 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