MidrealmDM Posted May 25, 2019 Share Posted May 25, 2019 (edited) I was wondering if anyone has an ideaBelow is the function from a chessjunk prefab that gives 10% chance to spawn hostile clockwork when hammered.I'd like to mod this so that it has a greater chance to spawn hostile clockwork if the source of being hammered is _not_ a player. (such as being struck by a rook's charge, or by a meteor)=-=-=-=-=-=-local function OnHammered(inst, worker)inst.components.lootdropper:DropLoot()if math.random() <= .1 then -- increase this chance if action is NOT from playerlocal pos = inst:GetPosition()TheWorld:PushEvent("ms_sendlightningstrike", pos)SpawnScion(pos, false, inst.style, worker)elselocal fx = SpawnPrefab("collapse_small")fx.Transform:SetPosition(inst.Transform:GetWorldPosition())fx:SetMaterial("metal")endinst:Remove()end=-=-=-=-=-I can easily mod it to change this to a higher chance, but am not sure how to discern if the action is coming from a player.Thank you Edited June 2, 2019 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/106697-mod-when-action-is-not-from-player/ Share on other sites More sharing options...
. . . Posted May 26, 2019 Share Posted May 26, 2019 (edited) if not worker:HasTag("player") then else end Edited May 26, 2019 by Warbucks Link to comment https://forums.kleientertainment.com/forums/topic/106697-mod-when-action-is-not-from-player/#findComment-1200497 Share on other sites More sharing options...
MidrealmDM Posted May 27, 2019 Author Share Posted May 27, 2019 On 5/25/2019 at 11:22 PM, Warbucks said: if not worker:HasTag("player") then else end Thank you, However I am apparently still doing something wrong - I can't get the desired results, but I am not getting a crash, so Im not sure where it is going wrong. As best I can tell, the new function is either not being added to the chessjunk.lua or Spoiler -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- local function hammeredpostinit(inst) local newonhammered = function(inst, worker) inst.components.lootdropper:DropLoot() if not worker:HasTag("player") then local pos = inst:GetPosition() GLOBAL.TheWorld:PushEvent("ms_sendlightningstrike", pos) SpawnScion(pos, false, inst.style, worker) elseif worker:HasTag("player") and math.random() <= .1 then local pos = inst:GetPosition() GLOBAL.TheWorld:PushEvent("ms_sendlightningstrike", pos) SpawnScion(pos, false, inst.style, worker) else local fx = GLOBAL.SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) fx:SetMaterial("metal") end inst:Remove() end inst.components.workable:SetOnFinishCallback(newonhammered) end AddPrefabPostInit("chessjunk", hammeredpostinit) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Which returns an error : [00:01:07]: [string "../mods/wreckage-1750803495/modmain.lua"]:129: attempt to call global 'SpawnScion' (a nil value) LUA ERROR stack traceback: SpawnScion is a local function defined in 'chessjunk.lua' I don't feel it should be GLOBAL. but I tried it anyway which resulted in [00:01:12]: [string "../mods/wreckage-1750803495/modmain.lua"]:129: variable 'SpawnScion' is not declared Link to comment https://forums.kleientertainment.com/forums/topic/106697-mod-when-action-is-not-from-player/#findComment-1201350 Share on other sites More sharing options...
. . . Posted May 27, 2019 Share Posted May 27, 2019 Did you try copy pasting the local function SpawnScion into your modmain above this code? Link to comment https://forums.kleientertainment.com/forums/topic/106697-mod-when-action-is-not-from-player/#findComment-1201362 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now