-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
79 lines (58 loc) · 1.77 KB
/
client.lua
File metadata and controls
79 lines (58 loc) · 1.77 KB
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
local QBCore = exports['qb-core']:GetCoreObject()
local function changePlayerModel(pedModel)
local modelHash = GetHashKey(pedModel)
RequestModel(modelHash)
while not HasModelLoaded(modelHash) do
Wait(100)
end
SetPlayerModel(PlayerId(), modelHash)
SetPedDefaultComponentVariation(PlayerPedId())
SetModelAsNoLongerNeeded(modelHash)
QBCore.Functions.Notify("You have changed to the new ped model!", "success")
end
local function spawnPed(pedModel, coords, heading)
RequestModel(pedModel)
while not HasModelLoaded(pedModel) do
Wait(1)
end
if not HasModelLoaded(pedModel) then
return nil
end
local ped = CreatePed(4, pedModel, coords.x, coords.y, coords.z, heading, false, true)
if DoesEntityExist(ped) then
else
return nil
end
SetEntityInvincible(ped, true)
SetBlockingOfNonTemporaryEvents(ped, true)
TaskStartScenarioInPlace(ped, "WORLD_HUMAN_STAND_IMPATIENT", 0, true)
return ped
end
local function addPedInteraction(ped, pedModel)
exports.ox_target:addLocalEntity(ped, {
{
name = 'ped_interaction',
icon = 'fas fa-user',
label = "Become this Ped",
onSelect = function()
changePlayerModel(pedModel)
end,
distance = 2.5
}
})
end
local function spawnAllPeds()
for _, pedData in ipairs(Config.Peds) do
local ped = spawnPed(pedData.model, pedData.location, pedData.heading)
if ped then
addPedInteraction(ped, pedData.model)
else
end
end
end
RegisterNetEvent('myScript:spawnAllPeds', function()
spawnAllPeds()
end)
RegisterCommand("spawnpeds", function()
TriggerServerEvent('myScript:spawnAllPeds')
end)