dot big bang

Developer API
Menu
All
  • Public
  • Public/Protected
  • All

If you want to add your own custom scripts to this game you can do so in a couple of different ways.

First, you can remix existing scripts and adjust them to work the way you want. You can also add your own scripts and react to game play by listening for specific events that the various FPS scripts broadcast. These events are outlined below along with some examples showing how they can be used.

Listening To FPS Events

To get your script to hear events being broadcast by the FPS scripts you will need to add a tag to the object your script is on. This can be done manually, or the script itself can add the tag. Having the script add the tag ensures that nobody forgets to add the tag so it's the recommended approach.

export class Script extends UserScriptComponent {
  start() {
    // Add the FPS events tag automatically.
    this.entity.tags.add("dmg_events");
  }
}

Now that your script can receive the events, you can listen to them by adding the functions below.

Round Events

// This is called when the pre round count down begins.
onGameStarting()

// This is called when a round begins.
onGameStart()

// This is called when a round ends and starts the post round count down.
onGameFinish()

// This is called after the post round count down.
onGameReset()

// This is called every frame during a round.
timeLeft(time: number)

Save Data Events

// This is called when save data for the local player has loaded. See the FPS - Save Data script to see the data included in PlayerData.
saveDataInit(playerData: any)

// Sent at the end of a round on each local player.
setWins(wins: number)

// Sent at the end of a round on each local player.
setBestScore(points: number)

// Sent for the local player when they die.
setTopGrudge(playerHandle: string, kills: number)

// Sent for the local player when they kill a player.
setKills(kills: number)

// Sent for the local player when they kill a player.
setTopVictim(playerHandle: string, kills: number)

// Sent for the local player when they revenge kill a player.
setTopRival(playerHandle: string, kills: number)

// Sent for the local player when they do damge.
setDamageDealt(damage: number)

// Sent for the local player when they do damge.
setTopGun(weaponName: string, damage: number)

Other Events

// Sent for the local player when damage they deal damage.
onDamageDealt(targetEntity: Entity, dealer: Entity | null, damage: number, weaponName: string, position: Vector3)

// Sent on all clients when a player is killed.
onPlayerKilled(playerEntity: Entity, killerEntity: Entity)

// Sent on all clients when a player's points change
onPointsChanged(playerId: string, currentPoints: number)

// Sent on all clients when a revenge kill happens.
onRevengeKill(killerId: string, victimId: string)

Sending FPS Events

There are some events you can use to modify the game state. These can be a great way to integrate your own scripts into the system.

// Adds points to a specific player.
this.game.sendEventToTag(
  "dmg_events",
  "addPoints",
  this.game.session.localPeer.user.id,
  points,
);

Some events are meant to be used to retrieve some information. Here are some snippets that you can use to get various information about the game.

// Gets the current game state. See the FPS - Round Controller script for more information.
let result = { state: "" };
this.game.sendEventToTag("dmg_events", "getGameState", result);

// Gets the current round stats for a specific player. Notice that the player id passed is the Peer.user.id. See the FPS - Points script for more information.
let result = { rank: 0, points: 0 };
this.game.sendEventToTag(
  "dmg_events",
  "getRoundStats",
  this.game.session.localPeer.user.id,
  result,
);

// Gets the currently active spawnpoint tag. If set up maps can be cycled by using different tags on spawnpoints. See the FPS - Spawn Controller script for more information.
let result = { tag: "spawnpoint" };
this.game.sendEventToTag("dmg_events", "getCurrentSpawnpointTag", result);

Entity Events

Aside from sending events to a tag, or listening to events that have been sent to a tag, you can also send events directly to some Entities to read or write data. To do this you will need a reference to the Entity. This reference will be the entity variable in the below examples.

Player Entity Events

Several events can be sent directly to the player Entity. This can easily be accessed with this.game.playerEntity.

// Adds ammo to the currently equipped weapon.
this.game.playerEntity.sendEvent("addAmmo", amount);

// Enables the currently equipped weapon.
this.game.playerEntity.sendEvent("enable");

// Disables the currently equipped weapon.
this.game.playerEntity.sendEvent("disable");

// Damages the player.
this.game.playerEntity.sendEvent("damage", amount, kind, dealer, position);

// Heals the player.
this.game.playerEntity.sendEvent("heal", amount);

// Kill the player.
this.game.playerEntity.sendEvent("die");

You can also retrieve information about the current player state.

// Gets the currently equipped Weapon Data Id.
let result = { dataId: "" };
this.game.playerEntity.sendEvent("getWeaponDataId", result);

// Gets the currently equipped weapon name and verb used when a player is killed with it.
let result = { name: "", verb: "" };
this.game.playerEntity.sendEvent("getWeaponNameAndVerb", result);

// Gets the currently equipped weapon ammo and magazine size.
let result = { rounds: 0, magazineSize: 0 };
this.game.playerEntity.sendEvent("getRoundsAndMagazineSize", result);

// Gets the current and max health.
let result = { health: 0, maxHealth: 0 };
this.game.playerEntity.sendEvent("getHealthAndMaxHealth", result);

Damageable Entity Events

Entities with the FPS - Damageable script on them can recieve the following events.

// Damages the Entity.
entity.sendEvent("damage", amount, kind, dealer, position);

// Heals the Entity.
entity.sendEvent("heal", amount);

Flashing Entity Events

Entities with the FPS - Flash Color script on them can recieve the following events.

// Makes the Entity flash.
entity.sendEvent("enableEmissive");

// Stops the Entity from flashing.
entity.sendEvent("disableEmissive");