Kamycz3q Posted March 6, 2020 Share Posted March 6, 2020 Error: Photo Server.Lua function bank(gracz) konto = getPlayerAccount(gracz) if konto then return getAccountData(konto, "bank.balance") end end addEvent("bank-hajs-panel",true) addEventHandler("bank-hajs-panel",getRootElement(), bank) Client.Lua function schowajgui() destroyElement(initBrowser) showCursor(false) initBrowser = nil end function pokazgui(gracz) if initBrowser == nil then setElementFrozen(getRootElement(), true) --In order to render the browser on the full screen, we need to know the dimensions. local screenWidth, screenHeight = guiGetScreenSize() --Let's create a new browser in local mode. We will not be able to load an external URL. initBrowser = guiCreateBrowser(screenWidth/4, screenHeight/4, screenWidth, screenHeight, true, true, false) local theBrowser = guiGetBrowser(initBrowser) --This is the function to render the browser. --The event onClientBrowserCreated will be triggered, after the browser has been initialized. --After this event has been triggered, we will be able to load our URL and start drawing. addEventHandler("onClientBrowserCreated", theBrowser, function() --After the browser has been initialized, we can load our file. loadBrowserURL(theBrowser, "http://mta/local/html/index.html") --Now we can start to render the browser. bank = triggerServerEvent("bank-hajs-panel", getLocalPlayer()) addEventHandler("onClientBrowserDocumentReady", theBrowser, function () bank = triggerServerEvent("bank-hajs-panel", getLocalPlayer()) executeBrowserJavascript(source, "document.getElementById('gotowka').innerHTML = '"..getPlayerMoney(getLocalPlayer()).."$'"); executeBrowserJavascript(source, "document.getElementById('Witamy__nazwa_gracza').innerHTML = 'Witamy "..getPlayerName(getLocalPlayer()).."!'"); executeBrowserJavascript(source, "document.getElementById('bank').innerHTML = '"..tostring(bank).."$'"); end) end ) else schowajgui() end end bindKey("F5", "down", pokazgui) bindKey("escape", "down", schowajgui) addEvent( "pokazgui_panel", true ) addEventHandler( "pokazgui_panel", getRootElement(), pokazgui) Link to comment
Maark Posted March 8, 2020 Share Posted March 8, 2020 first, use code <> to fix the problem, you need put the player in arguments to get account data bool triggerServerEvent ( string event, element theElement, [arguments...] ) code fixed: bank = triggerServerEvent("bank-hajs-panel", localPlayer, localPlayer) (you are sending the event to localPlayer, and sending the localPlayer in arguments to get the data.) if i help u, give a thanks pls! Link to comment
Addlibs Posted March 8, 2020 Share Posted March 8, 2020 (edited) You cannot return information from the server side this way. You need the server to trigger a client event back with the balance amount. The client should be something like this: -- ... triggerServerEvent("bank-hajs-panel", localPlayer) -- request balance from the server addEventHandler("onClientBrowserDocumentReady", theBrowser, function () bank = triggerServerEvent("bank-hajs-panel", localPlayer) executeBrowserJavascript(source, "document.getElementById('gotowka').innerHTML = '"..getPlayerMoney(localPlayer).."$';") executeBrowserJavascript(source, "document.getElementById('Witamy__nazwa_gracza').innerHTML = 'Witamy "..getPlayerName(localPlayer).."!';") executeBrowserJavascript(source, "document.getElementById('bank').innerHTML = 'Loading...';") -- display a placeholder while we're waiting for the server to return the balance end ) -- ... -- this should be at top level scope, outside any functions addEvent("bank-hajs-balans", true) addEventHandler("bank-hajs-balans", localPlayer, -- server triggers this event sending over the balance function(bank) if initBrowser then -- we only want to continue if the player hasn't hid the panel in the meantime local theBrowser = guiGetBrowser(initBrowser) executeBrowserJavascript(theBrowser, "document.getElementById('bank').innerHTML = '$"..tostring(bank).."';") -- update player's displayed balance end end ) The server should look like this: function bank() local konto = getPlayerAccount(client) -- account of the client who sent the event to the server if konto then triggerClientEvent(client, "bank-hajs-balans", client, getAccountData(konto, "bank.balance")) end end addEvent("bank-hajs-panel", true) addEventHandler("bank-hajs-panel", root, bank) Edited March 8, 2020 by MrTasty 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