forked from CN-DST-DEVELOPER/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponentutil.lua
More file actions
60 lines (53 loc) · 2.08 KB
/
componentutil.lua
File metadata and controls
60 lines (53 loc) · 2.08 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
require("components/raindome") --load some global functions defined for this component
require("components/temperatureoverrider") --load some global functions defined for this component
local GroundTiles = require("worldtiledefs")
--require_health being true means an entity is considered "dead" if it lacks the health replica.
function IsEntityDead(inst, require_health)
local health = inst.replica.health
if health == nil then
return require_health == true
end
return health:IsDead()
end
function IsEntityDeadOrGhost(inst, require_health)
if inst:HasTag("playerghost") then
return true
end
return IsEntityDead(inst, require_health)
end
function GetStackSize(inst)
local stackable = inst.replica.stackable
return stackable and stackable:StackSize() or 1
end
function HandleDugGround(dug_ground, x, y, z)
local spawnturf = GroundTiles.turf[dug_ground] or nil
if spawnturf ~= nil then
local loot = SpawnPrefab("turf_"..spawnturf.name)
if loot.components.inventoryitem ~= nil then
loot.components.inventoryitem:InheritWorldWetnessAtXZ(x, z)
end
loot.Transform:SetPosition(x, y, z)
if loot.Physics ~= nil then
local angle = math.random() * 2 * PI
loot.Physics:SetVel(2 * math.cos(angle), 10, 2 * math.sin(angle))
end
else
SpawnPrefab("sinkhole_spawn_fx_"..tostring(math.random(3))).Transform:SetPosition(x, y, z)
end
end
local VIRTUALOCEAN_HASTAGS = {"virtualocean"}
local VIRTUALOCEAN_CANTTAGS = {"INLIMBO"}
function FindVirtualOceanEntity(x, y, z, r)
local ents = TheSim:FindEntities(x, y, z, r or MAX_PHYSICS_RADIUS, VIRTUALOCEAN_HASTAGS, VIRTUALOCEAN_CANTTAGS)
for _, ent in ipairs(ents) do
if ent.Physics ~= nil then
local radius = ent.Physics:GetRadius()
local ex, ey, ez = ent.Transform:GetWorldPosition()
local dx, dz = ex - x, ez - z
if dx * dx + dz * dz <= radius * radius then
return ent
end
end
end
return nil
end