· 6 years ago · May 16, 2019, 08:16 PM
1customCarNames = -- новые названиÑ
2{
3
4}
5
6shopsVehSpawns = {
7 [1] = { 2131, -1133, 25.6, 0,0,359 },
8 [2] = { 555, -1278, 18, 0,0,100 },
9 [3] = { 1941, 2097, 10.8, 0,0,350 },
10 [4] = { -1988, 272, 36, 0,0,259 },
11 [5] = { -1642, 1213, 7.17, 0,0, 227 },
12}
13
14function getFreeID()
15 local result = dbPoll(dbQuery(db, "SELECT ID FROM VehicleList ORDER BY ID ASC"), -1)
16 newID = false
17 for i, id in pairs (result) do
18 if id["ID"] ~= i then
19 newID = i
20 break
21 end
22 end
23 if newID then return newID else return #result + 1 end
24end
25
26function getVehicleByID(id)
27 v = false
28 for i, veh in ipairs (getElementsByType("vehicle")) do
29 if getElementData(veh, "ID") == id then
30 v = veh
31 break
32 end
33 end
34 return v
35end
36
37function updateVehicleInfo(player)
38 if isElement(player) then
39 local result = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountName(getPlayerAccount(player))), -1)
40 if type(result) == "table" then
41 setElementData(player, "VehicleInfo", result)
42 end
43 end
44end
45
46addEventHandler("onResourceStart", resourceRoot,
47function()
48 db = dbConnect("sqlite", "database.db")
49 dbExec(db, "CREATE TABLE IF NOT EXISTS VehicleList (ID, Account, Model, X, Y, Z, RotZ, Colors, Upgrades, Paintjob, Cost, HP, new_hydr)")
50 for i, player in ipairs(getElementsByType("player")) do
51 updateVehicleInfo(player)
52 end
53end)
54
55addEvent("onOpenGui", true)
56addEventHandler("onOpenGui", root,
57function()
58 updateVehicleInfo(source)
59end)
60
61function destroyVehicle(theVehicle)
62 if isElement(theVehicle) then
63 local Owner = getElementData(theVehicle, "Owner")
64 if Owner then
65 local x, y, z = getElementPosition(theVehicle)
66 local _, _, rz = getElementRotation(theVehicle)
67 local r1, g1, b1, r2, g2, b2 = getVehicleColor(theVehicle, true)
68 local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2
69 upgrade = ""
70 for _, upgradee in ipairs (getVehicleUpgrades(theVehicle)) do
71 if upgrade == "" then
72 upgrade = upgradee
73 else
74 upgrade = upgrade..","..upgradee
75 end
76 end
77 local Paintjob = getVehiclePaintjob(theVehicle) or 3
78 local id = getElementData(theVehicle, "ID")
79 dbExec(db, "UPDATE VehicleList SET X = ?, Y = ?, Z = ?, RotZ = ?, HP = ?, Colors = ?, Upgrades = ?, Paintjob = ?, new_hydr = ? WHERE Account = ? AND ID = ?", x, y, z, rz, getElementHealth(theVehicle), color, upgrade, Paintjob, getElementData ( theVehicle, "NewHydr") and 1 or 0, getAccountName(getPlayerAccount(Owner)), id)
80 updateVehicleInfo(Owner)
81 local attached = getAttachedElements(theVehicle)
82 if (attached) then
83 for k,element in ipairs(attached) do
84 if getElementType(element) == "blip" then
85 destroyElement(element)
86 end
87 end
88 end
89 end
90 destroyElement(theVehicle)
91 end
92end
93
94addEvent("onBuyNewVehicle", true)
95addEventHandler("onBuyNewVehicle", root,
96function(Model, cost, r1, g1, b1, r2, g2, b2)
97 abc = false
98 local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ?", getAccountName(getPlayerAccount(source))), -1)
99 for i, data in ipairs (data) do
100 if data["Model"] == Model then
101 abc = true
102 break
103 end
104 end
105 if #data >= 1000 then outputMessage("#c1c1c1Desculpe, mas você só pode comprar #00FF6610#FFFFFF veiculos.", source, 38, 122, 216, true) return end
106 if abc then outputMessage("#c1c1c1Você já tem este veiculo.", source, 38, 122, 216, true) return end
107 if getPlayerMoney(source) >= tonumber(cost) then
108 takePlayerMoney ( source, cost )
109 local x, y, z = getElementPosition(source)
110 local _, _, rz = getElementRotation(source)
111 local shopID = getElementData ( source, "atVehShop")
112 local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2
113 if shopID and shopsVehSpawns[shopID] then
114 vehicle = createVehicle(Model, shopsVehSpawns[shopID][1], shopsVehSpawns[shopID][2], shopsVehSpawns[shopID][3], shopsVehSpawns[shopID][4], shopsVehSpawns[shopID][5], shopsVehSpawns[shopID][6])
115 else
116 vehicle = createVehicle(Model, x-5, y+5, z, 0, 0, rz)
117 end
118 setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2)
119 setElementData(vehicle, "Owner", source)
120 local NewID = getFreeID()
121 setElementData(vehicle, "ID", NewID)
122 dbExec(db, "INSERT INTO VehicleList VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", NewID, getAccountName(getPlayerAccount(source)), Model, x-5, y+5, z, rz, color, "", 3, cost, 1000, 0)
123 outputMessage("#c1c1c1Por: #00FF66$"..cost, source, 38, 122, 216, true)
124 updateVehicleInfo(source)
125 setElementData(vehicle, "ownercar", getAccountName(getPlayerAccount(source)))
126 warpPedIntoVehicle ( source, vehicle )
127 vv[vehicle] = setTimer(function(source)
128 if not isElement(source) then killTimer(vv[source]) vv[source] = nil end
129 if isElement(source) and getElementHealth(source) <= 255 then
130 setElementHealth(source, 255.5)
131 setVehicleDamageProof(source, true)
132 setVehicleEngineState(source, false)
133 end
134 end, 150, 0, vehicle)
135 addEventHandler("onVehicleDamage", vehicle,
136 function(loss)
137 local account = getAccountName(getPlayerAccount(getElementData(source, "Owner")))
138 setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source)
139 end)
140 addEventHandler("onVehicleEnter", vehicle,
141 function(player)
142 if getElementHealth(source) <= 255.5 then
143 setVehicleEngineState(source, false)
144 else
145 if isVehicleDamageProof(source) then
146 setVehicleDamageProof(source, false)
147 end
148 end
149 end)
150 else
151 outputMessage("#c1c1c1Você não tem grana para comprar este veiculo.", source, 38, 122, 216, true)
152 end
153end)
154
155vv = {}
156
157addEvent("SpawnMyVehicle", true)
158addEventHandler("SpawnMyVehicle", root,
159function(id)
160 local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1)
161 if type(data) == "table" and #data ~= 0 then
162 if getVehicleByID(id) then
163 outputMessage("#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1já está spawnado.", source, 38, 122, 216, true)
164 else
165 local color = split(data[1]["Colors"], ',')
166 r1 = color[1] or 255
167 g1 = color[2] or 255
168 b1 = color[3] or 255
169 r2 = color[4] or 255
170 g2 = color[5] or 255
171 b2 = color[6] or 255
172 vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"])
173 setElementData(vehicle, "ID", id)
174 local upd = split(tostring(data[1]["Upgrades"]), ',')
175 for i, upgrade in ipairs(upd) do
176 addVehicleUpgrade(vehicle, upgrade)
177 end
178 local Paintjob = data[1]["Paintjob"] or 3
179 setVehiclePaintjob(vehicle, Paintjob)
180 setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2)
181 if tonumber(data[1]["HP"]) <= 255.5 then data[1]["HP"] = 255 end
182 if data[1]["new_hydr"] and data[1]["new_hydr"] == 1 then
183 setElementData(vehicle, "NewHydr", true)
184 else
185 setElementData(vehicle, "NewHydr", false)
186 end
187 setElementData(vehicle, "ownercar", getAccountName(getPlayerAccount(source)))
188 setElementHealth(vehicle, data[1]["HP"])
189 setElementData(vehicle, "Owner", source)
190 vv[vehicle] = setTimer(function(source)
191 if not isElement(source) then killTimer(vv[source]) vv[source] = nil end
192 if isElement(source) and getElementHealth(source) <= 255 then
193 setElementHealth(source, 255.5)
194 setVehicleDamageProof(source, true)
195 setVehicleEngineState(source, false)
196 end
197 end, 50, 0, vehicle)
198 addEventHandler("onVehicleDamage", vehicle,
199 function(loss)
200 local account = getAccountName(getPlayerAccount(getElementData(source, "Owner")))
201 setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source)
202 end)
203 addEventHandler("onVehicleEnter", vehicle,
204 function(player)
205 if getElementHealth(source) <= 255.5 then
206 setVehicleEngineState(source, false)
207 else
208 if isVehicleDamageProof(source) then
209 setVehicleDamageProof(source, false)
210 end
211 end
212 end)
213 outputMessage("#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1foi spawnado.", source, 38, 122, 216, true)
214 end
215 else
216 outputMessage("#c1c1c1Há um problema com o veiculo, notifique o administrador.", source, 38, 122, 216, true)
217 end
218end)
219
220addEvent("DestroyMyVehicle", true)
221addEventHandler("DestroyMyVehicle", root,
222function(id)
223 local vehicle = getVehicleByID(id)
224 if isElement(vehicle) then
225 local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1)
226 if type(data) == "table" and #data ~= 0 then
227 destroyVehicle(vehicle)
228 outputMessage ("#c1c1c1O seu veiculo #00FF66"..(customCarNames[data[1]["Model"]] or getVehicleNameFromModel(data[1]["Model"])).." #c1c1c1foi removido.", source, 38, 122, 216, true)
229 else
230 outputMessage("#c1c1c1Selecione um veiculo.", source, 38, 122, 216, true)
231 end
232 else
233 outputMessage("#c1c1c1O seu veiculo não foi spawnado.", source, 38, 122, 216, true)
234 end
235end)
236
237addEvent("LightsMyVehicle", true)
238addEventHandler("LightsMyVehicle", root,
239function(id)
240 local vehicle = getVehicleByID(id)
241 if isElement(vehicle) then
242 local Vehicle = getPedOccupiedVehicle(source)
243 if Vehicle == vehicle then
244 if getVehicleOverrideLights(vehicle) ~= 2 then
245 setVehicleOverrideLights(vehicle, 2)
246 outputMessage("#c1c1c1Seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1teve as luzes acesas.", source, 38, 122, 216, true)
247 elseif getVehicleOverrideLights(vehicle) ~= 1 then
248 setVehicleOverrideLights(vehicle, 1)
249 outputMessage("#c1c1c1Seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1teve as luzes apagadas.", source, 38, 122, 216, true)
250 end
251 else
252 outputMessage("#c1c1c1Você não está no veiculo!", source, 38, 122, 216, true)
253 end
254 else
255 outputMessage("#c1c1c1O seu veiculo não está spawnado.", source, 38, 122, 216, true)
256 end
257end)
258
259addEvent("LockMyVehicle", true)
260addEventHandler("LockMyVehicle", root,
261function(id)
262 local vehicle = getVehicleByID(id)
263 if isElement(vehicle) then
264 if not isVehicleLocked(vehicle) then
265 setVehicleLocked(vehicle, true)
266 setVehicleDoorsUndamageable(vehicle, true)
267 setVehicleDoorState(vehicle, 0, 0)
268 setVehicleDoorState(vehicle, 1, 0)
269 setVehicleDoorState(vehicle, 2, 0)
270 setVehicleDoorState(vehicle, 3, 0)
271 outputMessage("#c1c1c1O seu transporte #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi #00FF66fechado.", source, 38, 122, 216, true)
272 elseif isVehicleLocked(vehicle) then
273 setVehicleLocked(vehicle, false)
274 setVehicleDoorsUndamageable(vehicle, false)
275 outputMessage("#c1c1c1O seu transporte #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi #00FF66aberto.", source, 38, 122, 216, true)
276 end
277 else
278 outputMessage("#c1c1c1O seu veiculo não foi spawnado.", source, 38, 122, 216, true)
279 end
280end)
281
282addEvent("BlipMyVehicle", true)
283addEventHandler("BlipMyVehicle", root,
284function(id)
285 local vehicle = getVehicleByID(id)
286 if isElement(vehicle) then
287 if not getElementData(vehicle, "ABlip") then
288 setElementData(vehicle, "ABlip", true)
289 createBlipAttachedTo(vehicle, 41, 2, 255, 0, 0, 255, 0, 65535, source)
290 outputMessage("#c1c1c1O seu transporte #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi marcado no mapa, usar #00FF66F11#c1c1c1 para encontrá-lo.", source, 38, 122, 216, true)
291 else
292 local attached = getAttachedElements(vehicle)
293 if (attached) then
294 for k,element in ipairs(attached) do
295 if getElementType(element) == "blip" then
296 destroyElement(element)
297 end
298 end
299 end
300 setElementData(vehicle, "ABlip", false)
301 outputMessage("#c1c1c1O seu veÃculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1teve o blip removido.", source, 38, 122, 216, true)
302 end
303 else
304 outputMessage("#c1c1c1O seu veiculo não está spawnado.", source, 38, 122, 216, true)
305 end
306end)
307
308addEvent("FixMyVehicle", true)
309addEventHandler("FixMyVehicle", root,
310function(id)
311 if getPlayerMoney(source) >= tonumber(500) then
312 takePlayerMoney ( source, 500 )
313 local vehicle = getVehicleByID(id)
314 if isElement(vehicle) then
315 fixVehicle(vehicle)
316 setVehicleEngineState(vehicle, true)
317 if isVehicleDamageProof(vehicle) then
318 setVehicleDamageProof(vehicle, false)
319 end
320 end
321 dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND ID = ?", 1000, getAccountName(getPlayerAccount(source)), id)
322 updateVehicleInfo(source)
323 outputMessage ("#c1c1c1O seu transporte foi reparado.", source, 38, 122, 216, true)
324 else
325 outputMessage("#c1c1c1Você não tem dinheiro suficiente para reparar.", source, 38, 122, 216, true)
326 outputMessage("#c1c1c1Preço: #00FF66$500.", source, 38, 122, 216, true)
327 end
328end)
329
330addEvent("WarpMyVehicle", true)
331addEventHandler("WarpMyVehicle", root,
332function(id)
333 if not isPedInVehicle (source) then
334 if getElementInterior(source) == 0 then
335 if getPlayerMoney(source) >= tonumber(500) then
336 local vehicle = getVehicleByID(id)
337 if isElement(vehicle) then
338 takePlayerMoney ( source, 500 )
339 local x, y, z = getElementPosition(source)
340 setElementPosition(vehicle, x, y, z)
341 warpPedIntoVehicle ( source, vehicle )
342 outputMessage ("#c1c1c1O seu veiculo #00FF66"..(customCarNames[getElementModel(vehicle)] or getVehicleNameFromModel(getElementModel(vehicle))).." #c1c1c1foi entregue a você.", source, 38, 122, 216, true)
343 else
344 outputMessage("#c1c1c1O seu veiculo não está spawnado.", source, 38, 122, 216, true)
345 end
346 else
347 outputMessage("#c1c1c1Você não tem os meios de se teletransportar para o veiculo.", source, 38, 122, 216, true)
348 end
349 else
350 outputMessage("#c1c1c1Você só poderá mudar de veiculo se sair do atual.", source, 38, 122, 216, true)
351 end
352 else
353outputMessage("#c1c1c1Nós não podemos dirigir seu veiculo. Por favor, sair do outro veiculo.", source, 38, 122, 216, true)
354 end
355end)
356
357addEvent("SellMyVehicle", true)
358addEventHandler("SellMyVehicle", root,
359function(id)
360 local vehicle = getVehicleByID(id)
361 local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1)
362 if type(data) == "table" and #data ~= 0 then
363 local Money = math.ceil((data[1]["Cost"]*.9)*math.floor(data[1]["HP"])/100/10)
364 givePlayerMoney (source, Money)
365 if isElement(vehicle) then destroyElement(vehicle) end
366 dbExec(db, "DELETE FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id)
367 updateVehicleInfo(source)
368 outputMessage("#c1c1c1Você vendeu o seu veiculo por #00FF66$"..Money, source, 38, 122, 216, true)
369 end
370end)
371
372function getDataOnLogin(_, account)
373 updateVehicleInfo(source)
374end
375addEventHandler("onPlayerLogin", root, getDataOnLogin)
376
377function SaveVehicleDataOnQuit()
378 for i, veh in ipairs (getElementsByType("vehicle")) do
379 if getElementData(veh, "Owner") == source then
380 destroyVehicle(veh)
381 end
382 end
383end
384addEventHandler("onPlayerQuit", root,SaveVehicleDataOnQuit)
385
386
387addEvent("inviteToBuyCarSended", true)
388addEventHandler("inviteToBuyCarSended", root,
389function(player, price, veh_name, veh_id)
390 if player and price and veh_name and veh_id then
391 local pl = getPlayerFromName ( player )
392 if pl then
393 triggerClientEvent ( pl, "recieveInviteToBuyCar", pl, getPlayerName (source), getAccountName(getPlayerAccount(source)), price, veh_name, veh_id )
394 else
395 outputMessage ( "#c1c1c1O jogador não foi encontrado, a venda foi cancelada", source, 250, 10, 10, true)
396 triggerClientEvent ( source, "cleanCarInvitations", source )
397 end
398 end
399end)
400
401
402addEvent("invitationBuyCarNotAccepted", true)
403addEventHandler("invitationBuyCarNotAccepted", root,
404function(player, acc, price, veh_name, veh_id)
405 local pl = getPlayerFromName ( player )
406 if pl then
407 triggerClientEvent ( pl, "cleanCarInvitations", pl )
408 outputMessage ( "#c1c1c1O jogador recusou-se a comprar o seu carro", pl, 250, 10, 10,true)
409 end
410end)
411
412addEvent("invitationBuyCarAccepted", true)
413addEventHandler("invitationBuyCarAccepted", root,
414function(player, acc, price, veh_name, veh_id)
415 local pl = getPlayerFromName ( player )
416 local avail = false
417 if pl and getAccountName ( getPlayerAccount (pl)) == acc then
418 avail = true
419 triggerClientEvent ( pl, "cleanCarInvitations", pl )
420 --outputMessage ( "Игрок отказалÑÑ Ð¿Ð¾ÐºÑƒÐ¿Ð°Ñ‚ÑŒ ваше авто", pl, 250, 10, 10)
421 else
422 for i, v in ipairs( getElementsByType ( 'player' ) ) do
423 if getAccountName(getPlayerAccount ( v )) == acc then
424 avail = true
425 pl = v
426 break
427 end
428 end
429 end
430 price = tonumber(price) or 0
431 if avail then
432 if isGuestAccount ( getPlayerAccount ( source ) ) then
433 triggerClientEvent ( pl, "cleanCarInvitations", pl )
434 outputMessage ( "#c1c1c1Você não está logado em sua conta, a transação foi cancelada", source, 250, 10, 10,true )
435 outputMessage ( "#c1c1c1O jogador não entrou na conta, a transação foi cancelada", pl, 250, 10, 10,true )
436 return true
437 end
438 if getPlayerMoney ( source ) >= price then
439 local vehicle = getVehicleByID(tonumber(veh_id))
440 local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(pl)), veh_id), -1)
441 if type(data) == "table" and #data ~= 0 and isElement ( vehicle ) then
442 givePlayerMoney ( pl, price )
443 takePlayerMoney ( source, price )
444 dbExec(db, "UPDATE VehicleList SET Account = ? WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), getAccountName(getPlayerAccount(pl)), veh_id)
445 updateVehicleInfo(source)
446 updateVehicleInfo(pl)
447 setElementData(vehicle, "Owner", source)
448 setElementData(vehicle, "ownercar", getAccountName(getPlayerAccount(source)))
449 outputMessage("#c1c1c1Você vendeu o seu veiculo por #00FF66$"..price, pl, 38, 122, 216, true)
450 outputMessage("#c1c1c1Você comprou um carro por #00FF66$"..price, source, 38, 122, 216, true)
451 triggerClientEvent ( pl, "cleanCarInvitations", pl )
452 else
453 outputMessage ( "#c1c1c1A máquina não pode ser encontrado, o negócio é cancelado", source, 250, 10, 10,true )
454 outputMessage ( "#c1c1c1A máquina não pode ser encontrado, o negócio é cancelado. Tente carro desova.", pl, 250, 10, 10,true )
455 triggerClientEvent ( pl, "cleanCarInvitations", pl )
456 end
457 else
458 outputMessage ( "#c1c1c1Você não tem dinheiro suficiente, a transação foi cancelada", source, 250, 10, 10,true )
459 end
460 else
461 outputMessage ( "#c1c1c1O jogador não foi encontrado, a operação foi cancelada", source, 250, 10, 10,true)
462 end
463end)
464
465
466function outputMessage (text, player, r, g, b)
467 return exports["scr-Lib"]:outputMessage(player, text, r, g, b);
468end