Jump to content

(Help) Light from weapon only shows for host


Recommended Posts

So I'm trying to add light to a weapon. The issue is that other players can see the glow/light effect when it's dropped (which is good!), but not when I'm holding it (which is bad!). Here's what the prefab looks like so far:

 

local function OnEquip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_sword_blue", "swap_sword_blue")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
		
	inst.Light:Enable(true)
end
  
local function OnUnequip(inst, owner)
	owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	inst.Light:Enable(false)
end

local function ondrop(inst, dropper)
		inst.onuse = false
		inst.Light:Enable(true)
end
 
local function fn()
  
    local inst = CreateEntity()
 
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
     
    MakeInventoryPhysics(inst)   
      
    inst.AnimState:SetBank("sword_blue")
    inst.AnimState:SetBuild("sword_blue")
    inst.AnimState:PlayAnimation("idle")
 
    inst:AddTag("sharp")

    local minimap = inst.entity:AddMiniMapEntity()
	minimap:SetIcon("sword_blue.tex")
	
    local light = inst.entity:AddLight()
	light:SetColour(235/255, 244/255, 66/255)
	light:SetIntensity(0.8)
	light:SetRadius(2)
	light:SetFalloff(.33)
	inst.Light:Enable(true)
	
    if not TheWorld.ismastersim then
        return inst
    end
 
    inst.entity:SetPristine()
     
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(50)
  
    inst:AddComponent("inspectable")
    inst:AddComponent("talker")
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "sword_blue"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/sword_blue.xml"
	
	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )

	inst.components.inventoryitem.keepondeath = true
	
	inst.components.inventoryitem.onputininventoryfn = function(inst, player)
	if player.prefab ~= "saber" then
	inst:DoTaskInTime(0.1, function()
	player.components.inventory:DropItem(inst)
	player.components.talker:Say("It's so heavy!")
	end)
	end
	end
	
    return inst
end
return  Prefab("common/inventory/sword_blue", fn, assets) 

I tried moving

	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )

above the "if not TheWorld.ismastersim" so that it was run on the client, but that threw an error about equippable being null. Adding

 local common_postinit = function(inst) 
    local light = inst.entity:AddLight()
	light:SetColour(235/255, 244/255, 66/255)
	light:SetIntensity(0.8)
	light:SetRadius(2)
	light:SetFalloff(.33)
	inst.Light:Enable(true)
end

didn't solve it either. Help?

 

Also, is it possible to change the radius of the light after creation? I'd like to have it be brighter when dropped

Edited by Aida Enna
Link to comment
Share on other sites

Alright, I changed it so that the player gives off light, and when dropped, the item will turn it on/off and turn it's own light on/off. Wish I could have done it via weapon, as each one has a unique glow, but... =/ 

Edited by Aida Enna
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...