Sign in to follow this  
Weizik

Создание организации

Recommended Posts

Weizik    1

Доброго времени суток. Подскажите, как возможно создать организацию? Есть какой-нибудь пример? От этого буду отталкиваться.

Думаю многих интересует этот вопрос.

Share this post


Link to post
Share on other sites
cacao    13
class Faction
{
  constructor(params) {
    if (params.members instanceof Array && params.members.length) {
      this.members = params.members
    }
    this.name = params.name
  }
  
  get ranks() {
    return ['Ранг 1', 'Ранг 2']
  }
  
  invite(player) {
    this.members.push(player)
  }
  
  uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id) ? arr.splice(i, 1) : null)
  }
  
  setrank(player, value) {
    if (typeof value === "number" && this.ranks[value]) {
      player.rank = value
    }
  }
  
  giverank(player) {
    return [player.rank, this.ranks[player.rank]]
  }
}

let player = mp.players[0]
 , faction = null
if (player) {
  let params = {
    name: "Фракция с тестовым названием",
    members: [ player.id ]
  }
  faction = new Faction(params)
}

 

Edited by cacao
111
  • Like 1

Share this post


Link to post
Share on other sites
Weizik    1
22 минуты назад, cacao сказал:
class Faction
{
  constructor(params) {
    if (params.members instanceof Array && params.members.length) {
      this.members = params.members
    }
    this.name = params.name
  }
  
  get ranks() {
    return ['Ранг 1', 'Ранг 2']
  }
  
  invite(player) {
    this.members.push(player)
  }
  
  uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id) ? arr.splice(i, 1) : null)
  }
  
  setrank(player, value) {
    if (typeof value === "number" && this.ranks[value]) {
      player.rank = value
    }
  }
  
  giverank(player) {
    return [player.rank, this.ranks[player.rank]]
  }
}

let player = mp.players[0]
 , faction = null
if (player) {
  let params = {
    name: "Фракция с тестовым названием",
    members: [ player.id ]
  }
  faction = new Faction(params)
}

 

Спасибо, буду использовать ваш код как пример.

Share this post


Link to post
Share on other sites
Weizik    1
26 минут назад, cacao сказал:
class Faction
{
  constructor(params) {
    if (params.members instanceof Array && params.members.length) {
      this.members = params.members
    }
    this.name = params.name
  }
  
  get ranks() {
    return ['Ранг 1', 'Ранг 2']
  }
  
  invite(player) {
    this.members.push(player)
  }
  
  uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id) ? arr.splice(i, 1) : null)
  }
  
  setrank(player, value) {
    if (typeof value === "number" && this.ranks[value]) {
      player.rank = value
    }
  }
  
  giverank(player) {
    return [player.rank, this.ranks[player.rank]]
  }
}

let player = mp.players[0]
 , faction = null
if (player) {
  let params = {
    name: "Фракция с тестовым названием",
    members: [ player.id ]
  }
  faction = new Faction(params)
}

 

" Uncaught SyntaxError: Unexpected token ) " ошибка, как можно решить?
~TWijOk21.png


 

Share this post


Link to post
Share on other sites
cacao    13
//было
uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id) ? arr.splice(i, 1) : null)
}
//нужно
uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id ? arr.splice(i, 1) : null)
}

 

  • Like 1

Share this post


Link to post
Share on other sites
Weizik    1
11 час назад, cacao сказал:
//было
uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id) ? arr.splice(i, 1) : null)
}
//нужно
uninvite(player) {
    this.members.forEach((_player, i, arr) => _player.id === player.id ? arr.splice(i, 1) : null)
}

 

Без Вас я бы эту скобочку не нашел)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.