https://github.com/script-js/firemp
Multiplayer game library for Firebase Realtime Databases
https://github.com/script-js/firemp
Last synced: 3 months ago
JSON representation
Multiplayer game library for Firebase Realtime Databases
- Host: GitHub
- URL: https://github.com/script-js/firemp
- Owner: script-js
- Created: 2024-12-12T00:14:44.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-27T22:44:39.000Z (10 months ago)
- Last Synced: 2025-02-10T05:14:29.058Z (8 months ago)
- Language: JavaScript
- Homepage: https://script-js.github.io/FireMP/
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FireMP
## A JavaScript library for creating multiplayer games using a Firebase Realtime Database
### Demo
[Client](https://script-js.github.io/FireMP/demo/client) | [Host](https://script-js.github.io/FireMP/demo/host)
### Getting Started**1. Create your database**
1. Create a Firebase Project
Go to console.firebase.google.com and click Create a project.
2. Add an app
Click the small > icon on the home page and set up your app. Make sure you save the firebase config variable it gives you.
3. Create a Realtime Database
Under the build tab in the sidebar, click Realtime Database. Click create database and go through the setup. Once you've set it up change the rules so they look like this:
```
{
"rules": {
"gameid": {
".read": true,
".write": true
}
}
}
```
5. Add this code to your game (make sure to replace the firebaseConfig variable with the one from step 1):
```import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js";
import { getDatabase, ref, set, get, child, onValue } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-database.js";
import { firemp } from "https://script-js.github.io/FireMP/main.js";const firebaseConfig = <Your Firebase Config Variable>
// Initialize Firebase
const app = initializeApp(firebaseConfig);
firemp.registerFunctions(getDatabase, ref, set, get, child, onValue)```
### createGame
Used to start a new gameExample:
```
firemp.createGame(function(gameid) {
alert("Game ID: " + gameid)
})
```### endGame
Used to end the gameExample:
```
firemp.endGame()
```### startGame
Used to start the gameExample:
```
firemp.startGame()
```### joinGame
Allows players to join the gameExample:
```
var playerName = prompt("Player Name")
var gameId = prompt("Game ID")
firemp.joinGame(gameId,playerName,function() {alert("Game Started")},function() {alert("Game Over")})
```### leaveGame
Allows a player to leave the gameExample:
```
firemp.leaveGame()
```### listen
Listens for changes in a specified valueExample:
```
firemp.listen(,function(data) {alert("Value Data: " + data)},function() {alert("Value Non-existent")})
```### send
Add or update a game valueExample:
```
firemp.send(,)
```### remove
Remove a game valueExample:
```
firemp.remove()
```### playerDataAdd
Add or update player dataExample:
```
firemp.playerDataAdd(,)
```### playerDataRemove
Remove player dataExample:
```
firemp.playerDataRemove()
```### getPlayerList
Get a list of players in the game
Fires every time the player list changesExample:
```
firemp.getPlayerList(function(players) {
alert("List of Players" + players) // Outputs an array
})
```### removePlayer
Removes a player from the gameExample:
```
firemp.removePlayer()
```