-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
127 lines (114 loc) · 3.65 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
let job_status = {
police: 0,
ambulance: 0,
unemployed: 0,
phone_number: null,
user_data: null,
total: 0,
playerId: 0
}
let listPlayers = []
var ESX = null
RegisterCommand('jssync', async (source) => {
emit('esx:getSharedObject', (obj) => {
ESX = obj
})
let playerId = source
let identifiers = ESX.GetIdentifier(playerId)
let sql = `SELECT * from users WHERE identifier = 'char1:${identifiers}'`
exports.oxmysql.query(sql, (result) => {
job_status.phone_number = result[0].phone_number
job_status.name = result[0].firstname + ' ' + result[0].lastname
})
// exports.oxmysql.query(`SELECT * FROM users WHERE identifier = 'char1:${identifiers}'`, function (result) {
// if (result) {
// result.forEach((v) => {
// job_status.phone_number = v.phone_number
// job_status.name = v.firstname + ' ' + v.lastname
// // console.log('JJ SQL', v.identifier, v.firstname, v.lastname, v.phone_number)
// // console.log(job_status.name, job_status.phone_number)
// })
// }
// })
})
on('esx:playerLoaded', (source) => {
job_status.total = job_status.total + 1
emit('esx:getSharedObject', (obj) => {
ESX = obj
})
let playerId = source
let xPlayer = ESX.GetPlayerFromId(playerId)
job_status.playerId = source
job_name = xPlayer.job.name
if (job_name == 'police') {
job_status.police++
} else if (job_name == 'ambulance') {
job_status.ambulance++
} else {
job_status.unemployed++
}
listPlayers.push({
id: playerId,
job_name: job_name
})
let identifiers = ESX.GetIdentifier(playerId)
let sql = `SELECT * from users WHERE identifier = 'char1:${identifiers}'`
exports.oxmysql.query(sql, (result) => {
job_status.user_data = result[0]
// console.log(job_status)
emitNet("fip:scoreboard:update", -1, job_status)
})
})
on('esx:playerDropped', (source) => {
job_status.total = job_status.total - 1
emit('esx:getSharedObject', (obj) => {
ESX = obj
})
let playerId = source
let xPlayer = ESX.GetPlayerFromId(playerId)
job_name = xPlayer.job.name
if (job_name == 'police') {
job_status.police--
} else if (job_name == 'ambulance') {
job_status.ambulance--
} else {
job_status.unemployed--
}
// slice the array form the player id
listPlayers.splice(listPlayers.findIndex((player) => player.id == source), 1)
emitNet("fip:scoreboard:update", -1, job_status)
})
on('esx:setJob', (source) => {
emit('esx:getSharedObject', (obj) => {
ESX = obj
})
let playerId = source
let xPlayer = ESX.GetPlayerFromId(playerId)
new_job_name = xPlayer.job.name
let old_player = listPlayers.find(player => {
if (player.id == playerId) {
return player.job_name
}
})
old_job = old_player.job_name
if (old_job == 'police') {
job_status.police--
} else if (old_job == 'ambulance') {
job_status.ambulance--
} else {
job_status.unemployed--
}
listPlayers.findIndex(player => {
if (player.id == playerId) {
player.job_name = new_job_name
}
})
if (new_job_name == 'police') {
job_status.police++
} else if (new_job_name == 'ambulance') {
job_status.ambulance++
} else {
job_status.unemployed++
}
emitNet("fip:scoreboard:update", -1, job_status)
})