brocky Posted November 6, 2015 Share Posted November 6, 2015 I have problem with my code "It doesn't let you to go to the specified interior and x, y, z position. I have made a GUI with edits and for interior it is called "IntEdit" and for X it is intx , for Y it is inty, for Z it is intz. This code doesn't works. intEdit = guiCreateEdit(111, 147, 166, 22, "", false, window1) intx = guiCreateEdit(110, 170, 167, 22, "", false, window1) inty = guiCreateEdit(111, 193, 170, 21, "", false, window1) intz = guiCreateEdit(109, 214, 178, 19, "", false, window1) function buttonDo() if buttonEnter == source then setElementInterior(localPlayer, intEdit, intx, inty, intz ) end end addEventHandler("onClientGUIClick", buttonEnter, buttonDo, false) Link to comment
Aristates Posted November 6, 2015 Share Posted November 6, 2015 addEventHandler("onClientResourceStart", root, function() intEdit = guiCreateEdit(111, 147, 166, 22, "", false, window1) intx = guiCreateEdit(110, 170, 167, 22, "", false, window1) inty = guiCreateEdit(111, 193, 170, 21, "", false, window1) intz = guiCreateEdit(109, 214, 178, 19, "", false, window1) end) addEventHandler("onClientGUIClick", root, function() if source == Button then intEditBox = guiGetText(intEdit) intxBox = guiGetText(intx) intyBox = guiGetText(inty) setElementInterior(localPlayer, tostring(intEditBox), tostring(intxBox), tostring(intyBox), tostring(intzBox) ) end end ) Link to comment
brocky Posted November 6, 2015 Author Share Posted November 6, 2015 I have a problem with my code, and its like I made an edit window which is set to variable "intPrice" and now I converted using "guiGetText" to "textPrice". The problem is that I want to take the exact amount of money that the player entered in "textPrice" and the problem is that "takePlayerMoney" is server sided.How is it possible to call the "textPrice" in server side so I CAN TAKE THE MONEY. This is how I did it and it doesn't works. buttonBuy = guiCreateButton(9, 297, 130, 26, "Buy House", false, window2) intPrice = guiCreateEdit(114, 294, 178, 22, "", false, window1) textPrice = guiGetText ( intPrice ) local theMoney = tonumber ( textPrice ) function buyApart() if buttonBuy == source then playerMoney = getPlayerMoney(localPlayer) if playerMoney >= theMoney then guiSetEnabled(buttonSell, true) outputChatBox("House Bought", 24, 247, 7, true) triggerServerEvent("takingMoney", localPlayer) else outputChatBox("Insufficient cash.", 249, 10, 4 ) end end end addEventHandler("onClientGUIClick", buttonBuy, buyApart, false) Server side :- function takeMoney() takePlayerMoney(source, textPrice) end addEvent("takingMoney", true) addEventHandler("takingMoney", getRootElement(), takeMoney) Hope you understood my problem. Link to comment
Aristates Posted November 6, 2015 Share Posted November 6, 2015 buttonBuy = guiCreateButton(9, 297, 130, 26, "Buy House", false, window2) intPrice = guiCreateEdit(114, 294, 178, 22, "", false, window1) local theMoney = tonumber ( textPrice ) function buyApart() if buttonBuy == source then playerMoney = getPlayerMoney(localPlayer) if playerMoney >= theMoney then guiSetEnabled(buttonSell, true) outputChatBox("House Bought", 24, 247, 7, true) textPrice = guiGetText ( intPrice ) if textPrice ~= "" then triggerServerEvent("takingMoney", localPlayer, textPrice) else outputChatBox("Insufficient cash.", 249, 10, 4 ) end end end addEventHandler("onClientGUIClick", buttonBuy, buyApart, false) function takeMoney(textPrice) takePlayerMoney(source, textPrice) end addEvent("takingMoney", true) addEventHandler("takingMoney", getRootElement(), takeMoney) Link to comment
brocky Posted November 6, 2015 Author Share Posted November 6, 2015 It says "textPrice" is a string in the server-side. Can you even explain it with comments a bit? Link to comment
Aristates Posted November 6, 2015 Share Posted November 6, 2015 (edited) I'm using would trigger a number value. Edited November 6, 2015 by Guest Link to comment
Dealman Posted November 6, 2015 Share Posted November 6, 2015 Because much like the name suggests, guiGetText gets the text - a string. String is not a number. You can however try and convert a string to a number like this; local theValue = tonumber(textPrice) Link to comment
brocky Posted November 6, 2015 Author Share Posted November 6, 2015 I know that, but what I am trying to say is that I want "that" number value and take it to the server side and excecute it but server side doesn't recognize it. Link to comment
Dealman Posted November 6, 2015 Share Posted November 6, 2015 takePlayerMoney(client, tonumber(textPrice)) Link to comment
brocky Posted November 7, 2015 Author Share Posted November 7, 2015 First of all ! takePlayerMoney is server sided! You can't use it on client side script! 2nd is that I made an Edit to input the amount of money that you want and I call it "textPrice" and it is in Client side. Now if a player clicks buyApart then the script will take the amount of money used in "textPrice" edit. but "the server side" doesn't recognize "textPrice" because it is in Client side and thats why "takePlayerMoney" doesn't recognize "textPrice" because I defined it in client side and server side doesn't know what is it. Understood? Thats my problem and here is the debugscript 3 decision. WARNING: [script]Test\server.lua:2: Bad argument @ 'takePlayerMoney' [Expected number at argument 2, got nil] Link to comment
Dealman Posted November 7, 2015 Share Posted November 7, 2015 That's because you need to use triggerServerEvent to transfer information/data from the client to the server. Read that page thoroughly and I'm sure you'll figure it out Link to comment
brocky Posted November 7, 2015 Author Share Posted November 7, 2015 Ok, lemme try something new on it, If it didn't work then I will "EDIT" this post. Link to comment
Rockyz Posted November 7, 2015 Share Posted November 7, 2015 (edited) its should works buttonBuy = guiCreateButton(9, 297, 130, 26, "Buy House", false, window2) intPrice = guiCreateEdit(114, 294, 178, 22, "", false, window1) addEventHandler("onClientGUIClick", resourceRoot, function ( ) if ( source == buttonBuy ) then local gTEXT = tonumber ( guiGetText ( intPrice ) ) if ( getPlayerMoney ( localPlayer ) >= gTEXT ) then guiSetEnabled(buttonSell, true) outputChatBox("House Bought", 24, 247, 7, true ) triggerServerEvent("takingMoney", localPlayer, gTEXT ) else outputChatBox("Insufficient cash.", 249, 10, 4, true ) end end end ) addEvent("takingMoney", true) addEventHandler("takingMoney", resourceRoot, function ( gTEXT ) takePlayerMoney ( source, gTEXT ) end ) Edited November 8, 2015 by Guest Link to comment
Dealman Posted November 7, 2015 Share Posted November 7, 2015 if ( ( getPlayerMoney ( localPlayer ) >= gTEXT ) and ( gTEXT ~= "" ) and ( gTEXT ~= " " ) ) then This line is entirely unnecessary. You've already converted it to a number, why check if it equals "" or " "? Those 2 if statements would always return false Link to comment
brocky Posted November 8, 2015 Author Share Posted November 8, 2015 Thanks, you all helped, I read the wiki about "triggerServerEvent" and I had to add the 3rd optionals argument to send the "textPrice" element to server so that it will recognize it but Thanks to everybody. 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