|
| 1 | +<p align="center"> |
| 2 | +<img src="https://infinixi.us/sourcemod.js/assets/logo_shadow.png"> |
| 3 | +</p> |
| 4 | + |
| 5 | +A JavaScript wrapper over SourceMod. |
| 6 | + |
| 7 | +# Installation |
| 8 | +``` |
| 9 | +npm install sourcemod.js |
| 10 | +``` |
| 11 | + |
| 12 | +First of all, install [MetaMod: Source](https://www.sourcemm.net/) and [SourceMod](https://www.sourcemod.net/) onto your Source server. Any version over **1.10** should work. Run your server and ensure SourceMod is working by running `sm version`. |
| 13 | + |
| 14 | +Head over to the [releases](https://github.com/Infinixius/sourcemod.js/releases), and grab the latest plugin download. Drop it in `tf\addons\sourcemod\plugins`. |
| 15 | + |
| 16 | +The plugin also uses [clugg's `sm-json`](https://github.com/clugg/sm-json) and [peace-maker's `sm-websocket`](https://github.com/peace-maker/sm-websocket) to communicate with the JavaScript plugin over WebSockets. Go ahead and install them to your server. |
| 17 | + |
| 18 | +You should see the following if it worked: |
| 19 | +``` |
| 20 | +[SMJS] sourcemod.js loaded! |
| 21 | +[SMJS] Started WebSocket server on port 12345! |
| 22 | +``` |
| 23 | + |
| 24 | +You can also run the console command `smjs_test`: |
| 25 | +``` |
| 26 | +[SMJS] Test! |
| 27 | +``` |
| 28 | + |
| 29 | +# Examples |
| 30 | + |
| 31 | +```js |
| 32 | +import { Server } from "sourcemod.js" |
| 33 | + |
| 34 | +const server = await new Server("ws://localhost:12345") |
| 35 | +server.connect() |
| 36 | + |
| 37 | +server.on("ready", async () => { |
| 38 | + console.log("Connected!") |
| 39 | + server.players.on("connect", (player) => { |
| 40 | + console.log(`${player.name} connected!`) |
| 41 | + }) |
| 42 | + server.players.on("disconnect", (player) => { |
| 43 | + console.log(`${player.name} disconnected!`) |
| 44 | + }) |
| 45 | +}) |
| 46 | + |
| 47 | +// node test.js |
| 48 | +// Connected! |
| 49 | +// infinixius connected! |
| 50 | +// infinixius disconnected! |
| 51 | +``` |
| 52 | + |
| 53 | +Documentation is available at [https://infinixi.us/sourcemod.js](https://infinixi.us/sourcemod.js). |
| 54 | + |
| 55 | +# Contributing |
| 56 | + |
| 57 | +Before creating an issue or pull request, please ensure that it hasn't already been reported or suggested, and double-check the [docs](https://infinixi.us/sourcemod.js). |
| 58 | + |
| 59 | +Other than that, feel free to contribute! Bugfixes, new features, or just better code in general are all greatly appreciated! |
| 60 | + |
| 61 | +# License |
| 62 | + |
| 63 | +This project is under the [MIT License](https://mit-license.org/). This allows you to use, modify, and distribute the source code as long as you include the license. |
| 64 | + |
| 65 | +# Troubleshooting |
| 66 | + |
| 67 | +### `Exception reported: Invalid match index passed.` |
| 68 | + |
| 69 | +This is an issue with `sm-websockets`. Use [this version](https://github.com/peace-maker/sm-websocket/files/7966813/websocket.zip) I built myself that contains the fix, or just build it yourself. |
| 70 | + |
| 71 | +### `Error: connect ECONNREFUSED` |
| 72 | + |
| 73 | +This error boils down to the JavaScript plugin not being able to connect to the WebSocket server. This could be for several reasons: |
| 74 | + |
| 75 | +- The SourceMod server isn't up |
| 76 | +- The SourceMod plugin isn't working |
| 77 | +- The port (`12345`) is taken by another service, or isn't port forwarded properly. (you need to port forward this port if you aren't accessing the WebSocket server from a LAN connection) |
| 78 | +- You aren't connected to the internet |
0 commit comments