Client side scripts: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Reverted edits by Marcin778 (talk) to last revision by AlexTMjugador)
Line 1: Line 1:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
Client side scripts are scripts that run inside the deathmatch mod client side. This means that the game has access to more information about the game world, but slightly less information about the rest of the players in the game.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This is useful for things that need to be done client side, such as visual effects, creation and manipulation of GUI elements.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==How does it work?==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
Client side scripts follow the same pattern as server side scripts. We will try to provide the necessary functionality for client side scripts. Interfacing between a server side and client side script is done by using the same event system as we already have. The server side and client side scripts will need to be in two different files, which are included from the resource (in the metafile) by using a <script> tag (and type attribute).
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
For example:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
'''meta.xml'''
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="xml">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<meta>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<script src="c_gui.lua" type="client" />
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<script src="s_gui.lua" type="server" />
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</meta>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
If you wanted to trigger a client side event from the server, you would first have to register the client side event using [[addEvent]]. Then, you can attach a handler to the event as you would in a server side script. Then in the server side script, you'll be able to call [[triggerClientEvent]], which will trigger the event client side. The same can be done in reverse using [[triggerServerEvent]].
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
For example:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
'''Client side'''
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
function showObjectBrowser ( id )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- code here
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
addEvent( "doShowObjectBrowser", true )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
addEventHandler( "doShowObjectBrowser", getRootElement(), showObjectBrowser )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
'''Server side'''
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
triggerClientEvent ( somePlayer, "doShowObjectBrowser", getRootElement(), 1034 )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[Category:Scripting Concepts]]
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[ru:Client side scripts]]
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[it:Script client-side]]
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
[[es:Scripts de Cliente]]

Revision as of 18:38, 1 January 2017

Client side scripts are scripts that run inside the deathmatch mod client side. This means that the game has access to more information about the game world, but slightly less information about the rest of the players in the game.

This is useful for things that need to be done client side, such as visual effects, creation and manipulation of GUI elements.

How does it work?

Client side scripts follow the same pattern as server side scripts. We will try to provide the necessary functionality for client side scripts. Interfacing between a server side and client side script is done by using the same event system as we already have. The server side and client side scripts will need to be in two different files, which are included from the resource (in the metafile) by using a <script> tag (and type attribute).

For example:

meta.xml

<meta>
	<script src="c_gui.lua" type="client" />
	<script src="s_gui.lua" type="server" />
</meta>

If you wanted to trigger a client side event from the server, you would first have to register the client side event using addEvent. Then, you can attach a handler to the event as you would in a server side script. Then in the server side script, you'll be able to call triggerClientEvent, which will trigger the event client side. The same can be done in reverse using triggerServerEvent.

For example:

Client side

function showObjectBrowser ( id )
	-- code here
end
addEvent( "doShowObjectBrowser", true )
addEventHandler( "doShowObjectBrowser", getRootElement(), showObjectBrowser )

Server side

triggerClientEvent ( somePlayer, "doShowObjectBrowser", getRootElement(), 1034 )