-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsv_pizzajob.lua
115 lines (91 loc) · 3.38 KB
/
sv_pizzajob.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
local Server = lib.require('sv_config')
local players = {}
local function createPizzaVehicle(source)
local veh = CreateVehicle(Server.Vehicle, Server.VehicleSpawn.x, Server.VehicleSpawn.y, Server.VehicleSpawn.z, Server.VehicleSpawn.w, true, true)
local ped = GetPlayerPed(source)
while not DoesEntityExist(veh) do Wait(0) end
while GetVehiclePedIsIn(ped, false) ~= veh do
TaskWarpPedIntoVehicle(ped, veh, -1)
Wait(0)
end
return NetworkGetNetworkIdFromEntity(veh)
end
lib.callback.register('randol_pizzajob:server:spawnVehicle', function(source)
if players[source] then return false end
local src = source
local netid = createPizzaVehicle(src)
local generatedLocs = {}
local addedLocs = {}
while #generatedLocs < Server.Deliveries do
local index = math.random(#Server.Locations)
if not addedLocs[index] then
local randomLoc = Server.Locations[index]
generatedLocs[#generatedLocs + 1] = randomLoc
addedLocs[index] = true
end
end
local currentLocIndex = math.random(#generatedLocs)
local currentLoc = generatedLocs[currentLocIndex]
table.remove(generatedLocs, currentLocIndex)
local payout = math.random(Server.Payout.min, Server.Payout.max)
players[src] = {
entity = NetworkGetEntityFromNetworkId(netid),
locations = generatedLocs,
payment = payout,
current = currentLoc,
}
return netid, players[src]
end)
lib.callback.register('randol_pizzajob:server:clockOut', function(source)
local src = source
if players[src] then
local ent = players[src].entity
if DoesEntityExist(ent) then
DeleteEntity(ent)
end
players[src] = nil
return true
end
return false
end)
lib.callback.register('randol_pizzajob:server:Payment', function(source)
local src = source
local Player = GetPlayer(src)
local pos = GetEntityCoords(GetPlayerPed(src))
if not players[src] or #(pos - players[src].current) > 5.0 then
handleExploit(src, 'Exploiting Pizza Job.')
return false
end
AddMoney(Player, Server.Account, players[src].payment)
if #players[src].locations == 0 then
DoNotification(src, ('You received $%s. No more deliveries left, return the vehicle.'):format(players[src].payment))
return true
end
DoNotification(src, ('You received $%s. Deliveries left: %s'):format(players[src].payment, #players[src].locations))
local index = math.random(#players[src].locations)
local newLoc = players[src].locations[index]
local payout = math.random(Server.Payout.min, Server.Payout.max)
table.remove(players[src].locations, index)
players[src].current = newLoc
players[src].payment = payout
return true, players[src]
end)
AddEventHandler("playerDropped", function()
local src = source
if players[src] then
local ent = players[src].entity
if DoesEntityExist(ent) then
DeleteEntity(ent)
end
players[src] = nil
end
end)
function ServerOnLogout(source)
if players[source] then
local ent = players[src].entity
if DoesEntityExist(ent) then
DeleteEntity(ent)
end
players[source] = nil
end
end