• attempt to perform arithmetic
    18 replies, posted
Hi, I have a big problem, I develop a bank system, so I need a button to transfer money from the inventory to the bank, but I have this error. attempt to perform arithmetic "monaywanttransfered" <a nill value> [U]Client-Side:[/U] local transfertenum = vgui.Create("DNumberWang", f) transfertenum:SetDecimals(0) transfertenum:SetKeyboardInputEnabled(true) transfertenum:SetSize(210,30) transfertenum:Center() local transferenum_button = vgui.Create( "DButton", f) transferenum_button:SetPos( 335, 190 ) transferenum_button:SetSize( 90, 15 ) transferenum_button:SetText("") local transfer_name = vgui.Create("DLabel", transferenum_button) transfer_name:SetPos(5,2) transfer_name:SetSize(70, 10) transfer_name:SetFont("default") transfer_name:SetText("VALIDATE") transfer_name:SetTextColor( Color(250, 250, 250, 255) ) transferenum_button.DoClick = function() net.Start("Transfer_To_Bank") moneywanttransfered = transfertenum:GetValue() net.WriteString(tostring( moneywanttransfered)) net.SendToServer() end transferenum_button.Paint = function() SKINS:DrawFrame(transferenum_button:GetWide(), transferenum_button:GetTall()) end [U]Server-Side[/U] net.Receive("Transfer_To_Bank", function(len, ply) local name = net.ReadString() local item = getItems( name ) local currentmoneybank = ply:databaseGetValue( "moneybank" ) local currentmoney = ply:databaseGetValue( "money" ) ply:databaseSetValue( "money", currentmoney + moneywanttransfered ) ply:databaseSetValue( "moneybank", currentmoneybank - moneywanttransfered ) ply:PrintMessage( HUD_PRINTTALK, "[BANK] You have transfered: "..moneywanttransfered.." RU , in your inventory." ) end) Please help me I try a lot of things, nothing works
Your Transfer_To_Bank net message writing doesn't make sense. You're writing "moneywanttransfered", but you're reading it as "name" serverside then still accessing "moneywanttransfered" without declaring it.
Why are you sending a string instead of a double or integer? What you're doing is very inefficient.
[U]code_gs: [/U] Thank you for your comment, I should not use "string" then? [U]LegoGuy:[/U] Thanks you, I just want to get back the amount that the players type and send it to the server-side, I only learned this way
Send and read it as a number
Yes I thank you, but I can not find the right "net." i try a lot of net. wiki...
Try net.Read/WriteDouble
You should also be checking if they have enough money in their bank before you change any values server side. Anyone who bypasses sv_allowcslua can run that net message and give them self any amount of money even if they don't have enough stored in their bank. Unless you're checking it inside the ply:databaseSetValue function
Actually I know that players can exploit, but first I wanted to solve the problem of the net. Thank you even for your comment, and I will try the "WriteDouble" said above. EDIT: WriteDouble = same error...
[QUOTE=swarshilder;51980664]Actually I know that players can exploit, but first I wanted to solve the problem of the net. Thank you even for your comment, and I will try the "WriteDouble" said above. EDIT: WriteDouble = same error...[/QUOTE] Because you're not [I]reading[/I] it properly!
[QUOTE=LegoGuy;51980840]Because you're not [I]reading[/I] it properly![/QUOTE] Sorry I still learn, if it was possible to have a very basic example you would be great..
Dude, it's very simple In your server-side code, you have this line: [lua] ply:databaseSetValue( "money", currentmoney + moneywanttransfered )[/lua] Yet you never defined [I]moneywanttransfered[/I]. What is [I]moneywanttransfered [/I]?
[I]"moneywanttransfered = transfertenum:GetValue()" [/I]define after my [I]"net.Start("Transfer_To_Bank")"[/I] // I would just like to know how to recover the encrypted value in "DNumberWang" and apply it to the player's data, please... I have been searching for days.. //
[QUOTE=swarshilder;51988600][I]"moneywanttransfered = transfertenum:GetValue()" [/I]define after my [I]"net.Start("Transfer_To_Bank")"[/I] [/QUOTE] You do that on the client, not on the server
Thanks you very much i try again
Your messages did not make much progress but for the future developer I will note the solution! [B]CLIENT SIDE[/B] transferenum_button.DoClick = function() [B]// button[/B] local datatowrite = {} [B]// table[/B] datatowrite.moneywanttransfered = transfertenum:GetValue() [B]//table[/B] net.Start("Transfer_To_Bank") [B]// server-side[/B] net.WriteTable(datatowrite) [B] // stock table[/B] net.SendToServer() [B]// send[/B] end [B]SERVER SIDE[/B] util.AddNetworkString( "Transfer_To_Bank")[B] // comunication client to server[/B] net.Receive("Transfer_To_Bank", function(len, ply) local datatowrite = net.ReadTable() local name = net.ReadString() local item = getItems( name ) local currentmoneybank = ply:databaseGetValue( "moneybank" ) local currentmoney = ply:databaseGetValue( "money" ) local minimumtransfer = 100 ply:databaseSetValue( "money", currentmoney + datatowrite.moneywanttransfered ) // [B]use table[/B] ply:databaseSetValue( "moneybank", currentmoneybank - datatowrite.moneywanttransfered ) // [B]use table[/B] ply:PrintMessage( HUD_PRINTTALK, "[BANK] You have transfered: "..datatowrite.moneywanttransfered.." RU , in your inventory." ) end)
You wrote "moneywanttransfered" as a string when sending via net, and then read it as name, and then attempted to add a string to a number. Also, you tried to read a variable on the serverside when it was set clientside. You need to learn basic lua before you try and make a banking system.
[QUOTE=swarshilder;51993398]Your messages did not make much progress but for the future developer I will note the solution! [/QUOTE] What is it with French people and assuming they were right, and that the people they were seeking help from are wrong? By the way your solution is horrible. You're using the most expensive way to transfer data when you could just send a single number. You should really use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteInt]net.WriteInt[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/ReadInt]net.ReadInt[/url] instead
[QUOTE=JasonMan34;51995071]What is it with French people and assuming they were right, and that the people they were seeking help from are wrong? By the way your solution is horrible. You're using the most expensive way to transfer data when you could just send a single number. You should really use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteInt]net.WriteInt[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/ReadInt]net.ReadInt[/url] instead[/QUOTE] Thanks you very much
Sorry, you need to Log In to post a reply to this thread.