5
5
---
6
6
7
7
-- 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
9
9
builtEntities = {}
10
10
11
11
-- the current index of the building-selection
@@ -17,6 +17,7 @@ classesWhiteList = {
17
17
" BathEntity" ,
18
18
" BedEntity" ,
19
19
" ChairEntity" ,
20
+ " ChestEntity" ,
20
21
" CookingSpotEntity" ,
21
22
" DynamicBuildingEntity" ,
22
23
" ECSManager" ,
@@ -203,7 +204,6 @@ function spawnPreview()
203
204
204
205
end
205
206
206
-
207
207
-- spawn the currently selected entity with the current selection as modelpath
208
208
function SpawnBuildingInstance (line )
209
209
@@ -231,6 +231,7 @@ function SpawnBuildingInstance(line)
231
231
-- System.LogAlways("Hit entity: " .. tostring(entity))
232
232
233
233
-- 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.
234
235
local spawnParams = {}
235
236
236
237
-- use arc_BasicBuildingEntity.lua as type for static constructions
@@ -278,6 +279,17 @@ function SpawnBuildingInstance(line)
278
279
spawnParams .class = " CustomShootingTarget"
279
280
end
280
281
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
+
281
293
if (construction .useable ) then
282
294
283
295
if (construction .useCategory == " addDirt" ) then
@@ -364,13 +376,13 @@ function SpawnBuildingInstance(line)
364
376
if construction .sleepable then
365
377
end
366
378
367
- if ( construction .useable ) then
379
+ if construction .useable then
368
380
end
369
381
370
- if ( construction .cookingSpot ) then
382
+ if construction .cookingSpot then
371
383
end
372
384
373
- if ( construction .generator ) then
385
+ if construction .generator then
374
386
end
375
387
376
388
-- setup the rotation of the spawned entity align the y-axis
@@ -403,6 +415,88 @@ function SpawnBuildingInstance(line)
403
415
System .LogAlways (" # SpawnBuildingInstance end" )
404
416
end
405
417
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
406
500
407
501
-- locks every entity which is a member of a whitelist element
408
502
function lockAll ()
@@ -591,9 +685,8 @@ function deleteRayCastEntityHit()
591
685
-- so we keep a whitelist of everything - if the hit entity is within the list, the entity will get deleted
592
686
if (contains (classesWhiteList , result .class )) then
593
687
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
597
690
598
691
visRes = " Removing construction: " .. tostring (result :GetName ())
599
692
0 commit comments