Jump to content

[Help] Is there any way, to do server-side sruff when clicked client-side gui button?


Kazafka

Recommended Posts

8 minutes ago, stPatrick said:

on gui click -> trigger server event -> trigger client event back -> do what you want

Okay, I have now another idea, right? So, how can I make a function, that returns values, that will be set by clicking button? ALL IN CLIENT!!!

@stPatrick what do you think 'bout this? /\ /\ /\

Edited by VaporZ
Link to comment
  • Moderators
7 minutes ago, VaporZ said:

I tried it, but I still wanted to operate these values from client, in functions that return something on server

-- CLIENT

addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function()
    local some_button_data = 5
    triggerServerEvent("doServerFunction", localPlayer, some_button_data)
end)

addEvent("doServerFunction:receiveResults", true)
addEventHandler("doServerFunction:receiveResults", localPlayer, function(results_from_server_data)
    outputChatBox(results_from_server_data) -- print: 10
end)


addEvent("doServerFunction", true)
addEventHandler("doServerFunction", root, function(data_from_client)
    local need_to_return_this = data_from_client * 2 -- do some magic here
    triggerClientEvent(source, "doServerFunction:receiveResults", source, need_to_return_this)
end)

 

Need to do like this.

Edited by stPatrick
Link to comment
1 minute ago, stPatrick said:

Need to do like this.

KK, but how can I return data in different function, set by clicking a button? <<< ALL IN CLIENT!!!

1 minute ago, stPatrick said:

 

'k, but how can I return data by clicking a button?

 

Sorry for multiple questions in one comment, but my final is: How can I return data by clicking a button? CLIENT

Link to comment
5 minutes ago, IIYAMA said:

From where are you returning that data?

Example:

You have made a scrollbar and you want to return scrollbar position to some variables by clicking button, I mean, some other scripts' variables. Like exports....

That's what I wanna get to my knowledge

Edited by VaporZ
Link to comment
  • Moderators

 

2 scripts, within the same resource

 

You can either use globals:

some_button_data = 5

 

addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function()
    
	iprint(some_button_data)
end)

 

Or return values:

local some_button_data = 5
function getData ()
	return some_button_data
end

 

addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function()
	local some_button_data = getData()
end)

 

And if you are dealing with multiple resources, you can use exports:

Resource 1

<!-- meta.xml -->
<export function="getData" type="client"/> 
local some_button_data = 5
function getData ()
	return some_button_data
end

Resource 2

addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function()
    local some_button_data = exports["resourceName"]:getData ()
end)

 

 

 

 

 

 

 

 

 

Link to comment

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