Jump to content

[HELP] How to make giants not attack the structure?


Recommended Posts

Or how to make the structure invincible?

for example:

 

local function Invincible( inst )
inst:AddComponent("health")
inst.components.health:SetInvincible(true)
end
AddPrefabPostInit("researchlab2", Invincible)
 
These lines cant make researchlab2 invincible.
Any solution please?
Link to comment
Share on other sites

@Jupiters:

if not GLOBAL.TheNet:GetIsServer() then	returnendlocal _HammerFn = GLOBAL.ACTIONS.HAMMER.fnGLOBAL.ACTIONS.HAMMER.fn = function(act)	act.target.components.workable = act.target.components.hammerworkable	local ret = _HammerFn(act)	act.target.components.workable = nil	return retendlocal function Swap(inst)	inst.components.hammerworkable = inst.components.workable	inst.components.workable = nilendlocal prefabs = {	"researchlab", "researchlab2",}for k, v in pairs(prefabs) do	AddPrefabPostInit(v, Swap)end
Link to comment
Share on other sites

@Jupiters:

Yeah, I forgot.

 

Add this to the code:

AddStategraphPostInit("wilson", function(sg)	local _TimeEvent14 = sg.states["hammer"].timeline[2].fn	sg.states["hammer"].timeline[2].fn = function(inst)		local sm = inst.sg.statemem.action		if sm and sm.target then			sm.target.components.workable = sm.target.components.hammerworkable		end		_TimeEvent14(inst)		if sm and sm.target then			sm.target.components.workable = nil		end	endend)
Link to comment
Share on other sites

Hello @DarkXero
 
This mod seems to collide with the mod "Advanced World Generation and Cave Content".

Need you help. :)
Here is the log:

 

[00:00:41]: [string "scripts/prefabs/altar_prototyper.lua"]:202: attempt to index field 'workable' (a nil value)
LUA ERROR stack traceback:
scripts/prefabs/altar_prototyper.lua:202 in (upvalue) SetState (Lua) <198-211>
   inst = 114036 - ancient_altar (valid:true)
   state = true
scripts/prefabs/altar_prototyper.lua:262 in (method) OnLoad (Lua) <257-263>
   inst = 114036 - ancient_altar (valid:true)
   data = table: 051E2FD8
scripts/entityscript.lua:1455 in (method) SetPersistData (Lua) <1440-1457>
   self (valid:true) =
      GUID = 114036
      Transform = Transform (2DCFC578)
      inlimbo = false
      actionreplica = table: 2DDBB0A8
      event_listening = table: 2DDBC138
      actioncomponents = table: 2DDBAF18
      displaynamefn = function - scripts/prefabs/altar_prototyper.lua:322
      lower_components_shadow = table: 2DDBAEC8
      _activecount = 0
      entity = Entity (2DD75BA0)
      AnimState = AnimState (2DCFC598)
      prefab = ancient_altar
      Light = Light (2DCFC618)
      OnSave = function - scripts/prefabs/altar_prototyper.lua:265
      Network = Network (2DCFC638)
      persists = true
      MiniMapEntity = MiniMapEntity (2DCFC5B8)
      SoundEmitter = SoundEmitter (2DCFC5D8)
      pendingtasks = table: 2DDDCC88
      state = net_bool (2DD82100)
      event_listeners = table: 2DDBC070
      spawntime = 0
      OnLoad = function - scripts/prefabs/altar_prototyper.lua:257
      replica = table: 2DDBAF40
      name = Ancient Pseudoscience Station
      components = table: 2DDBAEF0
      Physics = Physics (2DCFC5F8)
   data = table: 051E2FD8
   newents = table: 132CDF88
scripts/mainfunctions.lua:217 in (global) SpawnSaveRecord (Lua) <186-224>
   saved = table: 051E2FB0
   newents = table: 132CDF88
   inst = 114036 - ancient_altar (valid:true)
scripts/gamelogic.lua:413 in (upvalue) PopulateWorld (Lua) <234-448>
   savedata = table: 0630D858
   profile = table: 079EB028
   world = 100022 - forest (valid:true)
   retune = table: 132CD128
   newents = table: 132CDF88
   prefab = ancient_altar
   ents = table: 051E2F88
   prefab = ancient_altar
   k = 1
   v = table: 051E2FB0
