AddRemoteEvent: Difference between revisions
From Onset Developer Wiki
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | <syntaxhighlight lang="Lua"> | ||
-- This example calls the remote event from the server side to the client side | |||
-- Client side | -- Client side | ||
AddRemoteEvent("SetWeather", function(weatherid) | AddRemoteEvent("SetWeather", function(weatherid) | ||
Line 21: | Line 22: | ||
AddCommand("we", function(playerid, weatherid) | AddCommand("we", function(playerid, weatherid) | ||
CallRemoteEvent(playerid, "SetWeather", weatherid) | CallRemoteEvent(playerid, "SetWeather", weatherid) | ||
end) | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="Lua"> | |||
-- This example calls the remote event from the client side to the server side | |||
-- Client side | |||
AddEvent("OnKeyPress", function(key) | |||
if key == 'R' then | |||
CallRemoteEvent("OnClientRadio") | |||
end | |||
end) | |||
-- Server side | |||
AddRemoteEvent(playerid, "OnClientRadio", function() | |||
AddPlayerChat(playerid, "Client activated radio") | |||
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 12:52, 19 November 2019
Description
The remote event to call from either server to client or vice versa.
Syntax
AddRemoteEvent(RemoteEventName, LuaFunction)
Parameters
- RemoteEventName
The remote event name. - LuaFunction
The lua function.
Return Value
- This function has no specific return value.
Example
-- This example calls the remote event from the server side to the client side
-- Client side
AddRemoteEvent("SetWeather", function(weatherid)
SetWeather(weatherid)
end)
-- Server side
AddCommand("we", function(playerid, weatherid)
CallRemoteEvent(playerid, "SetWeather", weatherid)
end)
-- This example calls the remote event from the client side to the server side
-- Client side
AddEvent("OnKeyPress", function(key)
if key == 'R' then
CallRemoteEvent("OnClientRadio")
end
end)
-- Server side
AddRemoteEvent(playerid, "OnClientRadio", function()
AddPlayerChat(playerid, "Client activated radio")
end)