-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
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 | ||
|
||
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() | ||
if leaveCb then | ||
leaveCb() | ||
else | ||
SetEntityCoordsNoOffset(PlayerPedId(), self.oldCoord.x, self.oldCoord.y, self.oldCoord.z, false, false, true) | ||
end | ||
|
||
self:DespawnShell() | ||
end | ||
|
||
self.exitTarget = Framework[Config.Target].AddDoorZoneInsideTempShell(coords, size, heading, leave) | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters