Jump to content

local light = inst.entity:AddLight() script question. HELP!


Recommended Posts

hi,

 

i'm trying to add light effect to a weapon when it's held on hand,

 

i put 

 

local light = inst.entity:AddLight()
    inst.Light:SetRadius(5)
    inst.Light:SetFalloff(.6)
    inst.Light:SetIntensity(0.75)
    light:Enable(true)
    inst.Light:SetColour(220/255,209/255,50/255)
    inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )

 

under local function OnEquip(inst, owner).

 

now, this seems to be working on the person who is using the item. it lights up certain radius for that person. but other people cannot see the light emitted by this item.

 

can anyone tell me what i have to add more so others also can see the light?

Link to comment
Share on other sites

Oh, sorry, they're called

nightstick
and
nightstickfire

When you do your new item with light you should use that, or at least, I reccomend do that.

Instead of make the light on equip you can do this now

OnEquip

    inst.fire = SpawnPrefab("nightstickfire")
    local follower = inst.fire.entity:AddFollower()
    follower:FollowSymbol(owner.GUID, "swap_object", 0, -110, 1)
This will enable the fire.

OnUnequip

    inst.fire:Remove()
    inst.fire = nil
This will disable it.

on the nightstickfire you can customize the light

Link to comment
Share on other sites

Basically the strategy that the game uses for lights is to give them their own prefab, and then the item prefab will delete/add the light prefab as needed. This is nice because prefabs will get automatically networked, and will set up their appearance on clients just like the host. Torches, nightsticks, etc, all use this strategy. You could copy their light prefabs and tweak it as you want.

Link to comment
Share on other sites

Worth noting something else here.

Take for example this prefab:

test_light:lua

local assets = {
	Asset("ANIM", "anim/torch.zip"),
	Asset("ANIM", "anim/swap_torch.zip"),
}

local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_object", "swap_torch", "swap_torch")
	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 FixTorchLight(inst)
	inst.Light:Enable(false)
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddLight()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("torch")
	inst.AnimState:SetBuild("swap_torch")
	inst.AnimState:PlayAnimation("idle")

	inst.Light:SetIntensity(0.75)
	inst.Light:SetColour(197/255, 197/255, 50/255)
	inst.Light:SetFalloff(0.5)
	inst.Light:SetRadius(2)
	inst.Light:Enable(false)

	inst.Light:EnableClientModulation(true)

	inst:AddTag("nopunch")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "torch"

	inst:ListenForEvent("ondropped", FixTorchLight)

	inst:AddComponent("equippable")
	inst.components.equippable:SetOnEquip(onequip)
	inst.components.equippable:SetOnUnequip(onunequip)

	return inst
end

STRINGS.NAMES.TEST_LIGHT = "Test Light"

return Prefab("test_light", fn, assets)

Light is effectively networked on the same entity without needing extras, thanks to EnableClientModulation.

You aren't changing the intensity or making the light fade out smoothly. Just turning it on and off.

Entities that use this, like in altar_prototyper.lua, use other net variables to update it properly.

Another question is why dropping this item enables the Light.

Edited by DarkXero
Link to comment
Share on other sites

On 4.5.2016 at 9:39 AM, DarkXero said:

Another question is why dropping this item enables the Light.

heatrock.lua

-- InventoryItems automatically enable their lights when dropped, so we need to counteract that
inst:ListenForEvent("ondropped", function(inst)

Y'know, instead of changing the inventoryitem component to not force-enable light and specifically enabling it for the few prefabs that want it enabled.

Link to comment
Share on other sites

7 hours ago, Mobbstar said:

Y'know, instead of changing the inventoryitem component to not force-enable light and specifically enabling it for the few prefabs that want it enabled.

Ah, so it carried over from DS.

heatrock has a heatrocklight prefab now, as most inventoryitems have.

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