RU/Client side scripts: Difference between revisions
No edit summary |
No edit summary |
||
Line 35: | Line 35: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[en:Client side scripts]] | |||
[[it:Script client-side]] | [[it:Script client-side]] |
Revision as of 15:29, 27 June 2010
Клиентские скрипты - это те скрипты, которые исполняются непосредственно клиентской стороной мода. А значит, есть доступ к большому объему информации о игровом мире, но почти нет информации о других игроках в игре.
Это полезно для действий, которые нужно выполнить на клиентской стороне, например визуальные эффекты, создание и манипуляции с GUI.
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:
<!-- 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", true) addEventHandler("doShowObjectBrowser", getRootElement(), showObjectBrowser)
Server-side:
triggerClientEvent ( somePlayer, "doShowObjectBrowser", getRootElement(), 1034 )