scripts/gamelogic.lua:639 in (upvalue) DoInitGame (Lua) <527-741>
   savedata = table: 0630D858
   profile = table: 079EB028
   was_file_load = false
scripts/gamelogic.lua:773 in (upvalue) cb (Lua) <768-774>
   savedata = table: 0630D858
scripts/saveindex.lua:124 in () ? (Lua) <106-125>
   load_success = true
   str = return {world_network={persistdata={clock={moonphase="quarter",cycles=83,phase="day",remainingtimeinphase=175.04804992676,totaltimeinphase=240,segs={night=2,day=8,dusk=6}},seasons={elapseddaysinseason=13,premode=false,remainingdaysinseason=7,lengths={summer=15,autumn=20,spring=20,winter=15},totaldaysinseason=20,mode="cycle",season="autumn",segs={summer={night=4,day=11,dusk=1},autumn={night=2,day=8,dusk=6},spring={night=3,day=5,dusk=8},winter={night=6,day=5,dusk=5}}},weather={seasontemperature=22.5,preciptype="rain",daylight=true,moistureceil=8175.3959960938,peakprecipitationrate=0.2890365421772,season="autumn",moisturerateval=0.33174451956625,lightningmode="rain",moistureceilmultiplier=8,moisture=3779.7485351563,wet=true,stopsnowthreshold=0,snowlevel=0,moisturefloormultiplier=1,moisturerateoffset=0,noisetime=40181.7421875,moisturerate=0.33174452185631,wetness=100,nextlightningtime=42.701252688882,startsnowthreshold=-5,precipmode="dynamic",moisturefloor=2408.4946289063,moistureratemultiplier=1,phasetemperature [**truncated**]
   success = true
   savedata = table: 0630D858
=[C]:-1 in (method) GetPersistentString © <-1--1>
scripts/saveindex.lua:106 in (method) GetSaveDataFile (Lua) <105-126>
   self =
      data = table: 079EB140
      current_slot = 1
   file = session/010000A97F0F71AA/0000000086
   cb = function - scripts/gamelogic.lua:768
scripts/saveindex.lua:132 in (method) GetSaveData (Lua) <128-136>
   self =
      data = table: 079EB140
      current_slot = 1
   slot = 1
   cb = function - scripts/gamelogic.lua:768
   file = session/010000A97F0F71AA/0000000086
scripts/gamelogic.lua:775 in (upvalue) DoLoadWorld 
[00:00:41]: [string "scripts/prefabs/altar_prototyper.lua"]:202: attempt to index field 'workable' (a nil value)
LUA ERROR stack traceback:
    scripts/prefabs/altar_prototyper.lua:202 in (upvalue) SetState (Lua) <198-211>
    scripts/prefabs/altar_prototyper.lua:262 in (method) OnLoad (Lua) <257-263>
    scripts/entityscript.lua:1455 in (method) SetPersistData (Lua) <1440-1457>
    scripts/mainfunctions.lua:217 in (global) SpawnSaveRecord (Lua) <186-224>
    scripts/gamelogic.lua:413 in (upvalue) PopulateWorld (Lua) <234-448>
    scripts/gamelogic.lua:639 in (upvalue) DoInitGame (Lua) <527-741>
    scripts/gamelogic.lua:773 in (upvalue) cb (Lua) <768-774>
    scripts/saveindex.lua:124 in () ? (Lua) <106-125>
    =[C]:-1 in (method) GetPersistentString © <-1--1>
    scripts/saveindex.lua:106 in (method) GetSaveDataFile (Lua) <105-126>
    scripts/saveindex.lua:132 in (method) GetSaveData (Lua) <128-136>
    scripts/gamelogic.lua:775 in (upvalue) DoLoadWorld (Lua) <767-776>

Advanced World Generation and Cave Content.zip

Invincible Structures.zip

Link to comment
Share on other sites

Hello, @DarkXero

 

In another mod's modmain.lua, I wrote this to make the giant not take the initiative to attack players' structure. 

 

local require = GLOBAL.require
local combat = require "components/combat"
 
local combat_CanTarget_base = combat.CanTarget
function combat:CanTarget(target, ...)
    if target:HasTag("structure") and self.inst:HasTag("monster") or self.inst:HasTag("epic") then
        return false
    end
    return combat_CanTarget_base(self, target, ...)
end

 

But it has a crash:

 

[09:09:30]: [string "../mods/workshop-502999570/modmain.lua"]:6: attempt to index local 'target' (a nil value)
LUA ERROR stack traceback:
../mods/workshop-502999570/modmain.lua:6 in (method) CanTarget (Lua) <5-10>
self =
hiteffectsymbol = torso
GetGiveUpString = function - scripts/prefabs/player_common.lua:10
defaultdamage = 10
forcefacing = true
inst = 212111 - wathgrithr (valid:true)
hitrange = 2
lastwasattackedtime = 32809.868377835
playerdamagepercent = 1
pvp_damagemod = 0.5
GetBattleCryString = function - scripts/prefabs/player_common.lua:14
lastattacker = 211119 - mosquito (valid:true)
damagemultiplier = 1.25
keeptargettimeout = 0
battlecryenabled = true
_ = table: 270920B0
laststartattacktime = 0
target = nil
arg = nil
scripts/components/playercontroller.lua:753 in (method) OnRemoteControllerAttackButton (Lua) <740-771>
self =
isclientcontrollerattached = true
predictionsent = false
controller_target_age = 1.#INF
draggingonground = false
deploy_mode = true
inst = 212111 - wathgrithr (valid:true)
remote_vector = (84.59, 0.00, 563.26)
can_use_map = true
map = Map (12663548)
classified = 212112 - player_classified (valid:true)
is_map_enabled = true
directwalking = false
locomotor = table: 270900F8
time_direct_walking = 0.16666667535901
ismastersim = true
mousetimeout = 10
predictwalking = false
remote_controls = table: 424CD500
dragwalking = false
target = nil
isreleased = nil
noforce = nil
scripts/networkclientrpc.lua:97 in () ? (Lua) <94-99>
player = 212111 - wathgrithr (valid:true)
target = nil
isreleased = nil
noforce = nil
playercontroller = table: 424C7768
=[C]:-1 in (method) CallRPC © <-1--1>
scripts/networkclientrpc.lua:484 in (global) HandleRPCQueue (Lua) <475-492>
i = 1
fn = function - scripts/networkclientrpc.lua:94
sender = 212111 - wathgrithr (valid:true)
data = table: 3F38CE28
tick = true
scripts/update.lua:47 in () ? (Lua) <39-123>
dt = 0.016668831929564

[09:09:30]: [string "../mods/workshop-502999570/modmain.lua"]:6: attempt to index local 'target' (a nil value)
LUA ERROR stack traceback:
../mods/workshop-502999570/modmain.lua:6 in (method) CanTarget (Lua) <5-10>
scripts/components/playercontroller.lua:753 in (method) OnRemoteControllerAttackButton (Lua) <740-771>
scripts/networkclientrpc.lua:97 in () ? (Lua) <94-99>
=[C]:-1 in (method) CallRPC © <-1--1>
scripts/networkclientrpc.lua:484 in (global) HandleRPCQueue (Lua) <475-492>
scripts/update.lua:47 in () ? (Lua) <39-123>

[09:09:30]: SCRIPT ERROR! Showing error screen

 

What's wrong with it?

Edited by Jupiters
Link to comment
Share on other sites

@Jupiters, should be

local require = GLOBAL.requirelocal combat = require "components/combat" local combat_CanTarget_base = combat.CanTargetfunction combat:CanTarget(target, ...)    if target and target:HasTag("structure") and (self.inst:HasTag("monster") or self.inst:HasTag("epic")) then        return false    end    return combat_CanTarget_base(self, target, ...)end
Link to comment
Share on other sites

 

@Jupiters, should be

local require = GLOBAL.requirelocal combat = require "components/combat" local combat_CanTarget_base = combat.CanTargetfunction combat:CanTarget(target, ...)    if target and target:HasTag("structure") and (self.inst:HasTag("monster") or self.inst:HasTag("epic")) then        return false    end    return combat_CanTarget_base(self, target, ...)end

 

Oh, that's it. Thank you very much! :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...