Jump to content

problem with custom light


Recommended Posts

Hey guys, im helping a friend to make a simple item mod, but im getting this error: 

erro11.png

The code of the light follows up: 

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    --inst:AddTag("FX")

    inst.Light:SetIntensity(.75)
    inst.Light:SetColour(252 / 255, 251 / 255, 237 / 255)
    inst.Light:SetFalloff(.6)
    inst.Light:SetRadius(4)
    inst.Light:Enable(true)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    return inst
end

return Prefab("energylight", fn)

 

and the main code of the item: 

local assets=
{    
	Asset("ANIM", "anim/energyball.zip"),    
	Asset("ANIM", "anim/swap_energyball.zip"),    
	Asset("ATLAS", "images/inventoryimages/energyball.xml"),    
	Asset("IMAGE", "images/inventoryimages/energyball.tex"),
}

local prefabs = 
{
	"energylight",

}
--local function fn()    


local function OnEquip(inst, owner)        
	owner.AnimState:OverrideSymbol("swap_object", "swap_energyball", "swap_energyball")        
	owner.AnimState:Show("ARM_carry")        
	owner.AnimState:Hide("ARM_normal")  	
	
    --if inst.fire == nil then
        inst.fire = SpawnPrefab("energylight")
		local follower = inst.fire.entity:AddFollower()
		follower:FollowSymbol(owner.GUID, "swap_object", 0, -110, 1)
   -- end
		
end    

local function OnUnequip(inst, owner)     

    if inst.fire ~= nil then
        inst.fire:Remove()
        inst.fire = nil
    end
	
	owner.AnimState:Hide("ARM_carry")        
	owner.AnimState:Show("ARM_normal")   
	
end    

local function fn()	
	local inst = CreateEntity()    
	local trans = inst.entity:AddTransform()    
	local anim = inst.entity:AddAnimState()    
	local sound = inst.entity:AddSoundEmitter()  
	inst.entity:AddLight() --light is not a component
	inst.entity:AddNetwork()

	
	if not TheWorld.ismastersim then
		return inst
	end 
	
	
	MakeInventoryPhysics(inst)        
	anim:SetBank("energyball")    
	anim:SetBuild("energyball")    
	anim:PlayAnimation("idle")    
	inst:AddComponent("inspectable")        
	inst:AddComponent("inventoryitem")    
	inst.components.inventoryitem.imagename = "energyball"    
	inst.components.inventoryitem.atlasname = "images/inventoryimages/energyball.xml"        
	inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    
	inst.components.equippable:SetOnUnequip( OnUnequip )   
	
		inst.Light:SetIntensity(.8)
		inst.Light:SetRadius(1.5)
		inst.Light:SetFalloff(.5)
		inst.Light:SetColour(200/255, 100/255, 170/255)
		inst.Light:Enable(true)
		inst.Light:EnableClientModulation(true)

		return inst
	end 
	
	return  Prefab("common/inventory/energyball", fn, assets, prefabs)

 

i've tried to mimic morning star's code, and when i changed the line: 

inst.fire = SpawnPrefab("energylight")

to

inst.fire = SpawnPrefab("nightstickfire")

it works...

heres the mod if you guys wanna test (it also includes a character that have some bugs either, but im aiming for the item here):

starfire.rar

 

Link to comment
Share on other sites

@Gran

energyball.lua

local function fn()	
	local inst = CreateEntity()  	

	inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()
	
	inst.AnimState:SetBank("energyball")
    inst.AnimState:SetBuild("energyball")
    inst.AnimState:PlayAnimation("idle")
	
	MakeInventoryPhysics(inst) 
	
	inst.entity:SetPristine()
	
	if not TheWorld.ismastersim then
		return inst
	end 
	
	inst:AddComponent("inventoryitem")    
	inst.components.inventoryitem.imagename = "energyball"    
	inst.components.inventoryitem.atlasname = "images/inventoryimages/energyball.xml"   
			    
	inst:AddComponent("inspectable")        
     
	inst:AddComponent("equippable")    
	inst.components.equippable:SetOnEquip( OnEquip )    
	inst.components.equippable:SetOnUnequip( OnUnequip )  

	MakeHauntableLaunch(inst)	
	
	return inst
end 

energylight.lua

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    inst:AddTag("FX")

    inst.Light:SetIntensity(.75)
    inst.Light:SetColour(252 / 255, 251 / 255, 237 / 255)
    inst.Light:SetFalloff(.6)
    inst.Light:SetRadius(4)
    inst.Light:Enable(true)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    return inst
end

return Prefab("energylight", fn)

modmain.lua

PrefabFiles = {
	"starfire",
	"starfire_none",
	"energyball",
	"energylight"
}

 

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