Client side scripts

From Multi Theft Auto: Wiki
Revision as of 15:38, 4 December 2006 by EAi (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

    <script src="race_clientside.lua" runat="client" />
    <script src="race_serverside.lua" />

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

Server side:

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


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