Client side scripts: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Minor updates)
Line 1: Line 1:
Client side scripts are scripts that run inside the deathmatch mod client side. This means that have access to more information about the game world, but slightly less information about the rest of the players in the game.
Client side scripts are scripts that run inside the deathmatch mod client side. This means that have 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 things like the creation and manipulation of GUI elements.
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?==
==How does it work?==
Line 15: Line 15:
</syntaxhighlight>
</syntaxhighlight>


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 ( player, "eventName", element, args ... ) which will trigger the event client side. The same will be able to be done in reverse.
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 ( player, "eventName", fromElement, args ... ) which will trigger the event client side. The same can be done in reverse using triggerServerEvent.


For example:
For example:
Line 21: Line 21:
'''Client side:'''
'''Client side:'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEvent("ShowObjectBrowser", "id")
addEventHandler("ShowObjectBrowser", getRootElement(), "showObjectBrowser")
function showObjectBrowser(id)
function showObjectBrowser(id)
   -- code here
   -- code here
end
end
addEvent("doShowObjectBrowser")
addEventHandler("doShowObjectBrowser", getRootElement(), showObjectBrowser)
</syntaxhighlight>
</syntaxhighlight>
'''Server side:'''
'''Server side:'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
triggerClientEvent ( source, "ShowObjectBrowser", getRootElement(), 1034 )
triggerClientEvent ( somePlayer, "ShowObjectBrowser", getRootElement(), 1034 )
</syntaxhighlight>
</syntaxhighlight>

Revision as of 12:25, 23 August 2007

Client side scripts are scripts that run inside the deathmatch mod client side. This means that have 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- 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:

<!-- GUI (client) testing script -->
<meta>
	<script src="guitest.lua" type="client" />
	<info author="IJs" />
</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 ( player, "eventName", fromElement, args ... ) 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")
addEventHandler("doShowObjectBrowser", getRootElement(), showObjectBrowser)

Server side:

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