Jump to content

Recommended Posts

I really didn't want to make this post mostly because I thought I could solve this issue myself, but i've tried a bunch of diffrent methods and they don't seem to work. Basicly the issue is when reading the same book twice during it's effect duration, the effects stack and the extra effect dosen't vanish. I've tried detecting if fx ~= nil and not spawning the fx. no dice. I've tried deleteing the old fx as soon as the new one spawns, no dice either. Any pointers would be really awesome! 

image.png.4659d5237abd5f06062ed417e8c8f0b3.png

Here's what the issue looks like, The two effects stack on eachother.

Here's my current script for the book

local Assets = {
    -- Animation files for the item (showing it on the ground and swap symbols for the players).
    Asset("ANIM", "anim/wendalyn_book_shield_ground.zip"),
   
    -- Inventory image and atlas file used for the item.
    Asset("ATLAS", "images/inventoryimages/wendalyn_book_shield.xml"),
    Asset("IMAGE", "images/inventoryimages/wendalyn_book_shield.tex"),
}
 
local WENDALYNSHIELD = 20
 
local function ruinshat_unproc(inst)
        if inst:HasTag("forcefield") then
            inst:RemoveTag("forcefield")
            if inst._unstoppable_fx ~= nil then
            inst._unstoppable_fx:Remove("forcefieldfx")
            inst._unstoppable_fx = nil
            end
 
            if inst._task ~= nil then
                inst._task:Cancel()
            end
        end
        if inst.components.health ~= nil then
                --player.components.health.externalabsorbmodifiers:SetModifier(player, TUNING.BUFF_PLAYERABSORPTION_MODIFIER)
            inst.components.health:SetAbsorptionAmount(0)
        end
    end


 
local function MainFunction()
    -- Functions which are performed both on Client and Server start here.
    local inst = CreateEntity()
   
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()
   
    MakeInventoryPhysics(inst)
   
    -- Add minimap icon. Remember about its XML in modmain.lua!
    local minimap = inst.entity:AddMiniMapEntity()
    minimap:SetIcon("wendalyn_book_shield.tex")
   
    --[[ ANIMSTATE ]]--
    -- This is the name visible on the top of hierarchy in Spriter.
    inst.AnimState:SetBank("wendalyn_book_shield_ground")
    -- This is the name of your compiled*.zip file.
    inst.AnimState:SetBuild("wendalyn_book_shield_ground")
    -- This is the animation name while item is on the ground.
    inst.AnimState:PlayAnimation("anim")
 
    --[[ TAGS ]]--
    inst:AddTag("wendalyn_book_shield")
   
    inst:AddTag("book")
 
    inst:AddComponent("book")
 
    --[[affected players]]-- if you need this....
    inst._ruins_proc_players={}
   
    inst.components.book.onread = function(inst, reader)
 
    reader:StartThread(function()      
    local x, y, z = reader.Transform:GetWorldPosition()
   
    if true then -- SanityCheck(caster)
        local range = 10        
        local must_tags = {"player"}
                   
        local players = TheSim:FindEntities(x, y, z, range, must_tags)
        table.insert(inst._ruins_proc_players, players)
                if players ~= nil then
                    for key, player in pairs(players) do
                    --[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system
                    player:AddTag("forcefield")
                    if inst._unstoppable_fx ~= nil then
                        inst._unstoppable_fx:Remove("forcefieldfx")
                    end
 
                    player._unstoppable_fx = SpawnPrefab("forcefieldfx")
                    player._unstoppable_fx.entity:SetParent(player.entity)
                    player._unstoppable_fx.Transform:SetPosition(0, 0.2, 0)
                    if player.components.health ~= nil then
                        player.components.health:SetAbsorptionAmount(.95)
                    end
                    player._task = player:DoTaskInTime(WENDALYNSHIELD, ruinshat_unproc)
                end
            end
        end
    end)
 
reader.components.sanity:DoDelta(-35)          
return true
end
   
    MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2})
 
    inst.entity:SetPristine()
 
    if not TheWorld.ismastersim then
        -- If we're not the host - stop performing further functions.
        -- Only server functions below.
        return inst
    end
 
    inst:AddComponent("inspectable")
 
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "wendalyn_book_shield"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/wendalyn_book_shield.xml"
   
    --new new code
 
    MakeHauntableLaunch(inst)
 
    return inst
end
 
return  Prefab("wendalyn_book_shield", MainFunction, Assets)

You are trying to remove the fx from inst

--[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system
player:AddTag("forcefield")
if inst._unstoppable_fx ~= nil then
  inst._unstoppable_fx:Remove("forcefieldfx") -- Remove from inst
end

player._unstoppable_fx = SpawnPrefab("forcefieldfx")
player._unstoppable_fx.entity:SetParent(player.entity)

You may want to remove it from the player.

--[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system
player:AddTag("forcefield")
if player._unstoppable_fx ~= nil then
  player._unstoppable_fx:Remove("forcefieldfx") -- Remove from player
end

player._unstoppable_fx = SpawnPrefab("forcefieldfx")
player._unstoppable_fx.entity:SetParent(player.entity)

If this doesn't work, set the variable to null

--[[forcefield buff]]-- i recommend making a buff inst with the new sosurce modifierlist system
player:AddTag("forcefield")
if player._unstoppable_fx ~= nil then
  player._unstoppable_fx:Remove("forcefieldfx")
  player._unstoppable_fx = nil
end

player._unstoppable_fx = SpawnPrefab("forcefieldfx")
player._unstoppable_fx.entity:SetParent(player.entity)

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
×
  • Create New...