Skip to content

Commit a6e6884

Browse files
committed
Version 0.5.6a
- added persistent chests / stashes - refactoring of entities - updated docs
1 parent 03ff4c3 commit a6e6884

File tree

9 files changed

+945
-65
lines changed

9 files changed

+945
-65
lines changed

Data/Entities/ChestEntity.ent

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Entity
2+
Name="ChestEntity"
3+
Script="Scripts/Entities/arc_ChestEntity.lua"
4+
/>

Data/Scripts/Controller/arc_ConstructionController.lua

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---
66

77
-- the set of already created constructions
8-
-- this set will be empty onload of a game, only is used during runtime
8+
-- this set will be empty onload of a game and is only used during runtime
99
builtEntities = {}
1010

1111
-- the current index of the building-selection
@@ -17,6 +17,7 @@ classesWhiteList = {
1717
"BathEntity",
1818
"BedEntity",
1919
"ChairEntity",
20+
"ChestEntity",
2021
"CookingSpotEntity",
2122
"DynamicBuildingEntity",
2223
"ECSManager",
@@ -203,7 +204,6 @@ function spawnPreview()
203204

204205
end
205206

206-
207207
-- spawn the currently selected entity with the current selection as modelpath
208208
function SpawnBuildingInstance(line)
209209

@@ -231,6 +231,7 @@ function SpawnBuildingInstance(line)
231231
-- System.LogAlways("Hit entity: " .. tostring(entity))
232232

233233
-- construct the entity and setup its parameters
234+
-- creating an entity this way does not consider how it got persistet - take a look at the entity classes for more information.
234235
local spawnParams = {}
235236

236237
-- use arc_BasicBuildingEntity.lua as type for static constructions
@@ -278,6 +279,17 @@ function SpawnBuildingInstance(line)
278279
spawnParams.class = "CustomShootingTarget"
279280
end
280281

282+
if(construction.stash) then
283+
spawnParams.class = "ChestEntity"
284+
285+
-- skip the check if the player is infront of the chest
286+
spawnParams.properties.bSkipAngleCheck = 1
287+
spawnParams.properties.fUseDistance = 2
288+
289+
spawnParams.properties.soclasses_SmartObjectHelpers = "Chest"
290+
spawnParams.properties.sWH_AI_EntityCategory = "Chest"
291+
end
292+
281293
if (construction.useable) then
282294

283295
if (construction.useCategory == "addDirt") then
@@ -364,13 +376,13 @@ function SpawnBuildingInstance(line)
364376
if construction.sleepable then
365377
end
366378

367-
if (construction.useable) then
379+
if construction.useable then
368380
end
369381

370-
if (construction.cookingSpot) then
382+
if construction.cookingSpot then
371383
end
372384

373-
if (construction.generator) then
385+
if construction.generator then
374386
end
375387

376388
-- setup the rotation of the spawned entity align the y-axis
@@ -403,6 +415,88 @@ function SpawnBuildingInstance(line)
403415
System.LogAlways("# SpawnBuildingInstance end")
404416
end
405417

418+
function rayCastHitSimple()
419+
420+
-- if the mod is not enabled, dont do anything -- needs refactoring
421+
if not config.modEnabled then
422+
return
423+
end
424+
425+
System.LogAlways("# rayCastHit start")
426+
427+
local from = player:GetPos();
428+
from.z = from.z + 1.615;
429+
430+
local dir = System.GetViewCameraDir();
431+
dir = vecScale(dir, 250);
432+
433+
-- if previewModelEntity == nil then
434+
-- -- previewModelEntity = player -- wtf!
435+
-- System.LogAlways("ERROR - hit == player !?")
436+
-- return
437+
-- end
438+
439+
440+
local hitData = {};
441+
local hits = Physics.RayWorldIntersection(from, dir, 10, ent_all, player.id, nil, hitData);
442+
443+
if hits > 0 then
444+
dump(hitData[1])
445+
return hitData[1];
446+
end
447+
448+
System.LogAlways("# rayCastHit end")
449+
450+
end
451+
452+
function spawnmulti()
453+
spawnSimple("Objects/buildings/houses/executioners_house/executioners_house_basefloor.cgf")
454+
spawnSimple("Objects/buildings/houses/executioners_house/executioners_house_basefloor_int.cgf")
455+
spawnSimple("Objects/buildings/houses/executioners_house/executioners_house_basewall.cgf ")
456+
spawnSimple("Objects/buildings/houses/executioners_house/executioners_house_roof.cgf")
457+
end
458+
459+
-- spawn the currently selected entity with the current selection as modelpath
460+
function spawnSimple(line)
461+
462+
System.LogAlways("# SpawnBuildingInstance start - spawning " .. line)
463+
hitData = rayCastHitSimple()
464+
if (hitData ~= nil) then
465+
local entity = hitData
466+
local spawnParams = {}
467+
spawnParams.class = "BasicBuildingEntity"
468+
spawnParams.position = entity.pos
469+
spawnParams.orientation = { x = 0, y = 0, z = 1 }
470+
spawnParams.properties = {}
471+
spawnParams.properties.bSaved_by_game = 1
472+
spawnParams.properties.bSerialize = 1
473+
spawnParams.properties.object_Model = line
474+
475+
spawnParams.name = "spawn_multi_"
476+
spawnParams.uuid = uuid()
477+
478+
local ent = System.SpawnEntity(spawnParams)
479+
local up = player:GetAngles()
480+
481+
up = { up.x, up.y, up.z }
482+
ent:SetAngles(up)
483+
484+
-- setup flags
485+
-- See: https://forums.nexusmods.com/index.php?/topic/8540368-environment-effects-ignore-collision-like-rain-fog/
486+
ent:SetFlags(ENTITY_FLAG_RAIN_OCCLUDER, 1)
487+
ent:SetFlags(ENTITY_FLAG_CASTSHADOW, 1)
488+
489+
Game.SendInfoText(
490+
"Constructing " .. tostring(ent:GetName())
491+
, true, nil, 2)
492+
493+
-- undo / redo control, build history
494+
table.insert(builtEntities, ent)
495+
496+
end
497+
498+
System.LogAlways("# SpawnBuildingInstance end")
499+
end
406500

407501
-- locks every entity which is a member of a whitelist element
408502
function lockAll()
@@ -591,9 +685,8 @@ function deleteRayCastEntityHit()
591685
-- so we keep a whitelist of everything - if the hit entity is within the list, the entity will get deleted
592686
if (contains(classesWhiteList, result.class)) then
593687

594-
-- if there is something to delete, log its name to the player first
595-
596-
if (result.Properties.deletion_lock == false) then
688+
-- if something hasnt got locked explicitly or it doesnt contain a deletion_lock
689+
if (result.Properties.deletion_lock == false or result.Properties.deletion_lock == nil) then
597690

598691
visRes = "Removing construction: " .. tostring(result:GetName())
599692

Data/Scripts/Entities/arc_BasicBuildingEntity.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ BasicBuildingEntity = {
1717
bTurnedOn = 1,
1818

1919
bSaved_by_game = 1,
20-
Saved_by_game = 1,
2120
bSerialize = 1,
2221
deletion_lock = false,
2322

Data/Scripts/Entities/arc_BedEntity.lua

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ BedEntity = {
7474
}
7575

7676
function BedEntity:OnSpawn()
77-
if (self.Properties.MultiplayerOptions.bNetworked == 0) then
78-
self:SetFlags(ENTITY_FLAG_CLIENT_ONLY, 0);
79-
end
80-
8177
self.bRigidBodyActive = 1;
8278

8379
self:SetFromProperties();
@@ -86,54 +82,22 @@ end
8682
function BedEntity:SetFromProperties()
8783
local Properties = self.Properties;
8884

89-
if (Properties.object_Model == "") then
90-
do
91-
return
92-
end ;
93-
end
94-
9585
self:SetupModel();
96-
if (Properties.bAutoGenAIHidePts == 1) then
97-
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 0);
98-
else
99-
self:SetFlags(ENTITY_FLAG_AI_HIDEABLE, 2);
100-
end
101-
102-
if (self.Properties.bCanTriggerAreas == 1) then
103-
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 0);
104-
else
105-
self:SetFlags(ENTITY_FLAG_TRIGGER_AREAS, 2);
106-
end
107-
108-
-- setup entity flags
10986
self:SetFlags(ENTITY_FLAG_RAIN_OCCLUDER, 1)
11087
self:SetFlags(ENTITY_FLAG_CASTSHADOW, 1)
111-
11288
end
11389

11490
function BedEntity:SetupModel()
115-
11691
local Properties = self.Properties;
117-
118-
System.LogAlways("SetupModel")
119-
System.LogAlways("self.Properties.object_model: " .. Properties.object_Model)
120-
-- System.LogAlways("self.Properties.object_model: " .. Properties.object_Model)
121-
12292
self:LoadObject(0, Properties.object_Model);
123-
12493
self:PhysicalizeThis();
125-
126-
-- disable near fade-out by default
12794
self:SetViewDistUnlimited()
12895
end
12996

13097

13198
--
13299
function BedEntity:OnLoad(table)
133-
self.object_Model = table.object_Model;
134-
135-
local Properties = self.Properties;
136-
Properties.object_Model = table.object_Model;
100+
self.Properties.object_Model = table.object_Model;
137101

138102
-- load the persisted model path from the save file
139103
self:LoadObject(0, table.object_Model)

0 commit comments

Comments
 (0)