forked from Project-Sloth/ps-housing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.lua
129 lines (89 loc) · 3.34 KB
/
shell.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
Shells = {}
Shell = {
entity = nil,
hash = nil,
position = nil,
rotation = nil,
shellData = nil,
oldCoord = nil,
exitTarget = nil,
}
Shell.__index = Shell
function Shell:SpawnShell(shellHash, position, rotation)
lib.requestModel(shellHash)
local entity = CreateObjectNoOffset(shellHash, position.x, position.y, position.z, false, false, false)
FreezeEntityPosition(entity, true)
SetEntityRotation(entity, rotation, 2, true)
SetModelAsNoLongerNeeded(shellHash)
return entity
end
function Shell:DespawnShell()
if DoesEntityExist(self.entity) then
DeleteEntity(self.entity)
end
if self.exitTarget then
Framework[Config.Target].RemoveTargetZone(self.exitTarget)
end
self = nil
end
function Shell:CreatePropertyShell(shellName, position, rotation)
local self = setmetatable({}, Shell)
self.shellData = Config.Shells[shellName]
self.hash = self.shellData.hash
self.position = position
self.rotation = rotation or vector3(0.0, 0.0, 0.0)
self.entity = self:SpawnShell(self.hash, self.position, self.rotation)
return self
end
-- example of how to use
-- exports["ps-housing"]:CreateTempShell("Modern Hotel", GetEntityCoords(PlayerPedId()), GetEntityRotation(PlayerPedId()), function()
-- Framework[Config.Notify].Notify("You left the shell", "error")
-- local coords = GetEntityCoords(PlayerPedId())
-- SetEntityCoordsNoOffset(PlayerPedId(), coords.x, coords.y, coords.z + 50.0, false, false, true)
-- end)
-- this is used as a constructor for third party scripts
function Shell:CreateTempShell(shellName, position, rotation, leaveCb)
local self = setmetatable({}, Shell)
self.shellData = Config.Shells[shellName]
self.hash = self.shellData.hash
self.position = position
self.rotation = rotation
DoScreenFadeOut(250)
Wait(250)
self.oldCoord = GetEntityCoords(PlayerPedId())
self.entity = self:SpawnShell(self.hash, self.position, self.rotation)
local doorOffset = self.shellData.doorOffset
local offset = GetOffsetFromEntityInWorldCoords(self.entity, doorOffset.x, doorOffset.y, doorOffset.z)
SetEntityCoordsNoOffset(cache.ped, offset.x, offset.y, offset.z, false, false, true)
SetEntityHeading(cache.ped, self.shellData.doorOffset.h)
local coords = offset
local size = vector3(1.0, self.shellData.doorOffset.width, 3.0)
local heading = self.shellData.doorOffset.h
local function leave()
DoScreenFadeOut(250)
Wait(250)
SetEntityCoordsNoOffset(PlayerPedId(), self.oldCoord.x, self.oldCoord.y, self.oldCoord.z, false, false, true)
if leaveCb then
leaveCb()
end
self:DespawnShell()
Wait(250)
DoScreenFadeIn(250)
end
self.exitTarget = Framework[Config.Target].AddDoorZoneInsideTempShell(coords, size, heading, leave)
Wait(250)
DoScreenFadeIn(250)
Shells[self.entity] = self
return self.entity
end
exports('CreateTempShell', function(shellName, position, rotation, leaveCb)
return Shell:CreateTempShell(shellName, position, rotation, leaveCb)
end)
exports("GetShellData", function (shellName)
return Config.Shells[shellName]
end)
exports("DespawnTempShell", function (shellEntity)
if Shells[shellEntity] then
Shells[shellEntity]:DespawnShell()
end
end)