Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feature to choose default spawn points #49

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions skymp5-server/ts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export class Settings {
gamemodePath = "...";
loadOrder = new Array<string>();
dataDir = "./data";
startPoints = [
{
pos: [22659, -8697, -3594],
worldOrCell: '0x1a26f',
angleZ: 268
},
];

constructor() {
if (fs.existsSync("./skymp5-gamemode")) {
Expand All @@ -32,6 +39,7 @@ export class Settings {
"gamemodePath",
"loadOrder",
"dataDir",
"startPoints",
].forEach((prop) => {
if (parsed[prop])
(this as Record<string, unknown>)[prop] = parsed[prop];
Expand Down
14 changes: 6 additions & 8 deletions skymp5-server/ts/systems/spawn.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Settings } from "../settings";
import { System, Log, SystemContext } from "./system";

const spawnpoints = [
{ pos: [22659, -8697, -3594], worldOrCell: 0x1a26f, angleZ: 268 },
];

function randomInteger(min: number, max: number) {
const rand = min + Math.random() * (max + 1 - min);
return Math.floor(rand);
Expand All @@ -15,19 +12,20 @@ export class Spawn implements System {

async initAsync(ctx: SystemContext): Promise<void> {
ctx.gm.on("spawnAllowed", (userId: number, userProfileId: number) => {
const { startPoints } = Settings.get();
// TODO: Show race menu if character is not created after relogging
let actorId = ctx.svr.getActorsByProfileId(userProfileId)[0];
if (actorId) {
this.log("Loading character", actorId.toString(16));
ctx.svr.setEnabled(actorId, true);
ctx.svr.setUserActor(userId, actorId);
} else {
const idx = randomInteger(0, spawnpoints.length - 1);
const idx = randomInteger(0, startPoints.length - 1);
actorId = ctx.svr.createActor(
0,
spawnpoints[idx].pos,
spawnpoints[idx].angleZ,
spawnpoints[idx].worldOrCell,
startPoints[idx].pos,
startPoints[idx].angleZ,
+startPoints[idx].worldOrCell,
userProfileId
);
this.log("Creating character", actorId.toString(16));
Expand Down