Client side scripts: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 25: Line 25:


For example:
For example:
'''Client side:'''
'''Client side:'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Revision as of 16:45, 9 December 2006

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.

Why are we implementing client scripts now?

We had planned to do client scripts in a future release, but its become apparent that it may be the fastest way to make a new editor for deathmatch. The alternatives we've got for the editor are:

  • Hack the race editor to work with DM: This is possible, but would take a lot of work. The editor currently doesn't even compile with the dm code base and it doesn't support many things that are in dm. The old race editor is a mess code-wise and as a consequence really needs a rewrite to add anything new to it.
  • Write a new editor using wxwidgets. This would be ideal, but its clear that this is actually a larger task than we envisioned. We may do this in the future, but we don't have the time right now if we want a release within the next month or so.
  • Implement an editor in server side scripts. This could work, but the server is not really aware enough of the client to make it a smooth enough experience. This would be the fastest to do, much of this has already been done.
  • Implement client scripts. This is what we intend to do. The advantages are that its something we intended to do in the future anyway, it hopefully won't take too long and we can "open source" the editor script and allow QA to help us write it. This allows us to focus on just writing functionality client and server side, while letting 3rd parties write our scripts for us!

How will it work?

It is intended that client side scripts will follow the same pattern as server side scripts. We will provide as many as the same functions client side as exist server side, and we'll provide a simple way of interfacing between the two halves of a script, using the same event system as we already have. Client and server scripts will either have to be in two separate .lua files or within the .map file in a <script> tag.

For example:

<map>
    <script src="race_clientside.lua" runat="client" />
    <script src="race_serverside.lua" />
    <script runat="client">
       -- some map specific code here
    </script>
</map>

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.

For example:

Client side:

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

Server side:

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

More?

First draft, pester me (eAi) to answer anything I've missed or isn't clear.

  • Perfect. I don't know if it was mentioned before, but it would be really good to have extended camera movement (not like normal in game). So that you can move up, down, forward and so on with keys and move the place where camera looks at with mouse. --DracoBlue 10:53, 4 December 2006 (CST)