FordeD Posted February 21, 2017 Share Posted February 21, 2017 После создании структуры персонажа не удается вызвать функцию из структуры Существует данный скрипт global.PLAYERS = {}; function AddPlayer(playerid, skin, name, health, armor, eat, money, bank, weapons, arrests, stars, drugs, fraction, rank) { PLAYERS[playerid] = {}; const temp = {}; temp.name = name; temp.skin = skin; temp.health = health; temp.armor = armor; temp.eat = eat; temp.money = money; temp.bank = bank; temp.weapons = weapons; temp.arrests = arrests; temp.stars = stars; temp.fraction = fraction; temp.rank = rank; temp.drugs = drugs; this.GetName=function(){ return this.name; } this.GetSkin=function(){ return this.skin; } this.SetSkin=function(skin){ this.skin = skin; } this.GetHp=function(){ return this.health; } this.SetHp=function(health){ this.health = health; } this.GetHp=function(){ return this.health; } this.SetHp=function(health){ this.health = health; } this.GetArm=function(){ return this.armor; } this.SetArm=function(armor){ this.armor = armor; } this.GetEat=function(){ return this.eat; } this.SetEat=function(eat){ this.eat = eat; } this.GetMoney=function(){ return this.money; } this.SetMoney=function(money){ this.money = money; } this.GetBank=function(){ return this.bank; } this.SetBank=function(bank){ this.bank = bank; } this.GetDrugs=function(){ return this.drugs; } this.SetDrugs=function(drugs){ this.drugs = drugs; } this.GetWeapons=function(){ return this.weapons; } this.SetBank=function(weapons){ this.weapons = weapons; } this.AddWeapon=function(weapon){ this.weapons.push(weapon);} this.RemoveWeapon=function(weapon){ this.weapons.remove(this.indexOf(weapon));} this.GetArrests=function(){ return this.arrests; } this.AddArrests=function(){ this.arrests += 1; } this.GetStars=function(){ return this.stars; } this.SetStars=function(stars){ this.stars = stars; } this.GetFraction=function(){ return this.fraction; } this.SetFraction=function(fraction){ this.fraction = fraction; } this.GetRank=function(){ return this.rank; } this.SetRank=function(rank){ this.rank = rank; } PLAYERS[playerid] = temp; } function RemovePlayer(playerid) { PLAYERS[playerid] = {}; } При подключении игрока вызывается эвент "playerJoin" а в нем функция : AddPlayer(player.id, models["a_f_y_hipster_02"], player.name, 100, 100, 100, 500, 0, {"Pistol": 900}, 0, 0, 0, 0, 0); В мод добавлена команда: "getdata": (player, args) => { let id = player.id; player.outputChatBox('Name:<br /><b>'+PLAYERS[id].name+'</b>'); player.outputChatBox('skin:<br /><b>'+PLAYERS[id].skin+'</b>'); player.outputChatBox('health:<br /><b>'+PLAYERS[id].health+'</b>'); player.outputChatBox('armor:<br /><b>'+PLAYERS[id].armor+'</b>'); player.outputChatBox('eat:<br /><b>'+PLAYERS[id].eat+'</b>'); player.outputChatBox('money:<br /><b>'+PLAYERS[id].money+'</b>'); player.outputChatBox('bank:<br /><b>'+PLAYERS[id].bank+'</b>'); }, При вызове команды выходит ошибка, PLAYERS[0].name is not defined где именно я накосячил с ООП структурой? (P.S переходил с Lua ) Link to comment Share on other sites More sharing options...
FordeD Posted February 21, 2017 Author Share Posted February 21, 2017 Слегка изменил скрипт: global.PLAYERS = {}; function PLAYER(skin, name, health, armor, eat, money, bank, weapons, arrests, stars, drugs, fraction, rank, pos) { var name = name; var skin = skin; var health = health; var armor = armor; var eat = eat; var money = money; var bank = bank; var weapons = weapons; var arrests = arrests; var stars = stars; var fraction = fraction; var rank = rank; var drugs = drugs; var pos = pos; this.GetName = function(){ return name; }; this.GetSkin = function(){ return skin; }; this.SetSkin = function(s){ skin = s; }; this.GetHp = function(){ return health; }; this.SetHp = function(heal){ health = heal; }; this.GetArm = function(){ return armor; }; this.SetArm = function(arm){ armor = arm; }; this.GetEat = function(){ return eat; }; this.SetEat = function(e){ eat = e; }; this.GetMoney = function(){ return money; }; this.SetMoney = function(m){ money = m; }; this.GetBank = function(){ return bank; }; this.SetBank = function(b){ bank = b; }; this.GetDrugs = function(){ return drugs; }; this.SetDrugs = function(dr){ drugs = dr; }; this.GetWeapons = function(){ return weapons; }; this.SetBank = function(weap){ weapons = weap; }; this.AddWeapon = function(weap){ weapons.push(weap);}; //RemoveWeapon = function(weapon){ weapons.remove(indexOf(weapon));}; this.GetArrests = function(){ return arrests; }; this.AddArrests = function(){ arrests += 1; }; this.GetStars = function(){ return stars; }; this.SetStars = function(st){ stars = st; }; this.GetFraction = function(){ return fraction; }; this.SetFraction = function(fr){ fraction = fr; }; this.GetRank = function(){ return rank; }; this.SetRank = function(r){ rank = r; }; this.GetPos = function(){ return pos; }; this.SetPos = function(p){ pos = p }; } function RemovePlayer(playerid) { PLAYERS[playerid] = null; } Добавление игрока в массив PLAYERS был изменен на: PLAYERS[player.id] = new PLAYER(models["a_f_y_hipster_02"], player.name, 100, 100, 100, 500, 0, {"Pistol": 900}, 0, 0, 0, 0, 0); Но ошибка осталась той же. Link to comment Share on other sites More sharing options...
VADIMREX Posted February 21, 2017 Share Posted February 21, 2017 Так свойство name у объекта не объявлено. Судя по коду, чтобы исправить ошибку надо использовать что-то вроде: PLAYERS[id].GetName() Link to comment Share on other sites More sharing options...
FordeD Posted February 21, 2017 Author Share Posted February 21, 2017 16 минут назад, kemperrr сказал: Зачем так насиловать код? "playerJoin": (player) => { player.info = { level: 0, exp: 0 } } //загрузка function loadPlayer(player, params) { player.info = { level: params.level, exp: params.exp } } //использование consol.log(player.info.level) // - GET player.info.level = 999 // - SET Как пободное сделать тогда для транспорта и объектов (пикапы, текст на карте и т.д)? Link to comment Share on other sites More sharing options...
FordeD Posted February 21, 2017 Author Share Posted February 21, 2017 48 минут назад, kemperrr сказал: //автомобили let temp = mp.vehicles.add(...) temp.info = { id: 0, ... } Значит если сделать массив подобных temp объектов то можно к каждому авто получить данные но вот вопрос, как получить ID авто чтоб добавить его под его номером в массив для дальнейшей работы с данными? И по возможности где я могу посмотреть все возможные функции для игрока, авто и подобных объектов (так как вики пустует и необходимой информации там не получить ...) ? Link to comment Share on other sites More sharing options...
FordeD Posted February 21, 2017 Author Share Posted February 21, 2017 Спасибо, основной ID же можно получить в эвенте по структуре vehicle.id или по команде через игрока player.vehicle.id? Link to comment Share on other sites More sharing options...
FordeD Posted February 21, 2017 Author Share Posted February 21, 2017 (edited) @kemperrrСпасибо, вопросов по структурам в данный момент больше нет. Edited February 21, 2017 by FordeD Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now