Jump to content

Recommended Posts

I have a custom item and it has a level system. I want to be able to have players inspect it and it would say "bla bla bla" then next line "(Level: 1)".

 

How do I do that?

Also how does inspectable.getstatus work... example Abigail's flower has "SOON" but the corresponding quote-content "SOON" is only in speech_wendy.lua ... what about other character? I'd like this custom item of mine to be inspectable by anyone.

 

Thanks.

Link to comment
https://forums.kleientertainment.com/forums/topic/52247-inspectablegetstatus/
Share on other sites

Something must be inspectable to inspect it.

When you inspect it, your character will say the description of the item in question.

This description depends on the viewer, the item, and the status that the item reports.

The viewer selects the speech.

The item, the name of the entry in the speech table.

The status, the name of the entry in a table inside an entry in the speech table (so you get multiple descriptions in the same prefab).

 

getstatus exists so you add your own statuses, because abigail's flower can't have health, sleep, wither, or occupied.

 

Wendy has an entry on her speech, on her item, on the statuses defined.

Other characters have nothing, so they say "It's a... thing.", the generic comment.

 

Instead of editing speech files or making statuses, I suggest you use the

desc = self.descriptionfn(self.inst, viewer)

part in GetDescription of the inspectable component.

 

Like:

local mylines = {	wilson = "What is this?",	willow = "A test."}AddPrefabPostInit("axe", function(inst)	inst.level = 1	inst.components.inspectable.descriptionfn = function(inst, viewer)		local desc;		if mylines[viewer.prefab] then			desc = mylines[viewer.prefab]		else			desc = "I have no lines."		end		desc = desc.."\n".."Level: "..inst.level		return desc	endend)

Wilson and Willow have defined lines, others (including mod characters), get the generic one I made.

I also append the item level into the description.

It works. Thanks a lot.

 

Ok new problem. Apparently this below doesn't work. It works on character...

inst:ListenForEvent("entity_death", function(world, data) entitydeathfn(inst, data) end, TheWorld)

 

I want this custom item to gain exp as the wearer kills creatures.

What is the workaround?

 

Thanks.

Then, you are putting it wrong inside your prefab's fn, because

local function entitydeathfn(inst, data)	inst.exp = inst.exp + 1	if inst.exp == 2 then		inst.level = inst.level + 1		inst.exp = 0	endendAddPrefabPostInit("axe", function(inst)	inst.exp = 0	inst.level = 0	inst:ListenForEvent("entity_death", function(world, data) 		entitydeathfn(inst, data)	end, GLOBAL.TheWorld)end)

works fine.

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