Jump to content

[HELP]setElementInterior


brocky

Recommended Posts

Posted

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) 

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

Posted

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.

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

Posted

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) 

Posted

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.

Posted

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]

Posted (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 by Guest
Posted
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 :)

Posted

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.

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