Jump to content

Mod when action is not from player


Recommended Posts

I was wondering if anyone has an idea
Below 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 player
local pos = inst:GetPosition()
TheWorld:PushEvent("ms_sendlightningstrike", pos)
SpawnScion(pos, false, inst.style, worker)
else
local fx = SpawnPrefab("collapse_small")
fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
fx:SetMaterial("metal")
end
inst: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 by MidrealmDM
Link to comment
Share on other sites

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
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...