Resource:CallingFunctions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (prefer normal note)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Resource page}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{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.}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
__NOTOC__
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This resource was made off of the functions:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[CallClientFunction]]
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
and
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[CallServerFunction]]
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Calling Functions==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<section name="callSF" class="client" show="true">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua"> void exports.callingFunctions:callSF( string funcname, [ var arg1, ... ] ) </syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Required=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''funcname''': The name of the function that should be called serverside. May also be a function in a table, e.g. "math.round".
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Optional=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''agr1-argn''': The arguments that should be passed to the function.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Example=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This example removes the player from his team.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">-- get the local player element
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
local _local = getLocalPlayer()
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- define the leaveTeam command handler function
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
function cmdLeaveTeam()
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    -- set the player's team to nil
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    callServerFunction("setPlayerTeam", _local)
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- add the command handler
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
addCommandHandler("leaveTeam", cmdLeaveTeam, false)
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</section>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<section name="callCF" class="server" show="true">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua"> void exports.callingFunctions:callCF( client Client, string funcname, [ var arg1, ... ] ) </syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Required=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''Client''': The element of the player who should be affected.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''funcname''': The name of the function that should be called serverside. May also be a function in a table, e.g. "math.round".
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Optional=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''agr1-argn''': The arguments that should be passed to the function.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
=Example=
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This example sets the player's minute duration.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">-- define the onPlayerJoin handler function
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
function onPlayerJoin()
    -- set the minute duration
    callClientFunction(source, "setMinuteDuration", 10000)
end
-- add the event handler
addEventHandler("onPlayerJoin", root, onPlayerJoin)
</syntaxhighlight>
</section>
 
I give all thanks to Neon Black for making these functions.
==See Also==
*[http://community.mtasa.com/index.php?p=resources&s=details&id=4858 Download]
*[[callServerFunction]]
*[[callClientFunction]]

Latest revision as of 08:41, 7 September 2019

[[{{{image}}}|link=|]] 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.

This resource was made off of the functions: CallClientFunction and CallServerFunction

Calling Functions

Click to collapse [-]
callSF
 void 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 [-]
callCF
 void 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.

See Also