Resource:CallingFunctions: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (prefer normal note) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Resource page}} | {{Resource page}} | ||
{{ | {{Note|It is strongly advised that you validate the functions being called or potentially a client can do anything they want with your server - banning players, adding themselves as admin (depending how well your ACL is set up) etc. This is why this function is not built into MTA.}} | ||
__NOTOC__ | __NOTOC__ | ||
This resource was made off of the functions: | This resource was made off of the functions: | ||
Line 9: | Line 8: | ||
==Calling Functions== | ==Calling Functions== | ||
<section name="callSF" class=" | <section name="callSF" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> void exports.callingFunctions:callSF( string funcname, [ var arg1, ... ] ) </syntaxhighlight> | <syntaxhighlight lang="lua"> void exports.callingFunctions:callSF( string funcname, [ var arg1, ... ] ) </syntaxhighlight> | ||
=Required= | =Required= | ||
Line 16: | Line 15: | ||
*'''agr1-argn''': The arguments that should be passed to the function. | *'''agr1-argn''': The arguments that should be passed to the function. | ||
=Example= | =Example= | ||
<syntaxhighlight lang="lua"> | This example removes the player from his team. | ||
<syntaxhighlight lang="lua">-- get the local player element | |||
local _local = getLocalPlayer() | |||
-- define the leaveTeam command handler function | |||
function cmdLeaveTeam() | |||
-- set the player's team to nil | |||
callServerFunction("setPlayerTeam", _local) | |||
end | |||
-- add the command handler | |||
addCommandHandler("leaveTeam", cmdLeaveTeam, false) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
<section name="callCF" class=" | <section name="callCF" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> void exports.callingFunctions:callCF( client Client, string funcname, [ var arg1, ... ] ) </syntaxhighlight> | <syntaxhighlight lang="lua"> void exports.callingFunctions:callCF( client Client, string funcname, [ var arg1, ... ] ) </syntaxhighlight> | ||
=Required= | =Required= | ||
Line 27: | Line 35: | ||
*'''agr1-argn''': The arguments that should be passed to the function. | *'''agr1-argn''': The arguments that should be passed to the function. | ||
=Example= | =Example= | ||
<syntaxhighlight lang="lua"> | This example sets the player's minute duration. | ||
<syntaxhighlight lang="lua">-- define the onPlayerJoin handler function | |||
function onPlayerJoin() | |||
-- set the minute duration | |||
callClientFunction(source, "setMinuteDuration", 10000) | |||
end | |||
-- add the event handler | |||
addEventHandler("onPlayerJoin", root, onPlayerJoin) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Line 33: | Line 48: | ||
I give all thanks to Neon Black for making these functions. | I give all thanks to Neon Black for making these functions. | ||
==See Also== | ==See Also== | ||
[http://community.mtasa.com/index.php?p=resources&s=details&id=4858 Download] | *[http://community.mtasa.com/index.php?p=resources&s=details&id=4858 Download] | ||
[callServerFunction] | *[[callServerFunction]] | ||
[callClientFunction] | *[[callClientFunction]] |
Latest revision as of 08:41, 7 September 2019
This resource was made off of the functions: CallClientFunction and CallServerFunction
Calling Functions
Click to collapse [-]
callSFvoid exports.callingFunctions:callSF( string funcname, [ var arg1, ... ] )
Required
- funcname: The name of the function that should be called serverside. May also be a function in a table, e.g. "math.round".
Optional
- agr1-argn: The arguments that should be passed to the function.
Example
This example removes the player from his team.
-- get the local player element local _local = getLocalPlayer() -- define the leaveTeam command handler function function cmdLeaveTeam() -- set the player's team to nil callServerFunction("setPlayerTeam", _local) end -- add the command handler addCommandHandler("leaveTeam", cmdLeaveTeam, false)
Click to collapse [-]
callCFvoid exports.callingFunctions:callCF( client Client, string funcname, [ var arg1, ... ] )
Required
- Client: The element of the player who should be affected.
- funcname: The name of the function that should be called serverside. May also be a function in a table, e.g. "math.round".
Optional
- agr1-argn: The arguments that should be passed to the function.
Example
This example sets the player's minute duration.
-- define the onPlayerJoin handler function function onPlayerJoin() -- set the minute duration callClientFunction(source, "setMinuteDuration", 10000) end -- add the event handler addEventHandler("onPlayerJoin", root, onPlayerJoin)
I give all thanks to Neon Black for making these functions.