-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathapart_server.lua
304 lines (287 loc) · 13.7 KB
/
apart_server.lua
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
---------------------------
------CHOSE SQL MODE-------
---------------------------
--Async -----------------
--MySQL -----------------
---------------------------
local mode = "Async"
local lang = 'fr'
local txt = {
['fr'] = {
['welcome'] = 'Bienvenue dans votre appartement!',
['nocash'] = 'Vous n\'avez pas assez d\'argent!',
['estVendu'] = 'Appartement vendus!',
['deposit'] = 'Vous avez depose ',
['withdraw'] = 'Vous avez retire ',
['curency'] = '€'
},
['en'] = {
['welcome'] = 'Welcome to home!',
['nocash'] = 'You d\'ont have enough cash!',
['estVendu'] = 'Apartment sold!',
['depositcash'] = 'You deposited ',
['withdraw'] = 'You withdrew ',
['curency'] = '$'
}
}
local isBuy = 0
local money = 0
local dirtymoney = 0
RegisterServerEvent("apart:getAppart")
AddEventHandler('apart:getAppart', function(name)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local name = name
if (mode == "Async") then
MySQL.Async.fetchAll("SELECT * FROM user_appartement WHERE name = @nom", {['@nom'] = tostring(name)}, function (result)
if (result) then
count = 0
for _ in pairs(result) do
count = count + 1
end
if count > 0 then
if (result[1].identifier == player) then
TriggerClientEvent('apart:isMine', source)
else
TriggerClientEvent('apart:isBuy', source)
end
else
TriggerClientEvent('apart:isNotBuy', source)
end
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT * FROM user_appartement WHERE name = @nom", {['@nom'] = tostring(name)})
local result = MySQL:getResults(executed_query, {'identifier'})
if (result) then
count = 0
for _ in pairs(result) do
count = count +1
end
if count > 0 then
if (result[1].identifier == player) then
TriggerClientEvent('apart:isMine', source)
else
TriggerClientEvent('apart:isBuy', source)
end
else
TriggerClientEvent('apart:isNotBuy', source)
end
end
end
end)
end)
RegisterServerEvent("apart:getCash")
AddEventHandler('apart:getCash', function(name)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local name = name
if (mode == "Async") then
MySQL.Async.fetchAll("SELECT * FROM user_appartement WHERE name = @nom", {['@nom'] = tostring(name)}, function (result)
if (result) then
money = result[1].money
dirtymoney = result[1].dirtymoney
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT * FROM user_appartement WHERE name = @nom", {['@nom'] = tostring(name)})
local result = MySQL:getResults(executed_query, {'identifier'})
if (result) then
money = result[1].money
dirtymoney = result[1].dirtymoney
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
end
end
end)
end)
RegisterServerEvent("apart:depositcash")
AddEventHandler('apart:depositcash', function(cash, apart)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local money = 0
if (tonumber(user.getMoney()) >= tonumber(cash) and tonumber(cash) > 0) then
if mode == "Async" then
MySQL.Async.fetchAll("SELECT money FROM user_appartement WHERE name = @nom", {['@nom'] = apart}, function (result)
if (result) then
money = result[1].money
user.removeMoney(tonumber(cash))
local newmoney = money + cash
MySQL.Async.execute("UPDATE user_appartement SET `money`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart}, function(data)
end)
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['deposit'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT money FROM user_appartement WHERE name = @nom", {['@nom'] = apart})
local result = MySQL:getResults(executed_query, {'money'})
if (result) then
money = result[1].money
user.removeMoney(tonumber(cash))
local newmoney = money + cash
MySQL:executeQuery("UPDATE user_appartement SET `money`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart})
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['deposit'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
end
end
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end)
end)
RegisterServerEvent("apart:depositdirtycash")
AddEventHandler('apart:depositdirtycash', function(cash, apart)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local money = 0
if (tonumber(user.getDirtyMoney()) >= tonumber(cash) and tonumber(cash) > 0) then
if mode == "Async" then
MySQL.Async.fetchAll("SELECT dirtymoney FROM user_appartement WHERE name = @nom", {['@nom'] = apart}, function (result)
if (result) then
money = result[1].dirtymoney
user.removeDirtyMoney(tonumber(cash))
local newmoney = money + cash
MySQL.Async.execute("UPDATE user_appartement SET `dirtymoney`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart}, function(data)
end)
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['deposit'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT dirtymoney FROM user_appartement WHERE name = @nom", {['@nom'] = apart})
local result = MySQL:getResults(executed_query, {'dirtymoney'})
if (result) then
money = result[1].dirtymoney
user.removeDirtyMoney(tonumber(cash))
local newmoney = money + cash
MySQL:executeQuery("UPDATE user_appartement SET `dirtymoney`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart})
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['deposit'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
end
end
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end)
end)
RegisterServerEvent("apart:takecash")
AddEventHandler('apart:takecash', function(cash, apart)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local money = 0
if mode == "Async" then
MySQL.Async.fetchAll("SELECT money FROM user_appartement WHERE name = @nom", {['@nom'] = apart}, function (result)
if (result) then
money = result[1].money
if (tonumber(cash) <= tonumber(money) and tonumber(cash) > 0) then
user.addMoney(tonumber(cash))
local newmoney = money - cash
MySQL.Async.execute("UPDATE user_appartement SET `money`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart}, function(data)
end)
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['withdraw'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT money FROM user_appartement WHERE name = @nom", {['@nom'] = apart})
local result = MySQL:getResults(executed_query, {'money'})
if (result) then
money = result[1].money
if (tonumber(cash) <= tonumber(money) and tonumber(cash) > 0) then
user.addMoney(tonumber(cash))
local newmoney = money - cash
MySQL:executeQuery("UPDATE user_appartement SET `money`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart})
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['withdraw'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end
end
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
end)
end)
RegisterServerEvent("apart:takedirtycash")
AddEventHandler('apart:takedirtycash', function(cash, apart)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local money = 0
if mode == "Async" then
MySQL.Async.fetchAll("SELECT dirtymoney FROM user_appartement WHERE name = @nom", {['@nom'] = apart}, function (result)
if (result) then
money = result[1].dirtymoney
if (tonumber(cash) <= tonumber(money) and tonumber(cash) > 0) then
user.addDirtyMoney(tonumber(cash))
local newmoney = money - cash
MySQL.Async.execute("UPDATE user_appartement SET `dirtymoney`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart}, function(data)
end)
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['withdraw'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end
end)
elseif mode == "MySQL" then
local executed_query = MySQL:executeQuery("SELECT dirtymoney FROM user_appartement WHERE name = @nom", {['@nom'] = apart})
local result = MySQL:getResults(executed_query, {'dirtymoney'})
if (result) then
money = result[1].dirtymoney
if (tonumber(cash) <= tonumber(money) and tonumber(cash) > 0) then
user.addDirtyMoney(tonumber(cash))
local newmoney = money - cash
MySQL:executeQuery("UPDATE user_appartement SET `dirtymoney`=@cash WHERE name = @nom",{['@cash'] = newmoney, ['@nom'] = apart})
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['withdraw'] .. cash .. txt[lang]['curency'] , type = "success", timeout = 5000, layouts = "bottomCenter"})
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end
end
TriggerClientEvent('apart:getCash', source, money, dirtymoney)
end)
end)
RegisterServerEvent("apart:buyAppart")
AddEventHandler('apart:buyAppart', function(name, price)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local name = name
local price = price
if (tonumber(user.getMoney()) >= tonumber(price)) then
user.removeMoney(tonumber(price))
if (mode == "Async") then
MySQL.Async.execute("INSERT INTO user_appartement (`identifier`, `name`, `price`) VALUES (@username, @name, @price)", {['@username'] = player, ['@name'] = name, ['@price'] = price})
elseif mode == "MySQL" then
local executed_query2 = MySQL:executeQuery("INSERT INTO user_appartement (`identifier`, `name`, `price`) VALUES (@username, @name, @price)", {['@username'] = player, ['@name'] = name, ['@price'] = price})
end
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['welcome'], type = "success", timeout = 5000, layouts = "bottomCenter"})
TriggerClientEvent('apart:isMine', source)
else
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['nocash'], type = "error", timeout = 5000, layouts = "bottomCenter"})
end
end)
end)
RegisterServerEvent("apart:sellAppart")
AddEventHandler('apart:sellAppart', function(name, price)
local source = source
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.getIdentifier()
local name = name
local price = price/2
user.addMoney(tonumber(price))
if (mode == "Async") then
MySQL.Async.execute("DELETE from user_appartement WHERE identifier = @username AND name = @name",
{['@username'] = player, ['@name'] = name})
elseif mode == "MySQL" then
local executed_query3 = MySQL:executeQuery("DELETE from user_appartement WHERE identifier = @username AND name = @name",
{['@username'] = player, ['@name'] = name})
end
TriggerClientEvent("pNotify:SendNotification", -1, {text = txt[lang]['estVendu'], type = "success", timeout = 5000, layouts = "bottomCenter"})
TriggerClientEvent('apart:isNotBuy', source)
end)
end)