-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv_crypto.lua
173 lines (146 loc) · 6.68 KB
/
sv_crypto.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
local cryptoprice = 0
local url = "https://blockchain.info/ticker"
local cfg = module("cfg/cfg_crypto")
function getBitcoinCurrentPrice()
local p = promise.new()
PerformHttpRequest(url, function(err, res)
local res = json.decode(res)
price = res.GBP.buy
if err == 200 then
p:resolve(res.GBP.buy)
end
end)
cryptoprice = Citizen.Await(p)
end
Citizen.CreateThread(function()
while true do
getBitcoinCurrentPrice()
Citizen.Wait(5000)
end
end)
RegisterServerEvent('vRPCryptocore:getCryptoPrice', function()
TriggerClientEvent('vRPCryptocore:setCryptoPrice', source, cryptoprice)
end)
function CalculateBitcoin(amount)
return cryptoprice * amount
end
RegisterServerEvent('vRPCrypto:Withdraw:Crypto')
AddEventHandler('vRPCrypto:Withdraw:Crypto', function(system)
local source = source
local user_id = vRP.getUserId(source)
local player_coords = GetEntityCoords(GetPlayerPed(source))
local x,y,z = table.unpack(cfg.coords)
local manage_spot = vector3(x,y,z)
local amount_bank = roundToWholeNumber(CalculateBitcoin(system.amountmined))
if system.user_id == user_id then
if #(player_coords - manage_spot) < 5 then
exports['ghmattimysql']:executeSync("UPDATE c_cryptominers SET amountmined = 0 WHERE user_id = @user_id AND machineid = @machineid", {user_id = user_id, machineid = system.machineid}, function() end)
vRP.giveBankMoney(user_id, CalculateBitcoin(system.amountmined))
vRPclient.notifyPicture(source,{"CHAR_BANK_MAZE",1,'Crypto Systems',false,"Withdraw Successfull: £"..amount_bank})
else
print(user_id .. " Is Cheating Or He Moved Away From The Mining Spot")
end
else
print(user_id .. " Is Cheating")
end
end)
RegisterServerEvent('vRPCrypto:Sell:System')
AddEventHandler('vRPCrypto:Sell:System', function(system)
local source = source
local user_id = vRP.getUserId(source)
local system_user_id = system.user_id
local player_coords = GetEntityCoords(GetPlayerPed(source))
local x,y,z = table.unpack(cfg.coords)
local manage_spot = vector3(x,y,z)
local sell_amount = roundToWholeNumber(cfg.systems[system.pc_id].price / 4)
if system_user_id == user_id then
if #(player_coords - manage_spot) < 5 then
exports['ghmattimysql']:executeSync("DELETE FROM c_cryptominers WHERE user_id = @user_id AND machineid = @machineid", {user_id = user_id, machineid = system.machineid}, function()end)
vRP.giveMoney(user_id,sell_amount)
vRPclient.notifyPicture(source,{"CHAR_BANK_MAZE",1,'Crypto Systems',false,"You've been paid! Amount: £"..sell_amount})
else
print(user_id .. " Is Cheating Or He Moved Away From The Mining Spot")
end
else
print(user_id .. " Is Cheating")
end
end)
RegisterServerEvent("vRPCrypto:buy_crypto_system")
AddEventHandler("vRPCrypto:buy_crypto_system", function(system)
local player = source
local price = system.price
local idofmachine = system.id
local amountPerMin = system.amountPerMin
local user_id = vRP.getUserId(player)
local player_coords = GetEntityCoords(GetPlayerPed(player))
local x,y,z = table.unpack(cfg.coords)
local system_coords = vector3(x,y,z)
if #(player_coords - system_coords) < 7 then
if vRP.tryPayment(user_id,system.price) then
vRPclient.notify(player, {"~b~You bought a System For £"..price})
vRPclient.notify(player, {"~p~ We Are Setting Up Your System"})
exports['ghmattimysql']:executeSync("INSERT INTO c_cryptominers(user_id, pc_id,amountmined) VALUES( @user_id, @pc_id, @amountmined)", {user_id = user_id, pc_id = idofmachine, amountmined = 0}, function() end)
else
vRPclient.notify(player, {"~r~You Do Not Have Enough Money In Your Wallet To Pay The Man."})
end
else
print(user_id ..' Might Be Cheating, Take A Look')
end
end)
RegisterServerEvent("vRPCrypto:CRYPTO:ENTER")
AddEventHandler('vRPCrypto:CRYPTO:ENTER', function()
local player = source
local coords_exit = cfg.exit
local player_coords = GetEntityCoords(GetPlayerPed(player))
local coords_enter = vector3(table.unpack(cfg.enter))
local coords_exit = vector3(table.unpack(cfg.exit))
if #(player_coords - coords_enter) < 5 then
SetEntityCoords(GetPlayerPed(player), coords_exit)
SetPlayerRoutingBucket(player, player+1)
end
end)
RegisterServerEvent("vRPCrypto:CRYPTO:EXIT")
AddEventHandler('vRPCrypto:CRYPTO:EXIT', function()
local player = source
local coords_exit = cfg.exit
local player_coords = GetEntityCoords(GetPlayerPed(player))
local coords_enter = vector3(table.unpack(cfg.enter))
local coords_exit = vector3(table.unpack(cfg.exit))
if #(player_coords - coords_exit) < 6 then
SetEntityCoords(GetPlayerPed(player), coords_enter)
SetPlayerRoutingBucket(player, 0)
end
end)
RegisterServerEvent("vRPCrypto:CRYPTO:ReceiveMiners")
AddEventHandler('vRPCrypto:CRYPTO:ReceiveMiners', function()
local player = source
local user_id = vRP.getUserId(player)
local miners = exports['ghmattimysql']:executeSync("SELECT * FROM c_cryptominers WHERE user_id = @user_id", {user_id = user_id})
TriggerClientEvent('vRPCrypto:CRYPTO:SetMiners', player, miners)
end)
--Citizen.CreateThread(function()
-- while true do
-- Citizen.Wait(60000)
-- systems = exports['ghmattimysql']:executeSync("SELECT * FROM c_cryptominers WHERE user_id = @uid", {uid = user_id})
-- for i,v in pairs(systems) do
-- local pc_id = v.pc_id
-- local pcPricePermMin = cfg.systems[pc_id].amountPerMin
-- exports['ghmattimysql']:executeSync("UPDATE c_cryptominers SET amountmined = @amount WHERE machineid = @muid AND user_id = @uid", {muid = v.machineid, uid = user_id, amount = tonumber(v.amountmined + pcPricePermMin)})
-- end
-- end
--end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(60000)
for i, p in pairs(GetPlayers()) do
local user_id = vRP.getUserId(p)
systems = exports['ghmattimysql']:executeSync("SELECT * FROM c_cryptominers WHERE user_id = @uid", {uid = user_id})
if systems == nil then return end
for i,v in pairs(systems) do
local pc_id = v.pc_id
local pcPricePermMin = cfg.systems[pc_id].amountPerMin
exports['ghmattimysql']:executeSync("UPDATE c_cryptominers SET amountmined = @amount WHERE machineid = @muid AND user_id = @uid", {muid = v.machineid, uid = user_id, amount = tonumber(v.amountmined + pcPricePermMin)})
end
end
end
end)